diff options
author | udovichenko-r <[email protected]> | 2022-04-22 19:55:20 +0300 |
---|---|---|
committer | udovichenko-r <[email protected]> | 2022-04-22 19:55:20 +0300 |
commit | e3f6e44d787332f3dd5a645ef4a388da529032df (patch) | |
tree | c8169de68430d4fecd53e3fdca815607d90b83c5 | |
parent | eb96602aa423e6058480538df91caed98d51884c (diff) |
[YQL-14732] Use Optional at top level in type string
ref:74fed2bdc1cd02ecef9478d2898b8fce0cec00d7
3 files changed, 32 insertions, 6 deletions
diff --git a/ydb/library/yql/ast/yql_type_string.cpp b/ydb/library/yql/ast/yql_type_string.cpp index 898e19c80b5..928aecacdb6 100644 --- a/ydb/library/yql/ast/yql_type_string.cpp +++ b/ydb/library/yql/ast/yql_type_string.cpp @@ -1139,11 +1139,13 @@ public: private: void Visit(const TUnitExprType& type) final { + TopLevel = false; Y_UNUSED(type); Out_ << TStringBuf("Unit"); } void Visit(const TMultiExprType& type) final { + TopLevel = false; Out_ << TStringBuf("Multi<"); const auto& items = type.GetItems(); for (ui32 i = 0; i < items.size(); ++i) { @@ -1156,6 +1158,7 @@ private: } void Visit(const TTupleExprType& type) final { + TopLevel = false; Out_ << TStringBuf("Tuple<"); const auto& items = type.GetItems(); for (ui32 i = 0; i < items.size(); ++i) { @@ -1168,6 +1171,7 @@ private: } void Visit(const TStructExprType& type) final { + TopLevel = false; Out_ << TStringBuf("Struct<"); const auto& items = type.GetItems(); for (ui32 i = 0; i < items.size(); ++i) { @@ -1180,30 +1184,35 @@ private: } void Visit(const TItemExprType& type) final { + TopLevel = false; EscapeArbitraryAtom(type.GetName(), '\'', &Out_); Out_ << ':'; type.GetItemType()->Accept(*this); } void Visit(const TListExprType& type) final { + TopLevel = false; Out_ << TStringBuf("List<"); type.GetItemType()->Accept(*this); Out_ << '>'; } void Visit(const TStreamExprType& type) final { + TopLevel = false; Out_ << TStringBuf("Stream<"); type.GetItemType()->Accept(*this); Out_ << '>'; } void Visit(const TFlowExprType& type) final { + TopLevel = false; Out_ << TStringBuf("Flow<"); type.GetItemType()->Accept(*this); Out_ << '>'; } void Visit(const TDataExprType& type) final { + TopLevel = false; Out_ << type.GetName(); if (const auto dataExprParamsType = dynamic_cast<const TDataExprParamsType*>(&type)) { Out_ << '(' << dataExprParamsType->GetParamOne() << ',' << dataExprParamsType->GetParamTwo() << ')'; @@ -1211,6 +1220,7 @@ private: } void Visit(const TPgExprType& type) final { + TopLevel = false; TStringBuf name = type.GetName(); if (!name.SkipPrefix("_")) { Out_ << "pg" << name; @@ -1221,22 +1231,26 @@ private: void Visit(const TWorldExprType& type) final { Y_UNUSED(type); + TopLevel = false; Out_ << TStringBuf("World"); } void Visit(const TOptionalExprType& type) final { const TTypeAnnotationNode* itemType = type.GetItemType(); - if (itemType->GetKind() == ETypeAnnotationKind::Callable) { + if (TopLevel || itemType->GetKind() == ETypeAnnotationKind::Callable) { + TopLevel = false; Out_ << TStringBuf("Optional<"); itemType->Accept(*this); Out_ << '>'; } else { + TopLevel = false; itemType->Accept(*this); Out_ << '?'; } } void Visit(const TCallableExprType& type) final { + TopLevel = false; const auto& args = type.GetArguments(); ui32 argsCount = type.GetArgumentsSize(); ui32 optArgsCount = @@ -1278,18 +1292,21 @@ private: } void Visit(const TResourceExprType& type) final { + TopLevel = false; Out_ << TStringBuf("Resource<"); EscapeArbitraryAtom(type.GetTag(), '\'', &Out_); Out_ << '>'; } void Visit(const TTypeExprType& type) final { + TopLevel = false; Out_ << TStringBuf("Type<"); type.GetType()->Accept(*this); Out_ << '>'; } void Visit(const TDictExprType& type) final { + TopLevel = false; if (type.GetPayloadType()->GetKind() == ETypeAnnotationKind::Void) { Out_ << TStringBuf("Set<"); type.GetKeyType()->Accept(*this); @@ -1305,30 +1322,36 @@ private: void Visit(const TVoidExprType& type) final { Y_UNUSED(type); + TopLevel = false; Out_ << TStringBuf("Void"); } void Visit(const TNullExprType& type) final { Y_UNUSED(type); + TopLevel = false; Out_ << TStringBuf("Null"); } void Visit(const TEmptyListExprType& type) final { Y_UNUSED(type); + TopLevel = false; Out_ << TStringBuf("EmptyList"); } void Visit(const TEmptyDictExprType& type) final { Y_UNUSED(type); + TopLevel = false; Out_ << TStringBuf("EmptyDict"); } void Visit(const TGenericExprType& type) final { Y_UNUSED(type); + TopLevel = false; Out_ << TStringBuf("Generic"); } void Visit(const TTaggedExprType& type) final { + TopLevel = false; Out_ << TStringBuf("Tagged<"); type.GetBaseType()->Accept(*this); Out_ << ','; @@ -1337,6 +1360,7 @@ private: } void Visit(const TErrorExprType& type) final { + TopLevel = false; Out_ << TStringBuf("Error<"); auto pos = type.GetError().Position; EscapeArbitraryAtom(pos.File.empty() ? "<main>" : pos.File, '\'', &Out_); @@ -1350,6 +1374,7 @@ private: } void Visit(const TVariantExprType& type) final { + TopLevel = false; auto underlyingType = type.GetUnderlyingType(); if (underlyingType->GetKind() == ETypeAnnotationKind::Tuple) { Out_ << TStringBuf("Variant<"); @@ -1388,6 +1413,7 @@ private: private: IOutputStream& Out_; + bool TopLevel = true; }; } // namespace diff --git a/ydb/library/yql/ast/yql_type_string_ut.cpp b/ydb/library/yql/ast/yql_type_string_ut.cpp index 1ef629067f8..abeee1fec37 100644 --- a/ydb/library/yql/ast/yql_type_string_ut.cpp +++ b/ydb/library/yql/ast/yql_type_string_ut.cpp @@ -568,7 +568,7 @@ Y_UNIT_TEST_SUITE(TTypeString) } Y_UNIT_TEST(FormatOptional) { - TestFormat("((Optional (Data Uint32)))", "Uint32?"); + TestFormat("((Optional (Data Uint32)))", "Optional<Uint32>"); TestFormat("((List (Optional (Data Uint32))))", "List<Uint32?>"); } @@ -628,7 +628,7 @@ Y_UNIT_TEST_SUITE(TTypeString) " ((Data String))" " ((Optional (Data Uint8)))" "))))", - "Optional<Callable<(Uint8?)->String>>?"); + "Optional<Optional<Callable<(Uint8?)->String>>>"); } Y_UNIT_TEST(FormatCallableWithNamedArgs) { @@ -657,7 +657,7 @@ Y_UNIT_TEST_SUITE(TTypeString) TestFormat("((Resource aaa))", "Resource<'aaa'>"); TestFormat("((Resource \"a b\"))", "Resource<'a b'>"); TestFormat("((Resource \"a\\t\\n\\x01b\"))", "Resource<'a\\t\\n\\x01b'>"); - TestFormat("((Optional (Resource aaa)))", "Resource<'aaa'>?"); + TestFormat("((Optional (Resource aaa)))", "Optional<Resource<'aaa'>>"); } Y_UNIT_TEST(FormatTagged) { diff --git a/ydb/tests/functional/canonical/canondata/test_sql.TestCanonicalFolder1.test_case_json_json_query.sql-result_sets_/json_json_query.sql.results b/ydb/tests/functional/canonical/canondata/test_sql.TestCanonicalFolder1.test_case_json_json_query.sql-result_sets_/json_json_query.sql.results index 9c46b5be480..8c379570532 100644 --- a/ydb/tests/functional/canonical/canondata/test_sql.TestCanonicalFolder1.test_case_json_json_query.sql-result_sets_/json_json_query.sql.results +++ b/ydb/tests/functional/canonical/canondata/test_sql.TestCanonicalFolder1.test_case_json_json_query.sql-result_sets_/json_json_query.sql.results @@ -1,9 +1,9 @@ [ [ { - "column0": "JsonDocument?", + "column0": "Optional<JsonDocument>", "column1": "[1,2,3,4]", - "column2": "JsonDocument?", + "column2": "Optional<JsonDocument>", "column3": "{\"key\":\"value\"}" } ] |