diff options
author | uzhas <uzhas@ydb.tech> | 2022-08-08 23:04:09 +0300 |
---|---|---|
committer | uzhas <uzhas@ydb.tech> | 2022-08-08 23:04:09 +0300 |
commit | 134b8a706b6ac24bda99274fce27c0fb4ce22c03 (patch) | |
tree | 7db1a63ec2c79a993e0836ebdf1a08cb94a85e45 | |
parent | d930aa2ae8568d58b39909b29be61130cedfad15 (diff) | |
download | ydb-134b8a706b6ac24bda99274fce27c0fb4ce22c03.tar.gz |
fix TypePrinter for pg types, add tests
-rw-r--r-- | ydb/library/yql/minikql/mkql_type_builder.cpp | 1 | ||||
-rw-r--r-- | ydb/library/yql/minikql/mkql_type_builder_ut.cpp | 265 | ||||
-rw-r--r-- | ydb/library/yql/minikql/ut/CMakeLists.darwin.txt | 5 | ||||
-rw-r--r-- | ydb/library/yql/minikql/ut/CMakeLists.linux.txt | 5 | ||||
-rw-r--r-- | ydb/library/yql/public/udf/udf_type_printer.cpp | 7 |
5 files changed, 278 insertions, 5 deletions
diff --git a/ydb/library/yql/minikql/mkql_type_builder.cpp b/ydb/library/yql/minikql/mkql_type_builder.cpp index 9daa64a837..6ead464302 100644 --- a/ydb/library/yql/minikql/mkql_type_builder.cpp +++ b/ydb/library/yql/minikql/mkql_type_builder.cpp @@ -1606,6 +1606,7 @@ NUdf::ETypeKind TTypeInfoHelper::GetTypeKind(const NUdf::TType* type) const { case NMiniKQL::TType::EKind::EmptyList: return NUdf::ETypeKind::EmptyList; case NMiniKQL::TType::EKind::EmptyDict: return NUdf::ETypeKind::EmptyDict; case NMiniKQL::TType::EKind::Tagged: return NUdf::ETypeKind::Tagged; + case NMiniKQL::TType::EKind::Pg: return NUdf::ETypeKind::Pg; default: Y_VERIFY_DEBUG(false, "Wrong MQKL type kind %s", mkqlType->GetKindAsStr().data()); return NUdf::ETypeKind::Unknown; diff --git a/ydb/library/yql/minikql/mkql_type_builder_ut.cpp b/ydb/library/yql/minikql/mkql_type_builder_ut.cpp new file mode 100644 index 0000000000..7b26010789 --- /dev/null +++ b/ydb/library/yql/minikql/mkql_type_builder_ut.cpp @@ -0,0 +1,265 @@ +#include "mkql_type_builder.h" + +#include <ydb/library/yql/parser/pg_catalog/catalog.h> +#include <ydb/library/yql/public/udf/udf_type_printer.h> +#include <library/cpp/testing/unittest/registar.h> + +namespace NKikimr { + +namespace NMiniKQL { + +class TMiniKQLTypeBuilderTest: public TTestBase { +public: + TMiniKQLTypeBuilderTest() + : Env(Alloc) + , TypeInfoHelper(new TTypeInfoHelper()) + , FunctionTypeInfoBuilder(Env, TypeInfoHelper, "", nullptr, {}) + { + } + +private: + TScopedAlloc Alloc; + TTypeEnvironment Env; + NUdf::ITypeInfoHelper::TPtr TypeInfoHelper; + TFunctionTypeInfoBuilder FunctionTypeInfoBuilder; + + UNIT_TEST_SUITE(TMiniKQLTypeBuilderTest); + UNIT_TEST(TestPgTypeFormat); + UNIT_TEST(TestSingularTypeFormat); + UNIT_TEST(TestOptionalTypeFormat); + UNIT_TEST(TestDataTypeFormat); + UNIT_TEST(TestResourceTypeFormat); + UNIT_TEST(TestTaggedTypeFormat); + UNIT_TEST(TestContainerTypeFormat); + UNIT_TEST(TestStructTypeFormat); + UNIT_TEST(TestTupleTypeFormat); + UNIT_TEST_SUITE_END(); + + TString FormatType(NUdf::TType* t) { + TStringBuilder output; + NUdf::TTypePrinter p(*TypeInfoHelper, t); + p.Out(output.Out); + return output; + } + + void TestPgTypeFormat() { + { + auto s = FormatType(FunctionTypeInfoBuilder.Pg(NYql::NPg::LookupType("bool").TypeId)); + UNIT_ASSERT_VALUES_EQUAL(s, "pgbool"); + } + { + auto s = FormatType(FunctionTypeInfoBuilder.Pg(NYql::NPg::LookupType("_bool").TypeId)); + UNIT_ASSERT_VALUES_EQUAL(s, "_pgbool"); + } + } + + void TestSingularTypeFormat() { + { + auto s = FormatType(FunctionTypeInfoBuilder.Null()); + UNIT_ASSERT_VALUES_EQUAL(s, "Null"); + } + { + auto s = FormatType(FunctionTypeInfoBuilder.Void()); + UNIT_ASSERT_VALUES_EQUAL(s, "Void"); + } + { + auto s = FormatType(FunctionTypeInfoBuilder.EmptyList()); + UNIT_ASSERT_VALUES_EQUAL(s, "EmptyList"); + } + { + auto s = FormatType(FunctionTypeInfoBuilder.EmptyDict()); + UNIT_ASSERT_VALUES_EQUAL(s, "EmptyDict"); + } + } + + void TestOptionalTypeFormat() { + auto optional1 = FunctionTypeInfoBuilder.Optional()->Item<i64>().Build(); + auto optional2 = FunctionTypeInfoBuilder.Optional()->Item(optional1).Build(); + auto optional3 = FunctionTypeInfoBuilder.Optional()->Item(optional2).Build(); + { + auto s = FormatType(optional1); + UNIT_ASSERT_VALUES_EQUAL(s, "Int64?"); + } + { + auto s = FormatType(optional2); + UNIT_ASSERT_VALUES_EQUAL(s, "Int64??"); + } + { + auto s = FormatType(optional3); + UNIT_ASSERT_VALUES_EQUAL(s, "Int64???"); + } + } + + void TestContainerTypeFormat() { + { + auto s = FormatType(FunctionTypeInfoBuilder.List()->Item<i8>().Build()); + UNIT_ASSERT_VALUES_EQUAL(s, "List<Int8>"); + } + { + auto s = FormatType(FunctionTypeInfoBuilder.Dict()->Key<i8>().Value<bool>().Build()); + UNIT_ASSERT_VALUES_EQUAL(s, "Dict<Int8,Bool>"); + } + { + auto s = FormatType(FunctionTypeInfoBuilder.Set()->Key<char*>().Build()); + UNIT_ASSERT_VALUES_EQUAL(s, "Dict<String,Void>"); + } + } + + void TestResourceTypeFormat() { + { + auto s = FormatType(FunctionTypeInfoBuilder.Resource("my_resource")); + UNIT_ASSERT_VALUES_EQUAL(s, "Resource<'my_resource'>"); + } + } + + void TestTaggedTypeFormat() { + { + auto s = FormatType(FunctionTypeInfoBuilder.Tagged(FunctionTypeInfoBuilder.SimpleType<i8>(), "my_resource")); + UNIT_ASSERT_VALUES_EQUAL(s, "Tagged<Int8,'my_resource'>"); + } + } + + void TestStructTypeFormat() { + ui32 index = 0; + auto s1 = FunctionTypeInfoBuilder.Struct(2) + ->AddField<bool>("is_ok", &index) + .AddField<char*>("name", &index) + .Build(); + + auto s2 = FunctionTypeInfoBuilder.Struct(3) + ->AddField<char*>("country", &index) + .AddField<ui64>("id", &index) + .AddField("person", s1, &index) + .Build(); + + { + auto s = FormatType(s1); + UNIT_ASSERT_VALUES_EQUAL(s, "Struct<'is_ok':Bool,'name':String>"); + } + { + auto s = FormatType(s2); + UNIT_ASSERT_VALUES_EQUAL(s, "Struct<'country':String,'id':Uint64,'person':Struct<'is_ok':Bool,'name':String>>"); + } + } + + void TestTupleTypeFormat() { + auto t = FunctionTypeInfoBuilder.Tuple(2) + ->Add<bool>() + .Add<char*>() + .Build(); + { + auto s = FormatType(t); + UNIT_ASSERT_VALUES_EQUAL(s, "Tuple<Bool,String>"); + } + } + + void TestDataTypeFormat() { + { + auto s = FormatType(FunctionTypeInfoBuilder.SimpleType<i8>()); + UNIT_ASSERT_VALUES_EQUAL(s, "Int8"); + } + { + auto s = FormatType(FunctionTypeInfoBuilder.SimpleType<i16>()); + UNIT_ASSERT_VALUES_EQUAL(s, "Int16"); + } + { + auto s = FormatType(FunctionTypeInfoBuilder.SimpleType<i32>()); + UNIT_ASSERT_VALUES_EQUAL(s, "Int32"); + } + { + auto s = FormatType(FunctionTypeInfoBuilder.SimpleType<i64>()); + UNIT_ASSERT_VALUES_EQUAL(s, "Int64"); + } + { + auto s = FormatType(FunctionTypeInfoBuilder.SimpleType<ui8>()); + UNIT_ASSERT_VALUES_EQUAL(s, "Uint8"); + } + { + auto s = FormatType(FunctionTypeInfoBuilder.SimpleType<ui16>()); + UNIT_ASSERT_VALUES_EQUAL(s, "Uint16"); + } + { + auto s = FormatType(FunctionTypeInfoBuilder.SimpleType<ui32>()); + UNIT_ASSERT_VALUES_EQUAL(s, "Uint32"); + } + { + auto s = FormatType(FunctionTypeInfoBuilder.SimpleType<ui64>()); + UNIT_ASSERT_VALUES_EQUAL(s, "Uint64"); + } + + { + auto s = FormatType(FunctionTypeInfoBuilder.SimpleType<float>()); + UNIT_ASSERT_VALUES_EQUAL(s, "Float"); + } + { + auto s = FormatType(FunctionTypeInfoBuilder.SimpleType<double>()); + UNIT_ASSERT_VALUES_EQUAL(s, "Double"); + } + + { + auto s = FormatType(FunctionTypeInfoBuilder.SimpleType<char*>()); + UNIT_ASSERT_VALUES_EQUAL(s, "String"); + } + { + auto s = FormatType(FunctionTypeInfoBuilder.SimpleType<NUdf::TUtf8>()); + UNIT_ASSERT_VALUES_EQUAL(s, "Utf8"); + } + { + auto s = FormatType(FunctionTypeInfoBuilder.SimpleType<NUdf::TYson>()); + UNIT_ASSERT_VALUES_EQUAL(s, "Yson"); + } + { + auto s = FormatType(FunctionTypeInfoBuilder.SimpleType<NUdf::TJson>()); + UNIT_ASSERT_VALUES_EQUAL(s, "Json"); + } + { + auto s = FormatType(FunctionTypeInfoBuilder.SimpleType<NUdf::TUuid>()); + UNIT_ASSERT_VALUES_EQUAL(s, "Uuid"); + } + { + auto s = FormatType(FunctionTypeInfoBuilder.SimpleType<NUdf::TJsonDocument>()); + UNIT_ASSERT_VALUES_EQUAL(s, "JsonDocument"); + } + { + auto s = FormatType(FunctionTypeInfoBuilder.SimpleType<NUdf::TDate>()); + UNIT_ASSERT_VALUES_EQUAL(s, "Date"); + } + { + auto s = FormatType(FunctionTypeInfoBuilder.SimpleType<NUdf::TDatetime>()); + UNIT_ASSERT_VALUES_EQUAL(s, "Datetime"); + } + { + auto s = FormatType(FunctionTypeInfoBuilder.SimpleType<NUdf::TTimestamp>()); + UNIT_ASSERT_VALUES_EQUAL(s, "Timestamp"); + } + { + auto s = FormatType(FunctionTypeInfoBuilder.SimpleType<NUdf::TInterval>()); + UNIT_ASSERT_VALUES_EQUAL(s, "Interval"); + } + { + auto s = FormatType(FunctionTypeInfoBuilder.SimpleType<NUdf::TTzDate>()); + UNIT_ASSERT_VALUES_EQUAL(s, "TzDate"); + } + { + auto s = FormatType(FunctionTypeInfoBuilder.SimpleType<NUdf::TTzDatetime>()); + UNIT_ASSERT_VALUES_EQUAL(s, "TzDatetime"); + } + { + auto s = FormatType(FunctionTypeInfoBuilder.SimpleType<NUdf::TTzTimestamp>()); + UNIT_ASSERT_VALUES_EQUAL(s, "TzTimestamp"); + } + { + auto s = FormatType(FunctionTypeInfoBuilder.SimpleType<NUdf::TDyNumber>()); + UNIT_ASSERT_VALUES_EQUAL(s, "DyNumber"); + } + { + auto s = FormatType(FunctionTypeInfoBuilder.Decimal(7, 3)); + UNIT_ASSERT_VALUES_EQUAL(s, "Decimal(7,3)"); + } + } +}; + +UNIT_TEST_SUITE_REGISTRATION(TMiniKQLTypeBuilderTest); + +} +} diff --git a/ydb/library/yql/minikql/ut/CMakeLists.darwin.txt b/ydb/library/yql/minikql/ut/CMakeLists.darwin.txt index 3173c1e779..6943a02d37 100644 --- a/ydb/library/yql/minikql/ut/CMakeLists.darwin.txt +++ b/ydb/library/yql/minikql/ut/CMakeLists.darwin.txt @@ -22,8 +22,8 @@ target_link_libraries(ydb-library-yql-minikql-ut PUBLIC library-yql-minikql yql-minikql-computation yql-minikql-invoke_builtins + yql-parser-pg_wrapper udf-service-exception_policy - yql-sql-pg_dummy ) target_link_options(ydb-library-yql-minikql-ut PRIVATE -Wl,-no_deduplicate @@ -40,8 +40,9 @@ target_sources(ydb-library-yql-minikql-ut PRIVATE ${CMAKE_SOURCE_DIR}/ydb/library/yql/minikql/mkql_node_ut.cpp ${CMAKE_SOURCE_DIR}/ydb/library/yql/minikql/mkql_opt_literal_ut.cpp ${CMAKE_SOURCE_DIR}/ydb/library/yql/minikql/mkql_stats_registry_ut.cpp - ${CMAKE_SOURCE_DIR}/ydb/library/yql/minikql/mkql_type_ops_ut.cpp ${CMAKE_SOURCE_DIR}/ydb/library/yql/minikql/mkql_string_util_ut.cpp + ${CMAKE_SOURCE_DIR}/ydb/library/yql/minikql/mkql_type_builder_ut.cpp + ${CMAKE_SOURCE_DIR}/ydb/library/yql/minikql/mkql_type_ops_ut.cpp ${CMAKE_SOURCE_DIR}/ydb/library/yql/minikql/pack_num_ut.cpp ${CMAKE_SOURCE_DIR}/ydb/library/yql/minikql/watermark_tracker_ut.cpp ) diff --git a/ydb/library/yql/minikql/ut/CMakeLists.linux.txt b/ydb/library/yql/minikql/ut/CMakeLists.linux.txt index fdd3a5d0b1..72e421f3c1 100644 --- a/ydb/library/yql/minikql/ut/CMakeLists.linux.txt +++ b/ydb/library/yql/minikql/ut/CMakeLists.linux.txt @@ -24,8 +24,8 @@ target_link_libraries(ydb-library-yql-minikql-ut PUBLIC library-yql-minikql yql-minikql-computation yql-minikql-invoke_builtins + yql-parser-pg_wrapper udf-service-exception_policy - yql-sql-pg_dummy ) target_link_options(ydb-library-yql-minikql-ut PRIVATE -ldl @@ -46,8 +46,9 @@ target_sources(ydb-library-yql-minikql-ut PRIVATE ${CMAKE_SOURCE_DIR}/ydb/library/yql/minikql/mkql_node_ut.cpp ${CMAKE_SOURCE_DIR}/ydb/library/yql/minikql/mkql_opt_literal_ut.cpp ${CMAKE_SOURCE_DIR}/ydb/library/yql/minikql/mkql_stats_registry_ut.cpp - ${CMAKE_SOURCE_DIR}/ydb/library/yql/minikql/mkql_type_ops_ut.cpp ${CMAKE_SOURCE_DIR}/ydb/library/yql/minikql/mkql_string_util_ut.cpp + ${CMAKE_SOURCE_DIR}/ydb/library/yql/minikql/mkql_type_builder_ut.cpp + ${CMAKE_SOURCE_DIR}/ydb/library/yql/minikql/mkql_type_ops_ut.cpp ${CMAKE_SOURCE_DIR}/ydb/library/yql/minikql/pack_num_ut.cpp ${CMAKE_SOURCE_DIR}/ydb/library/yql/minikql/watermark_tracker_ut.cpp ) diff --git a/ydb/library/yql/public/udf/udf_type_printer.cpp b/ydb/library/yql/public/udf/udf_type_printer.cpp index 64c120e4a2..7e6fb52049 100644 --- a/ydb/library/yql/public/udf/udf_type_printer.cpp +++ b/ydb/library/yql/public/udf/udf_type_printer.cpp @@ -125,7 +125,12 @@ TTypePrinter5::TTypePrinter5(const ITypeInfoHelper2& typeHelper2, const TType* t void TTypePrinter5::OnPgImpl(ui32 typeId) { auto* description = TypeHelper2_.FindPgTypeDescription(typeId); Y_VERIFY(description); - *Output_ << std::string_view(description->Name); + auto name = std::string_view(description->Name); + if (name.starts_with('_')) { + name.remove_prefix(1); + *Output_ << '_'; + } + *Output_ << "pg" << name; } } |