Optimize and fix

This commit is contained in:
hcz 2020-07-01 11:21:53 +08:00
parent cfcfe32fda
commit e284bf83d0
3 changed files with 11 additions and 20 deletions

View File

@ -10,7 +10,7 @@ namespace DB
{
/** A stream to input data in tsv format, but without escaping individual values.
* It only supports one string column
* It only supports columns without '\n' or '\t'
*/
class TabSeparatedRawRowInputFormat : public TabSeparatedRowInputFormat
{
@ -33,23 +33,12 @@ public:
bool readField(IColumn & column, const DataTypePtr & type, bool) override
{
// TODO: possible to optimize
std::string buf;
char * pos = find_first_symbols<'\n', '\t'>(in.position(), in.buffer().end());
ReadBufferFromMemory cell(in.position(), pos - in.position());
while (!in.eof())
{
char c = *in.position();
type->deserializeAsWholeText(column, cell, format_settings);
if (c == '\n' || c == '\t')
break;
in.ignore();
buf.push_back(c);
}
ReadBufferFromString line_in(buf);
type->deserializeAsWholeText(column, line_in, format_settings);
in.position() = pos;
return true;
}

View File

@ -1 +1,2 @@
"a 1
"a 1 \ \\ "\"" "\\""
["\"a ", "1", "\\", "\\\\", "\"\\\"\"", "\"\\\\\"\""]

View File

@ -1,7 +1,8 @@
drop table if exists tsv_raw;
create table tsv_raw (a String, b Int64) engine = Memory;
insert into tsv_raw format TSVRaw "a 1
create table tsv_raw (strval String, intval Int64, b1 String, b2 String, b3 String, b4 String) engine = Memory;
insert into tsv_raw format TSVRaw "a 1 \ \\ "\"" "\\""
;
select * from tsv_raw;
select * from tsv_raw format TSVRaw;
select * from tsv_raw format JSONCompactEachRow;
drop table tsv_raw;