Repository navigation
Conversation
|
Workflow [PR], commit [c5aacf0] Summary: ❌
AI ReviewSummaryThis PR adds Final Verdict
|
945f359 to
9dc9643
Compare
9dc9643 to
860e0f1
Compare
bf82fc9 to
961906e
Compare
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes50 object files changed (+246.32 KiB total), 0 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units121 translation units recompiled, 1005 s compile time in total, 121 of them have a recent master baseline. |
961906e to
f344597
Compare
a2bd058 to
32d8b50
Compare
32d8b50 to
7c7c7fe
Compare
- Regenerate docs/reference/data-types/newjson.mdx from the JSON
Documentation{} source data instead of hand-editing the
AUTOGENERATED region.
- Initialize weak1/weak2 in gtest_column_object.cpp
(cppcoreguidelines-init-variables with -Werror).
ClickHouse#119389
…efault_path_type test
The query ordered by json.a, json.b, but with DEFAULT PATH TYPE Int64 a
missing path reads as 0, so '{"a":0}' and '{}' compare equal under
random settings that change the sort order. Order by sipHash64(json)
instead.
ClickHouse#119389
…docs
- Drop config_file_for_test.xml and test_truncated_object* leftovers.
- Revert docs/reference/data-types/newjson.mdx: the DEFAULT PATH TYPE
documentation lives in the Documentation{} attached at registerDataType
time; the generated .mdx is refreshed by the docs pipeline and must not
be hand-edited.
ClickHouse#119389
3549ad8 to
b3fba90
Compare
Declare a default type for every non-typed JSON path. Values of non-typed paths are coerced/validated against T during insert (a non-conforming value fails the insert unless type_json_skip_invalid_typed_paths is enabled) and stored as T instead of its natural JSON type: - runtime-discovered dynamic paths are stored as sparse Variant(T) columns instead of Dynamic; - shared data stores values as bare T (Array(Tuple(String, T))) instead of self-describing Dynamic blobs. Nullable, Dynamic, Variant and Object are rejected as DEFAULT PATH TYPE. Missing paths read as default(T) and never appear in output, path enumeration or hashes, even after merges move paths between subcolumn and shared storage; an explicit default(T) value is a real value and is distinguishable from a missing path. Binary encoding version 1 adds the DEFAULT PATH TYPE argument to the JSON type encoding (see data-types-binary-encoding.mdx). ClickHouse#119389
68ed74c to
3b6e26d
Compare
|
Status: 3b6e26d is the final tree (rebased on master 5ac4352, single commit). Fixes this round: (1) conflict with the Native-format OOB fix in SerializationObjectSharedData resolved; (2) regression in extractCombinedSubcolumn — skip rules must not be propagated into the synthetic sub-object type (05237_json_combined_subcolumn_skip_rules now passes, verified locally); (3) DPT tests tagged no-fasttest. Remaining failure is Fast test 'Server liveness check failed' — a widespread flake this week (6 distinct PRs in the last 3h: 113399, 120466, 122973, 122982, 114812, 119389), 0 test failures in the run. Needs a maintainer re-run of the Fast test job. |
3b6e26d to
80040fd
Compare
Declare a default type for every non-typed JSON path. Values of non-typed paths are coerced/validated against T during insert (a non-conforming value fails the insert unless type_json_skip_invalid_typed_paths is enabled) and stored as T instead of its natural JSON type: - runtime-discovered dynamic paths are stored as sparse Variant(T) columns instead of Dynamic; - shared data stores values as bare T (Array(Tuple(String, T))) instead of self-describing Dynamic blobs. Nullable, Dynamic, Variant and Object are rejected as DEFAULT PATH TYPE. Missing paths read as default(T) and never appear in output, path enumeration or hashes, even after merges move paths between subcolumn and shared storage; an explicit default(T) value is a real value and is distinguishable from a missing path in MAP shared-data serialization. With the ADVANCED shared-data serialization the dense bare-T path columns cannot distinguish an explicit default(T) value from a missing path, matching the typed-path read which returns default(T) for a missing path. The individual-value binary serde (RowBinary, Native) uses one on-wire encoding for every non-typed DPT path — the value coerced to T, serialized as bare T, wrapped in a length-prefixed blob — independent of whether the sender kept the path in a runtime path or in shared data; the Field overloads and the skip path follow the same contract. Binary encoding version 1 adds the DEFAULT PATH TYPE argument to the JSON type encoding (see data-types-binary-encoding.mdx). ClickHouse#119389
|
This is a repo-wide flake, not caused by this change:
@groeneai, investigate the failure: Fast test on 80040fd0 and provide a fix in a separate PR (this looks related to the |
|
Acknowledged. I'm investigating the |
|
I looked into it: on this PR it is not a flake, the server crashes. On
The harness part is real, and it is mine: when the server process is gone, the hung check still reports |
|
Here is the separate PR: #124032 With it, a server that dies mid-run is reported as |
80040fd to
09a5b08
Compare
`DEFAULT PATH TYPE T` declares the type of every path of a `JSON` column that has no explicit type hint. On insert, values of such paths are converted to `T`; a value that cannot be converted fails the insert unless `type_json_skip_invalid_typed_paths` is enabled, and JSON `null` means the path is missing. `T` cannot be `Nullable`, `LowCardinality(Nullable)`, `Dynamic`, `Variant`, `JSON` or `Nothing`. Storage: - dynamic paths are sparse `Variant(T)` columns instead of `Dynamic`, where NULL means the path is missing in the row; - shared data stores values as `T` (`Array(Tuple(String, T))`); - the individual-value binary serialization (used by the `RowBinary` formats) writes each non-typed value as a length-prefixed `T` blob. With the `advanced` shared data serialization a stored `default(T)` is not distinguishable from a missing path when reading a single path. The JSON type binary encoding uses version 1 with an appended encoded `T` only when the modifier is present, so the encoding of other `JSON` types is unchanged. Without the modifier nothing changes. Tests: `05338_json_default_path_type`, `05339_json_default_path_type_storage`, and gtests in `gtest_column_object.cpp` and `gtest_data_types_binary_encoding.cpp`. ClickHouse#119389
`DEFAULT PATH TYPE T` declares the type of every path of a `JSON` column that has no explicit type hint. On insert, values of such paths are converted to `T`; a value that cannot be converted fails the insert unless `type_json_skip_invalid_typed_paths` is enabled, and JSON `null` means the path is missing. `T` cannot be `Nullable`, `LowCardinality(Nullable)`, `Dynamic`, `Variant`, `JSON` or `Nothing`. Storage: - dynamic paths are sparse `Variant(T)` columns instead of `Dynamic`, where NULL means the path is missing in the row; - shared data stores values as `T` (`Array(Tuple(String, T))`); - the individual-value binary serialization (used by the `RowBinary` formats) writes each non-typed value as a length-prefixed `T` blob. With the `advanced` shared data serialization a stored `default(T)` is not distinguishable from a missing path when reading a single path. The JSON type binary encoding uses version 1 with an appended encoded `T` only when the modifier is present, so the encoding of other `JSON` types is unchanged. Without the modifier nothing changes. Tests: `05338_json_default_path_type`, `05339_json_default_path_type_storage`, and gtests in `gtest_column_object.cpp` and `gtest_data_types_binary_encoding.cpp`. ClickHouse#119389
09a5b08 to
9dffed7
Compare
`DEFAULT PATH TYPE T` declares the type of every path of a `JSON` column that has no explicit type hint. On insert, values of such paths are converted to `T`; a value that cannot be converted fails the insert unless `type_json_skip_invalid_typed_paths` is enabled, and JSON `null` means the path is missing. `T` cannot be `Nullable`, `LowCardinality(Nullable)`, `Dynamic`, `Variant`, `JSON` or `Nothing`. Storage: - dynamic paths are sparse `Variant(T)` columns instead of `Dynamic`, where NULL means the path is missing in the row; - shared data stores values as `T` (`Array(Tuple(String, T))`); - the individual-value binary serialization (used by the `RowBinary` formats) writes each non-typed value as a length-prefixed `T` blob. With the `advanced` shared data serialization a stored `default(T)` is not distinguishable from a missing path when reading a single path. The JSON type binary encoding uses version 1 with an appended encoded `T` only when the modifier is present, so the encoding of other `JSON` types is unchanged. Without the modifier nothing changes. `generateRandom` produces `T` values for non-typed paths of such columns, and `ColumnObject` rejects dynamic path and shared data columns whose layout disagrees with its default path type. Tests: `05338_json_default_path_type`, `05339_json_default_path_type_storage`, and gtests in `gtest_column_object.cpp` and `gtest_data_types_binary_encoding.cpp`. ClickHouse#119389
9dffed7 to
16cde35
Compare
`DEFAULT PATH TYPE T` declares the type of every path of a `JSON` column that has no explicit type hint. On insert, values of such paths are converted to `T`; a value that cannot be converted fails the insert unless `type_json_skip_invalid_typed_paths` is enabled, and JSON `null` means the path is missing. `T` cannot be `Nullable`, `LowCardinality(Nullable)`, `Dynamic`, `Variant`, `JSON` or `Nothing`. Storage: - dynamic paths are sparse `Variant(T)` columns instead of `Dynamic`, where NULL means the path is missing in the row; - shared data stores values as `T` (`Array(Tuple(String, T))`); - the individual-value binary serialization (used by the `RowBinary` formats) writes each non-typed value as a length-prefixed `T` blob. With the `advanced` shared data serialization a stored `default(T)` is not distinguishable from a missing path when reading a single path. The JSON type binary encoding uses version 1 with an appended encoded `T` only when the modifier is present, so the encoding of other `JSON` types is unchanged. Without the modifier nothing changes. `generateRandom` produces `T` values for non-typed paths of such columns, and `ColumnObject` rejects dynamic path and shared data columns whose layout disagrees with its default path type. Tests: `05338_json_default_path_type`, `05339_json_default_path_type_storage`, and gtests in `gtest_column_object.cpp` and `gtest_data_types_binary_encoding.cpp`. ClickHouse#119389
16cde35 to
6c6d50b
Compare
`DEFAULT PATH TYPE T` declares the type of every path of a `JSON` column that has no explicit type hint. On insert, values of such paths are converted to `T`; a value that cannot be converted fails the insert unless `type_json_skip_invalid_typed_paths` is enabled, and JSON `null` means the path is missing. `T` cannot be `Nullable`, `LowCardinality(Nullable)`, `Dynamic`, `Variant`, `JSON` or `Nothing`. Storage: - dynamic paths are sparse `Variant(T)` columns instead of `Dynamic`, where NULL means the path is missing in the row; - shared data stores values as `T` (`Array(Tuple(String, T))`); - the individual-value binary serialization (used by the `RowBinary` formats) writes each non-typed value as a length-prefixed `T` blob. With the `advanced` shared data serialization a stored `default(T)` is not distinguishable from a missing path when reading a single path. The JSON type binary encoding uses version 1 with an appended encoded `T` only when the modifier is present, so the encoding of other `JSON` types is unchanged. Without the modifier nothing changes. `generateRandom` and the Parquet variant reader produce `T` values for non-typed paths of such columns, and `ColumnObject` rejects dynamic path and shared data columns whose layout disagrees with its default path type. Tests: `05338_json_default_path_type`, `05339_json_default_path_type_storage`, `05355_json_default_path_type_parquet_variant`, and gtests in `gtest_column_object.cpp` and `gtest_data_types_binary_encoding.cpp`. ClickHouse#119389
6c6d50b to
c51df89
Compare
`DEFAULT PATH TYPE T` declares the type of every path of a `JSON` column that has no explicit type hint. On insert, values of such paths are converted to `T`; a value that cannot be converted fails the insert unless `type_json_skip_invalid_typed_paths` is enabled, and JSON `null` means the path is missing. `T` cannot be `Nullable`, `LowCardinality(Nullable)`, `Dynamic`, `Variant`, `JSON` or `Nothing`. Storage: - dynamic paths are sparse `Variant(T)` columns instead of `Dynamic`, where NULL means the path is missing in the row; - shared data stores values as `T` (`Array(Tuple(String, T))`); - the individual-value binary serialization (used by the `RowBinary` formats) writes each non-typed value as a length-prefixed `T` blob. With the `advanced` shared data serialization a stored `default(T)` is not distinguishable from a missing path when reading a single path. The JSON type binary encoding uses version 1 with an appended encoded `T` only when the modifier is present, so the encoding of other `JSON` types is unchanged. Without the modifier nothing changes. Values of non-typed paths inserted as a `Field` are converted to `T` like `CAST`. `generateRandom` and the Parquet variant reader produce `T` values for non-typed paths, and `ColumnObject` rejects dynamic path and shared data columns whose layout disagrees with its default path type. The `Native` format documentation describes the layout of such columns. Also fix the binary deserialization of `JSON` with a duplicated typed path and `type_json_skip_duplicated_paths=1`: the skipped value was not consumed, so the rest of the row was read from the middle of it. Tests: `05338_json_default_path_type`, `05339_json_default_path_type_storage`, `05355_json_default_path_type_parquet_variant`, and gtests in `gtest_column_object.cpp` and `gtest_data_types_binary_encoding.cpp`. ClickHouse#119389
c51df89 to
10b60f0
Compare
`DEFAULT PATH TYPE T` declares the type of every path of a `JSON` column that has no explicit type hint. On insert, values of such paths are converted to `T`; a value that cannot be converted fails the insert unless `type_json_skip_invalid_typed_paths` is enabled, and JSON `null` means the path is missing. `T` cannot be `Nullable`, `LowCardinality(Nullable)`, `Dynamic`, `Variant`, `JSON` or `Nothing`. Storage: - dynamic paths are sparse `Variant(T)` columns instead of `Dynamic`, where NULL means the path is missing in the row; - shared data stores values as `T` (`Array(Tuple(String, T))`); - the individual-value binary serialization (used by the `RowBinary` formats) writes each non-typed value as a length-prefixed `T` blob. With the `advanced` shared data serialization a stored `default(T)` is not distinguishable from a missing path when reading a single path. The JSON type binary encoding uses version 1 with an appended encoded `T` only when the modifier is present, so the encoding of other `JSON` types is unchanged. Without the modifier nothing changes. Values of non-typed paths inserted as a `Field` are converted to `T` like `CAST`. `generateRandom` and the Parquet variant reader produce `T` values for non-typed paths (the Parquet reader honors `type_json_skip_invalid_typed_paths` for them), and `ColumnObject` rejects dynamic path and shared data columns whose layout disagrees with its default path type. The `Native` format documentation describes the layout of such columns. Also fix the binary deserialization of `JSON` with a duplicated typed path and `type_json_skip_duplicated_paths=1`: the skipped value was not consumed, so the rest of the row was read from the middle of it. Tests: `05338_json_default_path_type`, `05339_json_default_path_type_storage`, `05355_json_default_path_type_parquet_variant`, and gtests in `gtest_column_object.cpp` and `gtest_data_types_binary_encoding.cpp`. ClickHouse#119389
10b60f0 to
f5bca90
Compare
`DEFAULT PATH TYPE T` declares the type of every path of a `JSON` column that has no explicit type hint. On insert, values of such paths are converted to `T`; a value that cannot be converted fails the insert unless `type_json_skip_invalid_typed_paths` is enabled, and JSON `null` means the path is missing. `T` cannot be `Nullable`, `LowCardinality(Nullable)`, `Dynamic`, `Variant`, `JSON` or `Nothing`. Storage: - dynamic paths are sparse `Variant(T)` columns instead of `Dynamic`, where NULL means the path is missing in the row; - shared data stores values as `T` (`Array(Tuple(String, T))`); - the individual-value binary serialization (used by the `RowBinary` formats) writes each non-typed value as a length-prefixed `T` blob. With the `advanced` shared data serialization a stored `default(T)` is not distinguishable from a missing path when reading a single path. The JSON type binary encoding uses version 1 with an appended encoded `T` only when the modifier is present, so the encoding of other `JSON` types is unchanged. Without the modifier nothing changes. Values of non-typed paths inserted as a `Field` are converted to `T` like `CAST`. `generateRandom` and the Parquet variant reader produce `T` values for non-typed paths (the Parquet reader honors `type_json_skip_invalid_typed_paths` for them; like the `JSON` text input, a skipped value does not take a slot of `max_dynamic_paths`), and `ColumnObject` rejects dynamic path and shared data columns whose layout disagrees with its default path type. The `Native` format documentation describes the layout of such columns. Also fix the binary deserialization of `JSON` with a duplicated typed path and `type_json_skip_duplicated_paths=1`: the skipped value was not consumed, so the rest of the row was read from the middle of it. Tests: `05338_json_default_path_type`, `05339_json_default_path_type_storage`, `05355_json_default_path_type_parquet_variant`, and gtests in `gtest_column_object.cpp` and `gtest_data_types_binary_encoding.cpp`. ClickHouse#119389
Avogar
left a comment
There was a problem hiding this comment.
Thanks, the overall looks good. I left some comments as a first review round, mostly about the serialization part and keeping plain JSON hot paths unaffected. I'll do a more detailed pass after these are addressed.
| if (isNullableOrLowCardinalityNullable(default_path_type) || type_id == TypeIndex::Nothing || type_id == TypeIndex::Variant | ||
| || type_id == TypeIndex::Dynamic || type_id == TypeIndex::Object) | ||
| throw Exception(ErrorCodes::BAD_ARGUMENTS, | ||
| "DEFAULT PATH TYPE {} is not allowed in {} type: Nullable, Nothing, Dynamic, Variant and Object types are not supported", | ||
| default_path_type->getName(), magic_enum::enum_name(schema_format)); |
There was a problem hiding this comment.
I don't like that we don't support Nullable(T) as default type. And I don't see any problems with adding support for that. We have all information about nulls already:
- In dynamic paths we use
Variant(T)and its subcolumnVariant(T).Tis naturallyNullable(T), so we don't need to do anything, forTwe just need to removeNullablefrom this subcolumn during read/extraction. - In shared data we store rows without
null, so if row doesn't contain the value we just insert default in the destination subcolumn, which isnullforNullable(T).
The only problem is that you use T in advanced shared datain per-granule columns of dynamic paths. But we just need to use Variant(T) there instead of T. Also because sub-object/combined subcolumn uses these columns and should keep the information about rows with nulls (which we loose when we use just T here).
So let's support Nullable(T) as default type and switch to Variant(T) in advanced shared data serialization.
| /// Use StringHashForHeterogeneousLookup hash for hash maps to be able to use std::string_view in find() method. | ||
| using PathToColumnMap = UnorderedMapWithMemoryTracking<String, WrappedPtr, StringHashForHeterogeneousLookup, StringHashForHeterogeneousLookup::transparent_key_equal>; | ||
| using PathToDynamicColumnPtrMap = UnorderedMapWithMemoryTracking<String, ColumnDynamic *, StringHashForHeterogeneousLookup, StringHashForHeterogeneousLookup::transparent_key_equal>; | ||
| using PathToDynamicColumnPtrMap = UnorderedMapWithMemoryTracking<String, IColumn *, StringHashForHeterogeneousLookup, StringHashForHeterogeneousLookup::transparent_key_equal>; |
There was a problem hiding this comment.
Changing ColumnDynamic * to IColumn * here removes all benefits from using PathToDynamicColumnPtrMap. Originally it was added to avoid virtual calls on IColumn on hot loops over dynamic paths. With default type we can switch to ColumnVariant *. Not sure how to implement it in a good way, maybe we just need 2 maps and decide what to use based on presense of the default path type. Smth like this:
/// ColumnObject.h
template <bool has_default_path_type>
using DynamicPathColumn = std::conditional_t<has_default_path_type, ColumnVariant, ColumnDynamic>;
template <bool has_default_path_type>
using PathToDynamicColumnPtrMap = UnorderedMapWithMemoryTracking<String, DynamicPathColumn<has_default_path_type> *, ...>;
/// One of them is always empty.
PathToDynamicColumnPtrMap<false> dynamic_paths_ptrs;
PathToDynamicColumnPtrMap<true> variant_paths_ptrs;
template <bool has_default_path_type>
auto & getDynamicPathsPtrs()
{
if constexpr (has_default_path_type)
return variant_paths_ptrs;
else
return dynamic_paths_ptrs;
}
/// ColumnObject.cpp
void ColumnObject::popBack(size_t n)
{
if (default_path_type)
popBackImpl<true>(n);
else
popBackImpl<false>(n);
}
template <bool has_default_path_type>
void ColumnObject::popBackImpl(size_t n)
{
for (auto & [_, column] : typed_paths)
column->popBack(n);
for (auto & [_, column] : getDynamicPathsPtrs<has_default_path_type>())
column->popBack(n);
shared_data->popBack(n);
}Or maybe you will have better idea.
| const ColumnArray::Offsets & getSharedDataOffsets() const { return assert_cast<const ColumnArray &>(*shared_data).getOffsets(); } | ||
|
|
||
| std::pair<ColumnString *, ColumnString *> getSharedDataPathsAndValues() | ||
| std::pair<ColumnString *, IColumn *> getSharedDataPathsAndValues() |
There was a problem hiding this comment.
Same problem here, we will pay virtual calls on IColumn now on hot paths where we need ColumnString methods in plain JSON with no default type.
There was a problem hiding this comment.
And changes below this are related to the problem
| /// With `DEFAULT PATH TYPE T` the value of a non-typed path in row binary formats is a | ||
| /// length-prefixed blob with the binary serialization of `T`. | ||
| template <typename Serialize> | ||
| void writeDefaultPathTypeValue(WriteBuffer & ostr, const Serialize & serialize) | ||
| { | ||
| WriteBufferFromOwnString value_buf; | ||
| serialize(value_buf); | ||
| writeStringBinary(value_buf.str(), ostr); | ||
| } | ||
|
|
||
| /// Reads (or skips) the blob written by `writeDefaultPathTypeValue`. | ||
| String readDefaultPathTypeValue(ReadBuffer & istr, const FormatSettings & settings) | ||
| { | ||
| String value; | ||
| readStringBinary(value, istr, settings.binary.max_binary_string_size ? settings.binary.max_binary_string_size : SerializationString::MAX_STRING_SIZE); | ||
| return value; | ||
| } | ||
|
|
||
| template <typename Deserialize> | ||
| void deserializeDefaultPathTypeValue(const String & value, const Deserialize & deserialize) | ||
| { | ||
| ReadBufferFromString buf(value); | ||
| deserialize(buf); | ||
| if (!buf.eof()) | ||
| throw Exception(ErrorCodes::INCORRECT_DATA, "Unexpected trailing data in the binary value of a JSON path with default path type"); | ||
| } |
There was a problem hiding this comment.
I don't understand why we need this. We know T in advance and we can serialize/deserialize into the T column directly. And when we need to read into the shared data we can use readParsedValueIntoString just like we do it for Dynamic paths right now. This whole logic of size + serialized value as string is not needed here at all in my opinion.
| @@ -1169,13 +1212,31 @@ void SerializationObject::deserializeBinaryBulkWithMultipleStreams( | |||
| void SerializationObject::serializeBinary(const Field & field, WriteBuffer & ostr, const DB::FormatSettings & settings) const | |||
There was a problem hiding this comment.
This code looks strange. I would expect the coming Field to have already converted types, so for each path:
- if it's a typed path, it has value of the corresponding type
- if it's not a typed path and default path type is enabled, it has exactly value of thistype
- otherwise it has valud of any type and Dynamic handles it
This is not the place we should convert fields to the expected types.
is_missing_path is also not needed here. If default type is non Nullable type, we should not get nulls anyhow, if it's Nullable(T) and somehow we got null here, we can safely write it in binary serialization, because we would use default type serialization which is Nullable serialization.
| } | ||
|
|
||
| /// Shared data values are `String` (binary `Dynamic` values) for ordinary JSON and `T` with `DEFAULT PATH TYPE T`. | ||
| void serializeCopyValues(const IColumn & values_column, const DataTypePtr & default_path_type, WriteBuffer & ostr, size_t offset, size_t limit) |
There was a problem hiding this comment.
I don't understand why we use for loop + serializeBinary/deserializeBinary. We just need to save somewhere the values serialization and use regular shared_data_values_serialization-> serializeBinaryBulkWithMultipleStreams()/shared_data_values_serialization-> deserializeBinaryBulkWithMultipleStreams(). It's ok to serialize values into different streams.
|
|
||
| /// With `DEFAULT PATH TYPE T` shared data values have type `T`. Fills either a `T` column | ||
| /// (a missing path is `default(T)`) or a `Variant(T)` column (a missing path is NULL). | ||
| void fillDefaultPathTypeColumnFromSharedData(IColumn & path_column, std::string_view path, const IColumn & shared_data_column, size_t start, size_t end) |
There was a problem hiding this comment.
Let's move it to the ColumnObject::fillPathColumnFromSharedData. This method should decide based on the default type presence how to fill the path from shared data.
| /// With `DEFAULT PATH TYPE T` convert values of all non-typed paths to `T` like `CAST` before changing | ||
| /// any subcolumn, so a value that cannot be converted to `T` doesn't leave subcolumns misaligned. |
There was a problem hiding this comment.
I would expect fields to be already converted here. As we expect it for any other typed subcolumns. Probably we need to implement the conversion somewhere in convertFieldToType
| auto & shared_data_values_chars = shared_data_values->getChars(); | ||
| if (const auto * variant = typeid_cast<const ColumnVariant *>(&column)) | ||
| { | ||
| shared_data_values->insertFrom(variant->getVariantByLocalDiscriminator(0), variant->offsetAt(n)); |
There was a problem hiding this comment.
There are many places that work with the values of dynamic paths of JSON with default path type by hand: getVariantByLocalDiscriminator(0)/getVariantByGlobalDiscriminator(0) + offsetAt(n) to read a value, insertIntoVariantFrom(0, ...) to insert one, deserializeBinaryIntoVariant(0, default_path_type->getDefaultSerialization(), ...) to deserialize one, and in JSONExtractTree::insertIntoDynamicPath even a manual push of the local discriminator and the offset. Local and global discriminators are mixed (it works only because there is a single variant), and the knowledge of how a dynamic path stores its values is spread over ColumnObject, SerializationObject, JSONExtractTree, Parquet decoding, Analyzer and aggregate functions.
Let's encapsulate it in methods of ColumnObject and use them everywhere instead. For example:
/// For `JSON(DEFAULT PATH TYPE T)`: dynamic paths are `Variant(T)`, where NULL means the path is absent in the row.
/// The column with values of type `T` of the dynamic path and the row in it with the value of row `n`.
/// The path must be present in row `n`.
std::pair<const IColumn &, size_t> getDynamicPathValue(const ColumnVariant & path_column, size_t n) const;
/// Appends value `n` of the column `src` of type `T` to the dynamic path.
void insertDynamicPathValueFrom(ColumnVariant & path_column, const IColumn & src, size_t n) const;
/// Binary serialization of the value of row `n` and deserialization of a value appended to the dynamic path.
void serializeDynamicPathValueBinary(const ColumnVariant & path_column, size_t n, WriteBuffer & ostr, const FormatSettings & settings) const;
void deserializeDynamicPathValueBinary(ColumnVariant & path_column, ReadBuffer & istr, const FormatSettings & settings) const;This is only an example, feel free to choose the methods and names you like. The point is that the layout of a dynamic path is handled in one place. As methods of ColumnObject they can also check that the object has default path type and use the default_path_serialization stored in the column, so callers don't need to pass default_path_type->getDefaultSerialization() around.
| /// Only streams that contain nothing but a prefix: with `DEFAULT PATH TYPE` the dynamic paths are `Variant(T)`, | ||
| /// whose discriminators stream holds the prefix followed by data, and it can be shared with an already | ||
| /// positioned subcolumn reader, so seeking it to the start here would break that reader. | ||
| auto enumerate_callback = [&](const SubstreamPath & path) | ||
| { | ||
| if (hasPrefix(path)) | ||
| if (hasPrefix(path, /*use_specialized_prefixes_and_suffixes_substreams=*/ true)) |
There was a problem hiding this comment.
This doesn't seem to be the right place to change anything. SerializationObject should know nothing about reader logic and seeking of the stream outside, it just has one job - call the callback on newly discovered streams. It it should workf for any prefixes out of the box, not only for specific prefixes stored in separate files.
Probably we need a fix in the reader in the prefixes_prefetch_callback callback. Or even propagate some dynamic_streams_enumerate_callback instead and on reader side decide what to do with new dynamic streams, either prefetch something like prefixes of not
Add a
DEFAULT PATH TYPE Targument to theJSONdata type that declares the type of values of all non-typed paths.Values of non-typed paths are coerced/validated against
Tat insert (a non-conforming value fails the insert unlesstype_json_skip_invalid_typed_pathsis enabled; JSONnullis treated as a missing path). Runtime-discovered dynamic paths are stored as sparseVariant(T)columns instead ofDynamic, and shared data stores bareTvalues (Array(Tuple(String, T))) instead of self-describingDynamicblobs.Nullable,Dynamic,VariantandObjectare rejected asDEFAULT PATH TYPE.Missing paths read as
default(T)and never appear in output, path enumeration or hashes, even after merges move paths between subcolumn and shared storage. An explicitdefault(T)value is a real value, distinguishable from a missing path in MAP shared-data serialization; with the ADVANCED shared-data serialization the dense bare-T path columns cannot distinguish an explicitdefault(T)from a missing path, matching the typed-path read which returnsdefault(T)for a missing path.Binary encoding version 1 adds the
DEFAULT PATH TYPEargument to theJSONtype encoding.Tests:
03553_json_default_path_type(coercion, runtime paths, merges, sub-object and combined subcolumns, nested paths, GROUP BY weak hashes, changingDEFAULT PATH TYPE) and03553_json_default_path_type_storage(map/map_with_buckets/advanced × compact/wide).Changelog category (leave one):
Changelog entry:
Add a
DEFAULT PATH TYPE Targument to theJSONdata type that declares the type of values of all non-typed paths.Documentation entry for user-facing changes
Workflow [PR]
Sync PR [sync-upstream/pr/119389]