Skip to content

Commit

Permalink
Merge 7b5da83 into ae6ef0c
Browse files Browse the repository at this point in the history
  • Loading branch information
iddqdex authored Feb 11, 2024
2 parents ae6ef0c + 7b5da83 commit 06bbbc3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
2 changes: 1 addition & 1 deletion ydb/core/formats/arrow/ssa_runtime_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace NKikimr::NSsa {

// Bump this version every time incompatible runtime functions are introduced.
#ifndef SSA_RUNTIME_VERSION
#define SSA_RUNTIME_VERSION 4U
#define SSA_RUNTIME_VERSION 3U
#endif

// History:
Expand Down
1 change: 1 addition & 0 deletions ydb/core/kqp/opt/physical/kqp_opt_phy_olap_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ std::vector<std::pair<TExprBase, TExprBase>> ExtractComparisonParameters(const T

TMaybeNode<TExprBase> ComparisonPushdown(const std::vector<std::pair<TExprBase, TExprBase>>& parameters, const TCoCompare& predicate, TExprContext& ctx, TPositionHandle pos);

[[maybe_unused]]
TMaybeNode<TExprBase> YqlCoalescePushdown(const TCoCoalesce& coalesce, TExprContext& ctx) {
if (const auto params = ExtractBinaryFunctionParameters(coalesce, ctx, coalesce.Pos())) {
return Build<TKqpOlapFilterBinaryOp>(ctx, coalesce.Pos())
Expand Down
38 changes: 30 additions & 8 deletions ydb/core/kqp/query_compiler/kqp_olap_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,12 @@ ui64 CompileSimpleArrowComparison(const TKqpOlapFilterBinaryOp& comparison, TKqp
function = TProgram::TAssignment::FUNC_CMP_GREATER;
} else if (comparison.Operator() == "gte") {
function = TProgram::TAssignment::FUNC_CMP_GREATER_EQUAL;
} else if (comparison.Operator() == "string_contains") {
function = TProgram::TAssignment::FUNC_STR_MATCH;
} else if (comparison.Operator() == "starts_with") {
function = TProgram::TAssignment::FUNC_STR_STARTS_WITH;
} else if (comparison.Operator() == "ends_with") {
function = TProgram::TAssignment::FUNC_STR_ENDS_WITH;
}

cmpFunc->SetId(function);
Expand Down Expand Up @@ -620,6 +626,7 @@ TTypedColumn CompileYqlKernelUnaryOperation(const TKqpOlapFilterUnaryOp& operati
return {command->GetColumn().GetId(), resultType};
}

[[maybe_unused]]
TTypedColumn CompileYqlKernelBinaryOperation(const TKqpOlapFilterBinaryOp& operation, TKqpOlapCompileContext& ctx)
{
// Columns should be created before operation, otherwise operation fail to find columns
Expand Down Expand Up @@ -708,7 +715,6 @@ const TTypedColumn BuildLogicalProgram(const TExprNode::TChildrenType& args, con
logicalFunc->SetFunctionType(TProgram::YQL_KERNEL);
logicalFunc->SetYqlOperationId((ui32)function);
} else {
logicalFunc->SetFunctionType(function);
logicalFunc->SetId((ui32)function);
}

Expand Down Expand Up @@ -740,22 +746,38 @@ const TTypedColumn BuildLogicalNot(const TExprBase& arg, TKqpOlapCompileContext&

TTypedColumn GetOrCreateColumnIdAndType(const TExprBase& node, TKqpOlapCompileContext& ctx) {
if (const auto& maybeBinaryOp = node.Maybe<TKqpOlapFilterBinaryOp>()) {
if (const auto& binaryOp = maybeBinaryOp.Cast(); ctx.CheckYqlCompatibleArgsTypes(binaryOp)) {
return CompileYqlKernelBinaryOperation(binaryOp, ctx);
if constexpr (NSsa::RuntimeVersion >= 4U) {
if (const auto& binaryOp = maybeBinaryOp.Cast(); ctx.CheckYqlCompatibleArgsTypes(binaryOp)) {
return CompileYqlKernelBinaryOperation(binaryOp, ctx);
} else {
return {
ConvertSafeCastToColumn(CompileSimpleArrowComparison(binaryOp, ctx), "Uint8", ctx),
ctx.ExprCtx().MakeType<TBlockExprType>(ctx.ExprCtx().MakeType<TDataExprType>(EDataSlot::Bool))
};
}
} else {
return {
ConvertSafeCastToColumn(CompileSimpleArrowComparison(binaryOp, ctx), "Uint8", ctx),
ctx.ExprCtx().MakeType<TBlockExprType>(ctx.ExprCtx().MakeType<TDataExprType>(EDataSlot::Uint8))
CompileSimpleArrowComparison(maybeBinaryOp.Cast(), ctx),
ctx.ExprCtx().MakeType<TBlockExprType>(ctx.ExprCtx().MakeType<TDataExprType>(EDataSlot::Bool))
};
}
} else if (const auto& maybeUnaryOp = node.Maybe<TKqpOlapFilterUnaryOp>()) {
return CompileYqlKernelUnaryOperation(maybeUnaryOp.Cast(), ctx);
} else if (const auto& maybeAnd = node.Maybe<TKqpOlapAnd>()) {
return BuildLogicalProgram(maybeAnd.Ref().Children(), TKernelRequestBuilder::EBinaryOp::And, ctx);
if constexpr (NSsa::RuntimeVersion >= 4U)
return BuildLogicalProgram(maybeAnd.Ref().Children(), TKernelRequestBuilder::EBinaryOp::And, ctx);
else
return BuildLogicalProgram(maybeAnd.Ref().Children(), TProgram::TAssignment::FUNC_BINARY_AND, ctx);
} else if (const auto& maybeOr = node.Maybe<TKqpOlapOr>()) {
return BuildLogicalProgram(maybeOr.Ref().Children(), TKernelRequestBuilder::EBinaryOp::Or, ctx);
if constexpr (NSsa::RuntimeVersion >= 4U)
return BuildLogicalProgram(maybeOr.Ref().Children(), TKernelRequestBuilder::EBinaryOp::Or, ctx);
else
return BuildLogicalProgram(maybeOr.Ref().Children(), TProgram::TAssignment::FUNC_BINARY_OR, ctx);
} else if (const auto& maybeXor = node.Maybe<TKqpOlapXor>()) {
return BuildLogicalProgram(maybeXor.Ref().Children(), TKernelRequestBuilder::EBinaryOp::Xor, ctx);
if constexpr (NSsa::RuntimeVersion >= 4U)
return BuildLogicalProgram(maybeXor.Ref().Children(), TKernelRequestBuilder::EBinaryOp::Xor, ctx);
else
return BuildLogicalProgram(maybeXor.Ref().Children(), TProgram::TAssignment::FUNC_BINARY_XOR, ctx);
} else if (const auto& maybeNot = node.Maybe<TKqpOlapNot>()) {
return BuildLogicalNot(maybeNot.Cast().Value(), ctx);
} else if (const auto& maybeJsonValue = node.Maybe<TKqpOlapJsonValue>()) {
Expand Down
4 changes: 4 additions & 0 deletions ydb/core/kqp/ut/olap/kqp_olap_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1709,7 +1709,11 @@ Y_UNIT_TEST_SUITE(KqpOlap) {
scanSettings.Explain(true);

TLocalHelper(kikimr).CreateTestOlapTable();
#if SSA_RUNTIME_VERSION >= 4U
WriteTestData(kikimr, "/Root/olapStore/olapTable", 10000, 3000000, 5, true);
#else
WriteTestData(kikimr, "/Root/olapStore/olapTable", 10000, 3000000, 5, false);
#endif
Tests::NCommon::TLoggerInit(kikimr).Initialize();

auto tableClient = kikimr.GetTableClient();
Expand Down
4 changes: 4 additions & 0 deletions ydb/core/kqp/ut/query/kqp_explain_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,11 @@ Y_UNIT_TEST_SUITE(KqpExplain) {
NJson::ReadJsonTree(*streamRes.PlanJson, &plan, true);
UNIT_ASSERT(ValidatePlanNodeIds(plan));

#if SSA_RUNTIME_VERSION >= 4U
auto readNode = FindPlanNodeByKv(plan, "Node Type", "TableFullScan");
#else
auto readNode = FindPlanNodeByKv(plan, "Node Type", "Filter-TableFullScan");
#endif
UNIT_ASSERT(readNode.IsDefined());

auto& operators = readNode.GetMapSafe().at("Operators").GetArraySafe();
Expand Down

0 comments on commit 06bbbc3

Please sign in to comment.