Avoid reusing columns among different named tuples

This commit is contained in:
Amos Bird 2024-09-29 09:30:44 +08:00
parent 9ae3d85dfe
commit 1c6e7d1ab3
No known key found for this signature in database
GPG Key ID: 80D430DCBECFEDB4
3 changed files with 37 additions and 0 deletions

View File

@ -182,6 +182,30 @@ public:
break;
}
/// Function "tuple" which generates named tuple should use argument aliases to construct its name.
if (function_node.getFunctionName() == "tuple")
{
if (const DataTypeTuple * type_tuple = typeid_cast<const DataTypeTuple *>(function_node.getResultType().get()))
{
if (type_tuple->haveExplicitNames())
{
const auto & names = type_tuple->getElementNames();
size_t size = names.size();
WriteBufferFromOwnString s;
s << "tuple(";
for (size_t i = 0; i < size; ++i)
{
if (i != 0)
s << ", ";
s << names[i];
}
s << ")";
result = s.str();
break;
}
}
}
String in_function_second_argument_node_name;
if (isNameOfInFunction(function_node.getFunctionName()))

View File

@ -0,0 +1 @@
1 ('dete','ok') ('dete','ok')

View File

@ -0,0 +1,12 @@
DROP TABLE IF EXISTS src;
DROP TABLE IF EXISTS dst;
CREATE TABLE src (id UInt32, type String, data String) ENGINE=MergeTree ORDER BY tuple();
CREATE TABLE dst (id UInt32, a Tuple (col_a Nullable(String), type String), b Tuple (col_b Nullable(String), type String)) ENGINE = MergeTree ORDER BY id;
INSERT INTO src VALUES (1, 'ok', 'data');
INSERT INTO dst (id, a, b) SELECT id, tuple(replaceAll(data, 'a', 'e') AS col_a, type) AS a, tuple(replaceAll(data, 'a', 'e') AS col_b, type) AS b FROM src;
SELECT * FROM dst;
DROP TABLE src;
DROP TABLE dst;