Merge pull request #10390 from ClickHouse/fix-flattening-of-array-tuples

Fix flattening of Array(Tuple(...)) data type.
This commit is contained in:
Ilya Yatsishin 2020-04-21 15:41:00 +03:00 committed by GitHub
commit 0ca37c75fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 30 additions and 1 deletions

View File

@ -86,7 +86,8 @@ Block flatten(const Block & block)
{
if (const DataTypeArray * type_arr = typeid_cast<const DataTypeArray *>(elem.type.get()))
{
if (const DataTypeTuple * type_tuple = typeid_cast<const DataTypeTuple *>(type_arr->getNestedType().get()))
const DataTypeTuple * type_tuple = typeid_cast<const DataTypeTuple *>(type_arr->getNestedType().get());
if (type_tuple && type_tuple->haveExplicitNames())
{
const DataTypes & element_types = type_tuple->getElements();
const Strings & names = type_tuple->getElementNames();

View File

@ -17,6 +17,7 @@ namespace Nested
std::string extractTableName(const std::string & nested_name);
/// Replace Array(Tuple(...)) columns to a multiple of Array columns in a form of `column_name.element_name`.
/// only for named tuples that actually represent Nested structures.
Block flatten(const Block & block);
/// Collect Array columns in a form of `column_name.element_name` to single Array(Tuple(...)) column.

View File

@ -61,6 +61,7 @@ public:
/// TODO add ability to rename nested columns
void rename(const String & column_from, const String & column_to);
/// NOTE Must correspond with Nested::flatten function.
void flattenNested(); /// TODO: remove, insert already flattened Nested columns.
bool operator==(const ColumnsDescription & other) const { return columns == other.columns; }

View File

@ -0,0 +1,10 @@
[(nan,1.1460459347849696e-169)] `xbguF 1493493065813843889
[(-2.6774132404843463e217,-1.5941466176583548e-32)] ?/;UTko 8163231169061670909
[(4.559039863342969e-218,1.1023812988249403e186)] k3Igp@ 9512519566588292358
[(-6.156499824044965e254,2.125276757267567e176)] 12763761121429990320
[] TlL 10781278062399783511
[(-1.6511853645079817e-21,-1.5094564365588905e303)] UeS}D 1158449958889177529
[(-5.109297304033652e229,-8.565674764550042e219),(-2.163260216301827e-75,-3.771562357185976e285)] 0Z3|h 12502841092151487477
[] -] 2092132020040612180
[(-2.9588901009588613e-146,-6.4241843242744556e268)] &b!M-e;7 10616749141511339887
[(3.084905744030789e-98,-4.973771413288743e177),(-1.8198487259356486e114,1.2449864950522508e251)] Dj7peUH{T 5992776369613298329

View File

@ -0,0 +1,5 @@
DROP TABLE IF EXISTS mass_table_457;
CREATE TABLE mass_table_457 (key Array(Tuple(Float64, Float64)), name String, value UInt64) ENGINE = Memory;
INSERT INTO mass_table_457 SELECT * FROM generateRandom('`key` Array(Tuple(Float64, Float64)),`name` String,`value` UInt64', 1, 10, 2) LIMIT 10;
SELECT * FROM mass_table_457;
DROP TABLE mass_table_457;

View File

@ -0,0 +1,2 @@
[(123,456),(789,234)] [(567,890)]
[] [(11,22),(33,44),(55,66)]

View File

@ -0,0 +1,9 @@
DROP TABLE IF EXISTS tutorial;
create table tutorial ( inner_poly Array(Tuple(Int32, Int32)), outer_poly Array(Tuple(Int32, Int32)) ) engine = Log();
SELECT * FROM tutorial;
INSERT INTO tutorial VALUES ([(123, 456), (789, 234)], [(567, 890)]), ([], [(11, 22), (33, 44), (55, 66)]);
SELECT * FROM tutorial;
DROP TABLE tutorial;