diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-08-07 15:36:12 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-08-07 15:36:12 +0100 |
commit | 77d8a4588723e97c6f6a3cfef584a6ef5516b951 (patch) | |
tree | c7c48cb0c25ea4135a8fbc880271d88dbc560c3d /lualib/lua_clickhouse.lua | |
parent | e11515be96af93e4a2f34cb4b7f260c11f439c9a (diff) | |
download | rspamd-77d8a4588723e97c6f6a3cfef584a6ef5516b951.tar.gz rspamd-77d8a4588723e97c6f6a3cfef584a6ef5516b951.zip |
[Minor] Various fixes to Clickhouse exporter
Diffstat (limited to 'lualib/lua_clickhouse.lua')
-rw-r--r-- | lualib/lua_clickhouse.lua | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/lualib/lua_clickhouse.lua b/lualib/lua_clickhouse.lua index 37c9ebb7a..3f3c4de40 100644 --- a/lualib/lua_clickhouse.lua +++ b/lualib/lua_clickhouse.lua @@ -27,6 +27,15 @@ local function escape_spaces(query) return query:gsub('%s', '%%20') end +local function ch_number(a) + if (a+2^52)-2^52 == a then + -- Integer + return tostring(math.floor(a)) + end + + return tostring(a) +end + local function clickhouse_quote(str) if str then return str:gsub('[\'\\]', '\\%1'):lower() @@ -40,8 +49,8 @@ local function array_to_string(ar) for i,elt in ipairs(ar) do if type(elt) == 'string' then ar[i] = '\'' .. clickhouse_quote(elt) .. '\'' - else - ar[i] = tostring(elt) + elseif type(elt) == 'number' then + ar[i] = ch_number(elt) end end @@ -54,8 +63,8 @@ local function row_to_tsv(row) for i,elt in ipairs(row) do if type(elt) == 'table' then row[i] = '[' .. array_to_string(elt) .. ']' - else - row[i] = tostring(elt) -- Assume there are no tabs there + elseif type(elt) == 'number' then + row[i] = ch_number(elt) end end |