diff options
author | a-romanov <Anton.Romanov@ydb.tech> | 2023-02-16 18:48:50 +0300 |
---|---|---|
committer | a-romanov <Anton.Romanov@ydb.tech> | 2023-02-16 18:48:50 +0300 |
commit | 372e7f04b762e8b34b8bab7a75fcce7cedaa08f6 (patch) | |
tree | fe89d5e218e4286cc938a055f0c5fef95c7452ab | |
parent | defd24f1f446ca99645908ccd5b7295d7206460e (diff) | |
download | ydb-372e7f04b762e8b34b8bab7a75fcce7cedaa08f6.tar.gz |
Replace type node in SafeCast if cast make optional.
-rw-r--r-- | ydb/core/kqp/opt/physical/kqp_opt_phy_olap_filter.cpp | 5 | ||||
-rw-r--r-- | ydb/core/kqp/query_compiler/kqp_olap_compiler.cpp | 5 | ||||
-rw-r--r-- | ydb/library/yql/core/type_ann/type_ann_core.cpp | 10 |
3 files changed, 18 insertions, 2 deletions
diff --git a/ydb/core/kqp/opt/physical/kqp_opt_phy_olap_filter.cpp b/ydb/core/kqp/opt/physical/kqp_opt_phy_olap_filter.cpp index 43f885a21ea..3812b925e96 100644 --- a/ydb/core/kqp/opt/physical/kqp_opt_phy_olap_filter.cpp +++ b/ydb/core/kqp/opt/physical/kqp_opt_phy_olap_filter.cpp @@ -100,6 +100,11 @@ bool IsSupportedDataType(const TCoDataCtor& node) { bool IsSupportedCast(const TCoSafeCast& cast) { auto maybeDataType = cast.Type().Maybe<TCoDataType>(); + if (!maybeDataType) { + if (const auto maybeOptionalType = cast.Type().Maybe<TCoOptionalType>()) { + maybeDataType = maybeOptionalType.Cast().ItemType().Maybe<TCoDataType>(); + } + } YQL_ENSURE(maybeDataType.IsValid()); auto dataType = maybeDataType.Cast(); diff --git a/ydb/core/kqp/query_compiler/kqp_olap_compiler.cpp b/ydb/core/kqp/query_compiler/kqp_olap_compiler.cpp index 1989b965d48..1234213c364 100644 --- a/ydb/core/kqp/query_compiler/kqp_olap_compiler.cpp +++ b/ydb/core/kqp/query_compiler/kqp_olap_compiler.cpp @@ -242,6 +242,11 @@ ui64 ConvertSafeCastToColumn(const TExprBase& colName, const std::string& target ui64 ConvertSafeCastToColumn(const TCoSafeCast& cast, TKqpOlapCompileContext& ctx) { auto maybeDataType = cast.Type().Maybe<TCoDataType>(); + if (!maybeDataType) { + if (const auto maybeOptionalType = cast.Type().Maybe<TCoOptionalType>()) { + maybeDataType = maybeOptionalType.Cast().ItemType().Maybe<TCoDataType>(); + } + } YQL_ENSURE(maybeDataType.IsValid()); return ConvertSafeCastToColumn(cast.Value(), maybeDataType.Cast().Type().StringValue(), ctx); } diff --git a/ydb/library/yql/core/type_ann/type_ann_core.cpp b/ydb/library/yql/core/type_ann/type_ann_core.cpp index 299845b8ee4..d3391229cba 100644 --- a/ydb/library/yql/core/type_ann/type_ann_core.cpp +++ b/ydb/library/yql/core/type_ann/type_ann_core.cpp @@ -4184,12 +4184,18 @@ namespace NTypeAnnImpl { return IGraphTransformer::TStatus::Repeat; } - input->SetTypeAnn(type); - if (IsSameAnnotation(*sourceType, *input->GetTypeAnn())) { + if (IsSameAnnotation(*sourceType, *type)) { output = input->HeadPtr(); return IGraphTransformer::TStatus::Repeat; } + if (!IsSameAnnotation(*type, *targetType)) { + output = ctx.Expr.ChangeChild(*input, 1U, ExpandType(input->Tail().Pos(), *type, ctx.Expr)); + return IGraphTransformer::TStatus::Repeat; + } + + input->SetTypeAnn(type); + const TDataExprType* sourceDataType = nullptr; const TDataExprType* targetDataType = nullptr; bool isOptional; |