Merge pull request #36327 from ucasfl/alias

Add aliases JSONLines and NDJSON for JSONEachRow
This commit is contained in:
Alexey Milovidov 2022-04-22 07:08:02 +03:00 committed by GitHub
commit e8575f5f35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 106 additions and 0 deletions

View File

@ -360,6 +360,24 @@ void registerInputFormatJSONEachRow(FormatFactory & factory)
return std::make_shared<JSONEachRowRowInputFormat>(buf, sample, std::move(params), settings, false);
});
factory.registerInputFormat("JSONLines", [](
ReadBuffer & buf,
const Block & sample,
IRowInputFormat::Params params,
const FormatSettings & settings)
{
return std::make_shared<JSONEachRowRowInputFormat>(buf, sample, std::move(params), settings, false);
});
factory.registerInputFormat("NDJSON", [](
ReadBuffer & buf,
const Block & sample,
IRowInputFormat::Params params,
const FormatSettings & settings)
{
return std::make_shared<JSONEachRowRowInputFormat>(buf, sample, std::move(params), settings, false);
});
factory.registerFileExtension("ndjson", "JSONEachRow");
factory.registerFileExtension("jsonl", "JSONEachRow");
@ -377,12 +395,16 @@ void registerFileSegmentationEngineJSONEachRow(FormatFactory & factory)
{
factory.registerFileSegmentationEngine("JSONEachRow", &fileSegmentationEngineJSONEachRow);
factory.registerFileSegmentationEngine("JSONStringsEachRow", &fileSegmentationEngineJSONEachRow);
factory.registerFileSegmentationEngine("JSONLines", &fileSegmentationEngineJSONEachRow);
factory.registerFileSegmentationEngine("NDJSON", &fileSegmentationEngineJSONEachRow);
}
void registerNonTrivialPrefixAndSuffixCheckerJSONEachRow(FormatFactory & factory)
{
factory.registerNonTrivialPrefixAndSuffixChecker("JSONEachRow", nonTrivialPrefixAndSuffixCheckerJSONEachRowImpl);
factory.registerNonTrivialPrefixAndSuffixChecker("JSONStringsEachRow", nonTrivialPrefixAndSuffixCheckerJSONEachRowImpl);
factory.registerNonTrivialPrefixAndSuffixChecker("JSONLines", nonTrivialPrefixAndSuffixCheckerJSONEachRowImpl);
factory.registerNonTrivialPrefixAndSuffixChecker("NDJSON", nonTrivialPrefixAndSuffixCheckerJSONEachRowImpl);
}
void registerJSONEachRowSchemaReader(FormatFactory & factory)
@ -396,6 +418,16 @@ void registerJSONEachRowSchemaReader(FormatFactory & factory)
{
return std::make_unique<JSONEachRowSchemaReader>(buf, true, settings);
});
factory.registerSchemaReader("JSONLines", [](ReadBuffer & buf, const FormatSettings & settings)
{
return std::make_unique<JSONEachRowSchemaReader>(buf, false, settings);
});
factory.registerSchemaReader("NDJSON", [](ReadBuffer & buf, const FormatSettings & settings)
{
return std::make_unique<JSONEachRowSchemaReader>(buf, false, settings);
});
}
}

View File

@ -140,6 +140,32 @@ void registerOutputFormatJSONEachRow(FormatFactory & factory)
});
factory.markOutputFormatSupportsParallelFormatting("JSONEachRow");
factory.registerOutputFormat("JSONLines", [](
WriteBuffer & buf,
const Block & sample,
const RowOutputFormatParams & params,
const FormatSettings & _format_settings)
{
FormatSettings settings = _format_settings;
settings.json.serialize_as_strings = false;
return std::make_shared<JSONEachRowRowOutputFormat>(buf, sample, params,
settings);
});
factory.markOutputFormatSupportsParallelFormatting("JSONLines");
factory.registerOutputFormat("NDJSON", [](
WriteBuffer & buf,
const Block & sample,
const RowOutputFormatParams & params,
const FormatSettings & _format_settings)
{
FormatSettings settings = _format_settings;
settings.json.serialize_as_strings = false;
return std::make_shared<JSONEachRowRowOutputFormat>(buf, sample, params,
settings);
});
factory.markOutputFormatSupportsParallelFormatting("NDJSON");
factory.registerOutputFormat("JSONStringsEachRow", [](
WriteBuffer & buf,
const Block & sample,

View File

@ -14,8 +14,10 @@ JSONCompactStringsEachRow
JSONCompactStringsEachRowWithNames
JSONCompactStringsEachRowWithNamesAndTypes
JSONEachRow
JSONLines
JSONStringsEachRow
MsgPack
NDJSON
Native
ORC
Parquet

View File

@ -0,0 +1,32 @@
{"number":"0"}
{"number":"1"}
{"number":"2"}
{"number":"3"}
{"number":"4"}
{"number":"5"}
{"number":"6"}
{"number":"7"}
{"number":"8"}
{"number":"9"}
{"number":"0"}
{"number":"1"}
{"number":"2"}
{"number":"3"}
{"number":"4"}
{"number":"5"}
{"number":"6"}
{"number":"7"}
{"number":"8"}
{"number":"9"}
{"n1":1,"n2":2}
{"n1":1,"n2":2}
{"n1":3,"n2":4}
{"n1":3,"n2":4}
{"n1":5,"n2":6}
{"n1":5,"n2":6}
{"n1":1,"n2":2}
{"n1":1,"n2":2}
{"n1":3,"n2":4}
{"n1":3,"n2":4}
{"n1":5,"n2":6}
{"n1":5,"n2":6}

View File

@ -0,0 +1,14 @@
SELECT * FROM numbers(10) FORMAT JSONLines;
SELECT * FROM numbers(10) FORMAT NDJSON;
DROP TABLE IF EXISTS 02267_t;
CREATE TABLE 02267_t (n1 UInt32, n2 UInt32) ENGINE = Memory;
INSERT INTO 02267_t FORMAT JSONLines {"n1": 1, "n2": 2} {"n1": 3, "n2": 4} {"n1": 5, "n2": 6};
INSERT INTO 02267_t FORMAT NDJSON {"n1": 1, "n2": 2} {"n1": 3, "n2": 4} {"n1": 5, "n2": 6};
SELECT * FROM 02267_t ORDER BY n1, n2 FORMAT JSONLines;
SELECT * FROM 02267_t ORDER BY n1, n2 FORMAT NDJSON;
DROP TABLE 02267_t;