diff --git a/dbms/include/DB/Functions/FunctionsArray.h b/dbms/include/DB/Functions/FunctionsArray.h index bc522d7ccb3..ceea7e4de0d 100644 --- a/dbms/include/DB/Functions/FunctionsArray.h +++ b/dbms/include/DB/Functions/FunctionsArray.h @@ -332,8 +332,8 @@ public: for (size_t j = 0; j < num_elements; ++j) out_data.insertFrom(*columns[j], i); - out_offsets[i] = current_offset; current_offset += num_elements; + out_offsets[i] = current_offset; } block.getByPosition(result).column = out; diff --git a/dbms/src/Columns/ColumnConst.cpp b/dbms/src/Columns/ColumnConst.cpp index a77443eb195..3aa75400bfa 100644 --- a/dbms/src/Columns/ColumnConst.cpp +++ b/dbms/src/Columns/ColumnConst.cpp @@ -116,11 +116,18 @@ ColumnPtr ColumnConst::convertToFullColumn() const if (!type) throw Exception("Non-Tuple data type specified for ColumnConstTuple", ErrorCodes::LOGICAL_ERROR); - /// Ask data_type to create ColumnTuple of corresponding type - ColumnPtr res = type->createColumn(); - static_cast(*res).insert(getDataFromHolderImpl()); + /// Create columns for each element and convert to full columns. + const DataTypes & element_types = type->getElements(); + size_t tuple_size = element_types.size(); + Block block; - return res; + for (size_t i = 0; i < tuple_size; ++i) + block.insert(ColumnWithTypeAndName{ + element_types[i]->createConstColumn(s, static_cast(*data)[i])->convertToFullColumnIfConst(), + element_types[i], + ""}); + + return std::make_shared(block); } void ColumnConst::getExtremes(Field & min, Field & max) const diff --git a/dbms/tests/queries/0_stateless/00348_tuples.reference b/dbms/tests/queries/0_stateless/00348_tuples.reference new file mode 100644 index 00000000000..46cad4ce023 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00348_tuples.reference @@ -0,0 +1,18 @@ +('1',2) 1 2 +('1',2) 1 2 +('1',2) 1 2 +('1',2) 1 2 +('1',2) 1 2 +[('1',2)] 1 2 +[('1',2)] 1 2 +[('1',2)] 1 2 +[('1',2)] 1 2 +[('1',2)] 1 2 +[('1',2)] 1 2 +[((1,'2'),[(3,[4])])] ((1,'2'),[(3,[4])]) (1,'2') [(3,[4])] 1 2 (3,[4]) 3 [4] 4 +[('1',4)] +[('1',4)] +[('1',4)] +[('1',4)] +[('1',4)] +[('1',4)] diff --git a/dbms/tests/queries/0_stateless/00348_tuples.sql b/dbms/tests/queries/0_stateless/00348_tuples.sql new file mode 100644 index 00000000000..61125b4aa4c --- /dev/null +++ b/dbms/tests/queries/0_stateless/00348_tuples.sql @@ -0,0 +1,30 @@ +SELECT ('1',2) AS t, t.1, t.2; +SELECT materialize(('1',2)) AS t, t.1, t.2; +SELECT (materialize('1'),2) AS t, t.1, t.2; +SELECT ('1',materialize(2)) AS t, t.1, t.2; +SELECT (materialize('1'),materialize(2)) AS t, t.1, t.2; + +SELECT [('1',2)] AS t, t[1].1, t[1].2; +SELECT [materialize(('1',2))] AS t, t[1].1, t[1].2; +SELECT [(materialize('1'),2)] AS t, t[1].1, t[1].2; +SELECT [('1',materialize(2))] AS t, t[1].1, t[1].2; +SELECT [(materialize('1'),materialize(2))] AS t, t[1].1, t[1].2; +SELECT materialize([('1',2)]) AS t, t[1].1, t[1].2; + +SELECT [((1, materialize('2')), [(3, [4])])] AS thing, + thing[1], + thing[1].1, + thing[1].2, + thing[1].1.1, + thing[1].1.2, + (thing[1].2)[1], + (thing[1].2)[1].1, + (thing[1].2)[1].2, + ((thing[1].2)[1].2)[1]; + +select arrayMap(t->tuple(t.1, t.2*2), [('1',2)]); +select arrayMap(t->tuple(t.1, t.2*2), [materialize(('1',2))]); +select arrayMap(t->tuple(t.1, t.2*2), [(materialize('1'),2)]); +select arrayMap(t->tuple(t.1, t.2*2), [('1',materialize(2))]); +select arrayMap(t->tuple(t.1, t.2*2), [(materialize('1'),materialize(2))]); +select arrayMap(t->tuple(t.1, t.2*2), materialize([('1',2)]));