-
Notifications
You must be signed in to change notification settings - Fork 4k
[fix](struct) Keep nested field comments and names #68307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
csun5285
wants to merge
2
commits into
apache:master
Choose a base branch
from
csun5285:fix/struct-type-sql-roundtrip
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+343
−33
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
be/test/exec/schema_scanner/schema_columns_scanner_test.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| #include "information_schema/schema_columns_scanner.h" | ||
|
|
||
| #include <gen_cpp/FrontendService_types.h> | ||
| #include <gen_cpp/Types_types.h> | ||
| #include <gtest/gtest.h> | ||
|
|
||
| #include <string> | ||
|
|
||
| namespace doris { | ||
|
|
||
| namespace { | ||
|
|
||
| TColumnDesc make_desc(const std::string& name, TPrimitiveType::type type) { | ||
| TColumnDesc desc; | ||
| desc.__set_columnName(name); | ||
| desc.__set_columnType(type); | ||
| return desc; | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| // COLUMN_TYPE is the text information_schema clients read a schema back from, so a | ||
| // STRUCT has to name its fields there. The names arrive lower cased from the FE, while | ||
| // SHOW CREATE TABLE keeps the spelling the user wrote. | ||
| class SchemaColumnsScannerTest : public testing::Test { | ||
| protected: | ||
| std::string type_to_string(TColumnDesc& desc) { return _scanner._type_to_string(desc); } | ||
|
|
||
| private: | ||
| SchemaColumnsScanner _scanner; | ||
| }; | ||
|
|
||
| TEST_F(SchemaColumnsScannerTest, struct_type_string_carries_field_names) { | ||
| TColumnDesc desc = make_desc("st", TPrimitiveType::STRUCT); | ||
| desc.__set_children( | ||
| {make_desc("f1", TPrimitiveType::INT), make_desc("f2", TPrimitiveType::STRING)}); | ||
|
|
||
| EXPECT_EQ("struct<f1:int(11),f2:string>", type_to_string(desc)); | ||
| } | ||
|
|
||
| TEST_F(SchemaColumnsScannerTest, nested_struct_type_string_carries_field_names) { | ||
| TColumnDesc element = make_desc("item", TPrimitiveType::STRUCT); | ||
| element.__set_children({make_desc("deep", TPrimitiveType::INT)}); | ||
|
|
||
| // An array element has no name of its own, only the struct fields are named. | ||
| TColumnDesc arr = make_desc("arr", TPrimitiveType::ARRAY); | ||
| arr.__set_children({element}); | ||
|
|
||
| TColumnDesc outer = make_desc("outer", TPrimitiveType::STRUCT); | ||
| outer.__set_children({arr}); | ||
|
|
||
| EXPECT_EQ("struct<arr:array<struct<deep:int(11)>>>", type_to_string(outer)); | ||
| } | ||
|
|
||
| TEST_F(SchemaColumnsScannerTest, struct_field_name_holding_a_separator_is_quoted) { | ||
| // These names are legal, they are declared with back quotes. Printed raw they would make | ||
| // the text impossible to split back into fields. | ||
| TColumnDesc desc = make_desc("st", TPrimitiveType::STRUCT); | ||
| desc.__set_children( | ||
| {make_desc("a,b", TPrimitiveType::INT), make_desc("c:d", TPrimitiveType::INT), | ||
| make_desc("e<f>", TPrimitiveType::INT), make_desc("g`h", TPrimitiveType::INT)}); | ||
|
|
||
| EXPECT_EQ("struct<`a,b`:int(11),`c:d`:int(11),`e<f>`:int(11),`g``h`:int(11)>", | ||
| type_to_string(desc)); | ||
| } | ||
|
|
||
| TEST_F(SchemaColumnsScannerTest, plain_struct_field_name_stays_bare) { | ||
| TColumnDesc desc = make_desc("st", TPrimitiveType::STRUCT); | ||
| desc.__set_children({make_desc("a-b", TPrimitiveType::INT), | ||
| make_desc("f 2", TPrimitiveType::INT), | ||
| make_desc("order", TPrimitiveType::INT)}); | ||
|
|
||
| // A hyphen, a space or a keyword carries no meaning in this text, so leave them alone. | ||
| EXPECT_EQ("struct<a-b:int(11),f 2:int(11),order:int(11)>", type_to_string(desc)); | ||
| } | ||
|
|
||
| TEST_F(SchemaColumnsScannerTest, empty_struct_type_string) { | ||
| TColumnDesc desc = make_desc("st", TPrimitiveType::STRUCT); | ||
| EXPECT_EQ("struct<>", type_to_string(desc)); | ||
| } | ||
|
|
||
| // Array and map keep printing types only, they have no field names to carry. | ||
| TEST_F(SchemaColumnsScannerTest, array_and_map_type_string_unchanged) { | ||
| TColumnDesc arr = make_desc("arr", TPrimitiveType::ARRAY); | ||
| arr.__set_children({make_desc("item", TPrimitiveType::INT)}); | ||
| EXPECT_EQ("array<int(11)>", type_to_string(arr)); | ||
|
|
||
| TColumnDesc mp = make_desc("mp", TPrimitiveType::MAP); | ||
| mp.__set_children( | ||
| {make_desc("key", TPrimitiveType::STRING), make_desc("value", TPrimitiveType::INT)}); | ||
| EXPECT_EQ("map<string,int(11)>", type_to_string(mp)); | ||
| } | ||
|
|
||
| } // namespace doris |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
regression-test/data/datatype_p0/nested_types/ddl/test_struct_nested_comment_ddl.out
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| -- This file is automatically generated. You should know what you did if you want to edit this | ||
| -- !show_create -- | ||
| struct_nested_comment CREATE TABLE `struct_nested_comment` (\n `id` int NULL,\n `s` struct<a:int,b:text comment "owner''s \\\\path",c:int> NULL COMMENT "top-level",\n `n` struct<lvl1:struct<lvl2:int comment "deep doc">> NULL,\n `arr` array<struct<inside:int comment "in array">> NULL\n) ENGINE=OLAP\nDUPLICATE KEY(`id`)\nDISTRIBUTED BY HASH(`id`) BUCKETS 1\nPROPERTIES (\n"replication_allocation" = "tag.location.default: 1",\n"min_load_replica_num" = "-1",\n"is_being_synced" = "false",\n"storage_medium" = "hdd",\n"storage_format" = "V2",\n"inverted_index_storage_format" = "V3",\n"light_schema_change" = "true",\n"disable_auto_compaction" = "false",\n"group_commit_interval_ms" = "10000",\n"group_commit_data_bytes" = "134217728"\n); | ||
|
|
||
| -- !column_type -- | ||
| arr array array<struct<inside:int(11)>> | ||
| id int int(11) | ||
| n struct struct<lvl1:struct<lvl2:int(11)>> | ||
| s struct struct<a:int(11),b:string,c:int(11)> | ||
|
|
||
| -- !column_type_quoting -- | ||
| id int(11) | ||
| s struct<`a,b`:int(11),`c:d`:int(11),`e<f>`:int(11),plain:int(11)> | ||
|
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P2] Pin the CCR parser to this canonical SQL mode
This forces synced DDL to ordinary backslash-escape mode, so one stored backslash is serialized as two. However,
CreateTableRecordcarries only the SQL, and the current CCRCreateTableOrView->Spec.Execpath executes it through a pooleddb.Execwithout settingsql_mode. If the destination global mode includesNO_BACKSLASH_ESCAPESbefore CCR opens its connection, that session reads both backslashes literally and stores two, so nested comments still diverge across clusters. This is downstream of the earlier interactive-mode thread: generation is now canonical, but the consumer's parse context is not. Please pin ordinary mode and execute CREATE on the same physical connection (or use a mode-independent representation), then cover differing source/target modes.