mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 08:40:50 +00:00
Merge pull request #36327 from ucasfl/alias
Add aliases JSONLines and NDJSON for JSONEachRow
This commit is contained in:
commit
e8575f5f35
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -14,8 +14,10 @@ JSONCompactStringsEachRow
|
||||
JSONCompactStringsEachRowWithNames
|
||||
JSONCompactStringsEachRowWithNamesAndTypes
|
||||
JSONEachRow
|
||||
JSONLines
|
||||
JSONStringsEachRow
|
||||
MsgPack
|
||||
NDJSON
|
||||
Native
|
||||
ORC
|
||||
Parquet
|
||||
|
@ -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}
|
14
tests/queries/0_stateless/02267_jsonlines_ndjson_format.sql
Normal file
14
tests/queries/0_stateless/02267_jsonlines_ndjson_format.sql
Normal 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;
|
Loading…
Reference in New Issue
Block a user