local rspamd_logger = require "rspamd_logger"
local rspamd_http = require "rspamd_http"
local lua_util = require "lua_util"
+local rspamd_text = require "rspamd_text"
local exports = {}
local N = 'clickhouse'
end
end
- return table.concat(row, '\t')
+ return rspamd_text.fromtable(row, '\t')
end
+exports.row_to_tsv = row_to_tsv
+
-- Parses JSONEachRow reply from CH
local function parse_clickhouse_response_json_eachrow(params, data)
local ucl = require "ucl"
http_params.user = settings.user
http_params.password = settings.password
http_params.method = 'POST'
- http_params.body = {table.concat(fun.totable(fun.map(function(row)
- return row_to_tsv(row)
- end, rows)), '\n'), '\n'}
+ http_params.body = {rspamd_text.from_table(rows, '\n'), '\n'}
http_params.log_obj = params.task or params.config
if not http_params.url then
end
send_data('generic data', data_rows,
- string.format('INSERT INTO rspamd (%s)', table.concat(fields, ',')))
+ string.format('INSERT INTO rspamd (%s)',
+ table.concat(fields, ',')))
for k,crows in pairs(custom_rows) do
if #crows > 1 then
- send_data('custom data ('..k..')', settings.custom_rules[k].first_row(),
- crows)
+ send_data('custom data ('..k..')', crows,
+ settings.custom_rules[k].first_row())
end
end
end
-- Custom data
for k,rule in pairs(settings.custom_rules) do
if not custom_rows[k] then custom_rows[k] = {} end
- table.insert(custom_rows[k], rule.get_row(task))
+ table.insert(custom_rows[k], lua_clickhouse.row_to_tsv(rule.get_row(task)))
end
nrows = nrows + 1
- table.insert(data_rows, row)
+ data_rows[#data_rows + 1] = lua_clickhouse.row_to_tsv(row)
lua_util.debugm(N, task, "add clickhouse row %s / %s", nrows, settings.limit)
if nrows >= settings['limit'] then