diff --git a/src/Columns/ColumnObject.cpp b/src/Columns/ColumnObject.cpp index 1680f7050c6..5b72b838b99 100644 --- a/src/Columns/ColumnObject.cpp +++ b/src/Columns/ColumnObject.cpp @@ -12,6 +12,7 @@ #include #include #include +#include namespace DB { @@ -823,6 +824,44 @@ MutableColumnPtr ColumnObject::cloneResized(size_t new_size) const return applyForSubcolumns([&](const auto & subcolumn) { return subcolumn.cloneResized(new_size); }); } +void ColumnObject::getPermutation(PermutationSortDirection, PermutationSortStability, size_t, int, Permutation & res) const +{ + res.resize(num_rows); + std::iota(res.begin(), res.end(), 0); +} + +void ColumnObject::compareColumn(const IColumn & rhs, size_t rhs_row_num, + PaddedPODArray * row_indexes, PaddedPODArray & compare_results, + int direction, int nan_direction_hint) const +{ + return doCompareColumn(assert_cast(rhs), rhs_row_num, row_indexes, + compare_results, direction, nan_direction_hint); +} + +void ColumnObject::getExtremes(Field & min, Field & max) const +{ + if (num_rows == 0) + { + min = Object(); + max = Object(); + } + else + { + get(0, min); + get(0, max); + } +} + +MutableColumns ColumnObject::scatter(ColumnIndex num_columns, const Selector & selector) const +{ + return scatterImpl(num_columns, selector); +} + +void ColumnObject::gather(ColumnGathererStream & gatherer) +{ + gatherer.gather(*this); +} + const ColumnObject::Subcolumn & ColumnObject::getSubcolumn(const PathInData & key) const { if (const auto * node = subcolumns.findLeaf(key)) diff --git a/src/Columns/ColumnObject.h b/src/Columns/ColumnObject.h index 594c6e047c4..07099307258 100644 --- a/src/Columns/ColumnObject.h +++ b/src/Columns/ColumnObject.h @@ -15,7 +15,7 @@ namespace DB namespace ErrorCodes { - extern const int LOGICAL_ERROR; + extern const int NOT_IMPLEMENTED; } /// Info that represents a scalar or array field in a decomposed view. @@ -224,6 +224,19 @@ public: ColumnPtr replicate(const Offsets & offsets) const override; MutableColumnPtr cloneResized(size_t new_size) const override; + /// Order of rows in ColumnObject is undefined. + void getPermutation(PermutationSortDirection, PermutationSortStability, size_t, int, Permutation & res) const override; + void compareColumn(const IColumn & rhs, size_t rhs_row_num, + PaddedPODArray * row_indexes, PaddedPODArray & compare_results, + int direction, int nan_direction_hint) const override; + + void updatePermutation(PermutationSortDirection, PermutationSortStability, size_t, int, Permutation &, EqualRanges &) const override {} + int compareAt(size_t, size_t, const IColumn &, int) const override { return 0; } + void getExtremes(Field & min, Field & max) const override; + + MutableColumns scatter(ColumnIndex num_columns, const Selector & selector) const override; + void gather(ColumnGathererStream & gatherer) override; + /// All other methods throw exception. StringRef getDataAt(size_t) const override { throwMustBeConcrete(); } @@ -236,14 +249,7 @@ public: void updateWeakHash32(WeakHash32 &) const override { throwMustBeConcrete(); } void updateHashFast(SipHash &) const override { throwMustBeConcrete(); } void expand(const Filter &, bool) override { throwMustBeConcrete(); } - int compareAt(size_t, size_t, const IColumn &, int) const override { throwMustBeConcrete(); } - void compareColumn(const IColumn &, size_t, PaddedPODArray *, PaddedPODArray &, int, int) const override { throwMustBeConcrete(); } bool hasEqualValues() const override { throwMustBeConcrete(); } - void getPermutation(PermutationSortDirection, PermutationSortStability, size_t, int, Permutation &) const override { throwMustBeConcrete(); } - void updatePermutation(PermutationSortDirection, PermutationSortStability, size_t, int, Permutation &, EqualRanges &) const override { throwMustBeConcrete(); } - MutableColumns scatter(ColumnIndex, const Selector &) const override { throwMustBeConcrete(); } - void gather(ColumnGathererStream &) override { throwMustBeConcrete(); } - void getExtremes(Field &, Field &) const override { throwMustBeConcrete(); } size_t byteSizeAt(size_t) const override { throwMustBeConcrete(); } double getRatioOfDefaultRows(double) const override { throwMustBeConcrete(); } void getIndicesOfNonDefaultRows(Offsets &, size_t, size_t) const override { throwMustBeConcrete(); } @@ -251,7 +257,7 @@ public: private: [[noreturn]] static void throwMustBeConcrete() { - throw Exception("ColumnObject must be converted to ColumnTuple before use", ErrorCodes::LOGICAL_ERROR); + throw Exception("ColumnObject must be converted to ColumnTuple before use", ErrorCodes::NOT_IMPLEMENTED); } template diff --git a/src/DataTypes/Serializations/SerializationObject.cpp b/src/DataTypes/Serializations/SerializationObject.cpp index 7ad7706ae1e..b893407e7a5 100644 --- a/src/DataTypes/Serializations/SerializationObject.cpp +++ b/src/DataTypes/Serializations/SerializationObject.cpp @@ -260,7 +260,12 @@ void SerializationObject::serializeBinaryBulkWithMultipleStreams( auto * state_object = checkAndGetState(state); if (!column_object.isFinalized()) - throw Exception(ErrorCodes::LOGICAL_ERROR, "Cannot write non-finalized ColumnObject"); + { + auto finalized_object = column_object.clone(); + assert_cast(*finalized_object).finalize(); + serializeBinaryBulkWithMultipleStreams(*finalized_object, offset, limit, settings, state); + return; + } auto [tuple_column, tuple_type] = unflattenObjectToTuple(column_object); diff --git a/tests/queries/0_stateless/01825_type_json_order_by.reference b/tests/queries/0_stateless/01825_type_json_order_by.reference new file mode 100644 index 00000000000..611d2835127 --- /dev/null +++ b/tests/queries/0_stateless/01825_type_json_order_by.reference @@ -0,0 +1,6 @@ +0 +0 +{"k":"v"} + +{"k":"v"} +{"k":"v"} diff --git a/tests/queries/0_stateless/01825_type_json_order_by.sql b/tests/queries/0_stateless/01825_type_json_order_by.sql new file mode 100644 index 00000000000..1d5768fe0b4 --- /dev/null +++ b/tests/queries/0_stateless/01825_type_json_order_by.sql @@ -0,0 +1,5 @@ +-- Tags: no-fasttest + +SELECT dummy FROM system.one ORDER BY materialize('{"k":"v"}'::JSON); +SELECT dummy FROM system.one ORDER BY materialize('{"k":"v"}'::JSON), dummy; +SELECT materialize('{"k":"v"}'::JSON) SETTINGS extremes = 1;