Greatly improve performance when inserting large strings (credit to M1hacka for identifying the problem)

This commit is contained in:
Itai Shirav 2017-04-05 17:09:56 +03:00
parent 7145984797
commit ec99044fab
2 changed files with 6 additions and 2 deletions

View File

@ -6,6 +6,7 @@ Unreleased
- Add support for ReplacingMergeTree (leenr)
- Fix problem with SELECT WITH TOTALS (pilosus)
- 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
------

View File

@ -17,15 +17,18 @@ SPECIAL_CHARS = {
SPECIAL_CHARS_REGEX = re.compile("[" + ''.join(SPECIAL_CHARS.values()) + "]")
def escape(value, quote=True):
'''
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),
converts it to one.
'''
def escape_one(match):
return SPECIAL_CHARS[match.group(0)]
if isinstance(value, string_types):
if SPECIAL_CHARS_REGEX.search(value):
value = "".join(SPECIAL_CHARS.get(c, c) for c in value)
value = SPECIAL_CHARS_REGEX.sub(escape_one, value)
if quote:
value = "'" + value + "'"
return text_type(value)