mirror of
https://github.com/Infinidat/infi.clickhouse_orm.git
synced 2025-07-25 15:29:50 +03:00
Greatly improve performance when inserting large strings (credit to M1hacka for identifying the problem)
This commit is contained in:
parent
7145984797
commit
ec99044fab
|
@ -6,6 +6,7 @@ Unreleased
|
||||||
- Add support for ReplacingMergeTree (leenr)
|
- Add support for ReplacingMergeTree (leenr)
|
||||||
- Fix problem with SELECT WITH TOTALS (pilosus)
|
- Fix problem with SELECT WITH TOTALS (pilosus)
|
||||||
- Update serialization format of DateTimeField to 10 digits, zero padded (nikepan)
|
- Update serialization format of DateTimeField to 10 digits, zero padded (nikepan)
|
||||||
|
- Greatly improve performance when inserting large strings (credit to M1hacka for identifying the problem)
|
||||||
|
|
||||||
v0.8.0
|
v0.8.0
|
||||||
------
|
------
|
||||||
|
|
|
@ -17,15 +17,18 @@ SPECIAL_CHARS = {
|
||||||
SPECIAL_CHARS_REGEX = re.compile("[" + ''.join(SPECIAL_CHARS.values()) + "]")
|
SPECIAL_CHARS_REGEX = re.compile("[" + ''.join(SPECIAL_CHARS.values()) + "]")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def escape(value, quote=True):
|
def escape(value, quote=True):
|
||||||
'''
|
'''
|
||||||
If the value is a string, escapes any special characters and optionally
|
If the value is a string, escapes any special characters and optionally
|
||||||
surrounds it with single quotes. If the value is not a string (e.g. a number),
|
surrounds it with single quotes. If the value is not a string (e.g. a number),
|
||||||
converts it to one.
|
converts it to one.
|
||||||
'''
|
'''
|
||||||
|
def escape_one(match):
|
||||||
|
return SPECIAL_CHARS[match.group(0)]
|
||||||
|
|
||||||
if isinstance(value, string_types):
|
if isinstance(value, string_types):
|
||||||
if SPECIAL_CHARS_REGEX.search(value):
|
value = SPECIAL_CHARS_REGEX.sub(escape_one, value)
|
||||||
value = "".join(SPECIAL_CHARS.get(c, c) for c in value)
|
|
||||||
if quote:
|
if quote:
|
||||||
value = "'" + value + "'"
|
value = "'" + value + "'"
|
||||||
return text_type(value)
|
return text_type(value)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user