diff --git a/src/DataTypes/Serializations/ISerialization.h b/src/DataTypes/Serializations/ISerialization.h index 76c88fe7522..3f4f4b8f875 100644 --- a/src/DataTypes/Serializations/ISerialization.h +++ b/src/DataTypes/Serializations/ISerialization.h @@ -17,6 +17,7 @@ namespace DB namespace ErrorCodes { extern const int LOGICAL_ERROR; + extern const int NOT_IMPLEMENTED; } class IDataType; diff --git a/src/DataTypes/Serializations/SerializationAsStringNonTrivialJSON.h b/src/DataTypes/Serializations/SerializationAsStringNonTrivialJSON.h index 7d8375368a7..c6d6b864bed 100644 --- a/src/DataTypes/Serializations/SerializationAsStringNonTrivialJSON.h +++ b/src/DataTypes/Serializations/SerializationAsStringNonTrivialJSON.h @@ -12,6 +12,11 @@ namespace DB { +namespace ErrorCodes +{ + extern const int NOT_IMPLEMENTED; +} + /** Serialization for non-numeric non-string data types serialized as JSON strings * For these data types, we support an option, input_format_json_empty_as_default, which, when set to 1, * allows for JSON deserialization to treat an encountered empty string as a default value for the specified type. diff --git a/src/DataTypes/Serializations/SerializationNullable.cpp b/src/DataTypes/Serializations/SerializationNullable.cpp index 72c6a661dde..3cd767e58eb 100644 --- a/src/DataTypes/Serializations/SerializationNullable.cpp +++ b/src/DataTypes/Serializations/SerializationNullable.cpp @@ -868,7 +868,7 @@ template ReturnType deserializeTextJSONImpl(IColumn & column, ReadBuffer & istr, const FormatSettings & settings, const SerializationPtr & nested, bool & is_null) { auto check_for_null = [](ReadBuffer & buf){ return checkStringByFirstCharacterAndAssertTheRest("null", buf); }; - auto deserialize_nested = [&nested, &settings](IColumn & nested_column, ReadBuffer & buf) + auto deserialize_nested = [&nested, &settings](IColumn & nested_column, ReadBuffer & buf) -> ReturnType { if constexpr (strategy == Strategy::TryDeserialize) return nested->tryDeserializeTextJSON(nested_column, buf, settings); diff --git a/tests/queries/0_stateless/03203_json_empty_as_default.reference b/tests/queries/0_stateless/03203_json_empty_as_default.reference index 53d7014e452..1c689228cdf 100644 --- a/tests/queries/0_stateless/03203_json_empty_as_default.reference +++ b/tests/queries/0_stateless/03203_json_empty_as_default.reference @@ -1,20 +1,47 @@ +-- Simple types +-- { echoOn } +SELECT x FROM format(JSONEachRow, 'x Date', '{"x":""}'); 1970-01-01 +SELECT x FROM format(JSONEachRow, 'x Date32', '{"x":""}'); 1970-01-01 +SELECT toTimeZone(x, 'UTC') FROM format(JSONEachRow, 'x DateTime', '{"x":""}'); 1970-01-01 00:00:00 +SELECT toTimeZone(x, 'UTC') FROM format(JSONEachRow, 'x DateTime64', '{"x":""}'); 1970-01-01 00:00:00.000 +SELECT x FROM format(JSONEachRow, 'x IPv4', '{"x":""}'); 0.0.0.0 +SELECT x FROM format(JSONEachRow, 'x IPv6', '{"x":""}'); :: +SELECT x FROM format(JSONEachRow, 'x UUID', '{"x":""}'); 00000000-0000-0000-0000-000000000000 +-- { echoOn } +SELECT COUNT(DISTINCT col) FROM table1; 1 +-- { echoOn } +SELECT * FROM table1 ORDER BY address ASC; :: 2001:db8:3333:4444:5555:6666:7777:8888 +-- Nullable +-- { echoOn } +SELECT x FROM format(JSONEachRow, 'x Nullable(IPv6)', '{"x":""}'); :: +-- Compound types +SELECT x FROM format(JSONEachRow, 'x Array(UUID)', '{"x":["00000000-0000-0000-0000-000000000000","b15f852c-c41a-4fd6-9247-1929c841715e",""]}'); ['00000000-0000-0000-0000-000000000000','b15f852c-c41a-4fd6-9247-1929c841715e','00000000-0000-0000-0000-000000000000'] +SELECT x FROM format(JSONEachRow, 'x Array(Nullable(IPv6))', '{"x":["",""]}'); ['::','::'] +SELECT x FROM format(JSONEachRow, 'x Tuple(Date, IPv4, String)', '{"x":["", "", "abc"]}'); ('1970-01-01','0.0.0.0','abc') +SELECT x FROM format(JSONEachRow, 'x Map(String, IPv6)', '{"x":{"abc": ""}}'); {'abc':'::'} +SELECT x FROM format(JSONEachRow, 'x Variant(Date, UUID)', '{"x":""}'); 00000000-0000-0000-0000-000000000000 +-- Deep composition +SELECT x FROM format(JSONEachRow, 'x Array(Array(IPv6))', '{"x":[["2001:db8:3333:4444:CCCC:DDDD:EEEE:FFFF", ""], ["", "2001:db8:3333:4444:5555:6666:7777:8888"]]}'); [['2001:db8:3333:4444:cccc:dddd:eeee:ffff','::'],['::','2001:db8:3333:4444:5555:6666:7777:8888']] +SELECT x FROM format(JSONEachRow, 'x Variant(Date, Array(UUID))', '{"x":["", "b15f852c-c41a-4fd6-9247-1929c841715e"]}'); ['00000000-0000-0000-0000-000000000000','b15f852c-c41a-4fd6-9247-1929c841715e'] +SELECT x FROM format(JSONEachRow, 'x Tuple(Array(UUID), Tuple(UUID, Map(String, IPv6)))', '{"x":[[""], ["",{"abc":""}]]}'); (['00000000-0000-0000-0000-000000000000'],('00000000-0000-0000-0000-000000000000',{'abc':'::'})) +SELECT x FROM format(JSONEachRow, 'x Map(Tuple(Date,IPv4), Variant(UUID,IPv6))', '{"x":{["",""]:""}}'); {('1970-01-01','0.0.0.0'):'00000000-0000-0000-0000-000000000000'} diff --git a/tests/queries/0_stateless/03203_json_empty_as_default.sql b/tests/queries/0_stateless/03203_json_empty_as_default.sql index 35652f4c751..1243d450c2e 100644 --- a/tests/queries/0_stateless/03203_json_empty_as_default.sql +++ b/tests/queries/0_stateless/03203_json_empty_as_default.sql @@ -1,7 +1,7 @@ -set input_format_json_empty_as_default = 1; -set allow_experimental_variant_type = 1; +SET input_format_json_empty_as_default = 1, allow_experimental_variant_type = 1; -# Simple types +-- Simple types +-- { echoOn } SELECT x FROM format(JSONEachRow, 'x Date', '{"x":""}'); SELECT x FROM format(JSONEachRow, 'x Date32', '{"x":""}'); SELECT toTimeZone(x, 'UTC') FROM format(JSONEachRow, 'x DateTime', '{"x":""}'); @@ -9,8 +9,9 @@ SELECT toTimeZone(x, 'UTC') FROM format(JSONEachRow, 'x DateTime64', '{"x":""}') SELECT x FROM format(JSONEachRow, 'x IPv4', '{"x":""}'); SELECT x FROM format(JSONEachRow, 'x IPv6', '{"x":""}'); SELECT x FROM format(JSONEachRow, 'x UUID', '{"x":""}'); +-- { echoOff } -# Simple type AggregateFunction +-- Simple type AggregateFunction DROP TABLE IF EXISTS table1; CREATE TABLE table1(col AggregateFunction(uniq, UInt64)) ENGINE=Memory(); DROP TABLE IF EXISTS table2; @@ -18,35 +19,41 @@ CREATE TABLE table2(UserID UInt64) ENGINE=Memory(); INSERT INTO table1 SELECT uniqState(UserID) FROM table2; INSERT INTO table1 SELECT x FROM format(JSONEachRow, 'x AggregateFunction(uniq, UInt64)' AS T, '{"x":""}'); + +-- { echoOn } SELECT COUNT(DISTINCT col) FROM table1; +-- { echoOff } DROP TABLE table1; DROP TABLE table2; -# The setting input_format_defaults_for_omitted_fields determines the default value if enabled. +-- The setting input_format_defaults_for_omitted_fields determines the default value if enabled. CREATE TABLE table1(address IPv6 DEFAULT toIPv6('2001:db8:3333:4444:5555:6666:7777:8888')) ENGINE=Memory(); -set input_format_defaults_for_omitted_fields = 0; +SET input_format_defaults_for_omitted_fields = 0; INSERT INTO table1 FORMAT JSONEachRow {"address":""}; -set input_format_defaults_for_omitted_fields = 1; +SET input_format_defaults_for_omitted_fields = 1; INSERT INTO table1 FORMAT JSONEachRow {"address":""}; +-- { echoOn } SELECT * FROM table1 ORDER BY address ASC; +-- { echoOff } DROP TABLE table1; -# Nullable +-- Nullable +-- { echoOn } SELECT x FROM format(JSONEachRow, 'x Nullable(IPv6)', '{"x":""}'); -# Compound types +-- Compound types SELECT x FROM format(JSONEachRow, 'x Array(UUID)', '{"x":["00000000-0000-0000-0000-000000000000","b15f852c-c41a-4fd6-9247-1929c841715e",""]}'); SELECT x FROM format(JSONEachRow, 'x Array(Nullable(IPv6))', '{"x":["",""]}'); SELECT x FROM format(JSONEachRow, 'x Tuple(Date, IPv4, String)', '{"x":["", "", "abc"]}'); SELECT x FROM format(JSONEachRow, 'x Map(String, IPv6)', '{"x":{"abc": ""}}'); SELECT x FROM format(JSONEachRow, 'x Variant(Date, UUID)', '{"x":""}'); -# Deep composition +-- Deep composition SELECT x FROM format(JSONEachRow, 'x Array(Array(IPv6))', '{"x":[["2001:db8:3333:4444:CCCC:DDDD:EEEE:FFFF", ""], ["", "2001:db8:3333:4444:5555:6666:7777:8888"]]}'); SELECT x FROM format(JSONEachRow, 'x Variant(Date, Array(UUID))', '{"x":["", "b15f852c-c41a-4fd6-9247-1929c841715e"]}'); SELECT x FROM format(JSONEachRow, 'x Tuple(Array(UUID), Tuple(UUID, Map(String, IPv6)))', '{"x":[[""], ["",{"abc":""}]]}');