aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authora-romanov <Anton.Romanov@ydb.tech>2023-06-26 18:55:35 +0300
committera-romanov <Anton.Romanov@ydb.tech>2023-06-26 18:55:35 +0300
commit6c5745e5a9039670e62fdb9968f5add6ab279357 (patch)
tree2efe413bd48063f00e592d29400d20ae83ccaef3
parent90298d692c83e6f459903ed532b38a0806d626fa (diff)
downloadydb-6c5745e5a9039670e62fdb9968f5add6ab279357.tar.gz
YQL-16099 Add 'any' settings for grace join expr node.
-rw-r--r--ydb/library/yql/core/expr_nodes/yql_expr_nodes.json3
-rw-r--r--ydb/library/yql/core/type_ann/type_ann_join.cpp24
-rw-r--r--ydb/library/yql/core/yql_expr_constraint.cpp12
-rw-r--r--ydb/library/yql/dq/opt/dq_opt_join.cpp1
-rw-r--r--ydb/library/yql/providers/common/mkql/yql_provider_mkql.cpp16
5 files changed, 38 insertions, 18 deletions
diff --git a/ydb/library/yql/core/expr_nodes/yql_expr_nodes.json b/ydb/library/yql/core/expr_nodes/yql_expr_nodes.json
index 852e7c7a20..c2f130d0b9 100644
--- a/ydb/library/yql/core/expr_nodes/yql_expr_nodes.json
+++ b/ydb/library/yql/core/expr_nodes/yql_expr_nodes.json
@@ -1522,7 +1522,8 @@
{"Index": 3, "Name": "LeftKeysColumns", "Type": "TCoAtomList"},
{"Index": 4, "Name": "RightKeysColumns", "Type": "TCoAtomList"},
{"Index": 5, "Name": "LeftRenames", "Type": "TCoAtomList"},
- {"Index": 6, "Name": "RightRenames", "Type": "TCoAtomList"}
+ {"Index": 6, "Name": "RightRenames", "Type": "TCoAtomList"},
+ {"Index": 7, "Name": "Flags", "Type": "TCoAtomList"}
]
},
diff --git a/ydb/library/yql/core/type_ann/type_ann_join.cpp b/ydb/library/yql/core/type_ann/type_ann_join.cpp
index fcf8db1de3..2008d37def 100644
--- a/ydb/library/yql/core/type_ann/type_ann_join.cpp
+++ b/ydb/library/yql/core/type_ann/type_ann_join.cpp
@@ -506,14 +506,12 @@ namespace NTypeAnnImpl {
}
}
-
IGraphTransformer::TStatus GraceJoinCoreWrapperImp(const TExprNode::TPtr& input, const TMultiExprType& leftTupleType, const TMultiExprType& rightTupleType, TContext& ctx) {
-
if (!EnsureAtom(*input->Child(2), ctx.Expr)) {
return IGraphTransformer::TStatus::Error;
}
- const auto joinKind = input->Child(2)->Content();
+ const auto joinKind = input->Child(2);
auto& leftKeyColumns = *input->Child(3);
auto& rightKeyColumns = *input->Child(4);
@@ -576,7 +574,7 @@ namespace NTypeAnnImpl {
}
auto columnType = GetFieldType(leftTupleType, *oldPos);
- if ((joinKind == "Right" || joinKind == "Full" || joinKind == "Exclusion" ) && !columnType->IsOptionalOrNull()) {
+ if (joinKind->IsAtom({"Right", "Full", "Exclusion"}) && !columnType->IsOptionalOrNull()) {
columnType = ctx.Expr.MakeType<TOptionalExprType>(columnType);
}
@@ -610,7 +608,7 @@ namespace NTypeAnnImpl {
}
auto columnType = GetFieldType(rightTupleType, *oldPos);
- if ((joinKind == "Left" || joinKind == "Full" || joinKind == "Exclusion" ) && !columnType->IsOptionalOrNull()) {
+ if (joinKind->IsAtom({"Left", "Full", "Exclusion"}) && !columnType->IsOptionalOrNull()) {
columnType = ctx.Expr.MakeType<TOptionalExprType>(columnType);
}
@@ -620,7 +618,13 @@ namespace NTypeAnnImpl {
} else {
resultItems[index] = columnType;
}
+ }
+ for (auto i = 0U; i < input->Tail().ChildrenSize(); ++i) {
+ if (const auto& flag = *input->Tail().Child(i); !flag.IsAtom({"LeftAny", "RightAny"})) {
+ ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(flag.Pos()), TStringBuilder() << "Unsupported grace join option: " << flag.Content()));
+ return IGraphTransformer::TStatus::Error;
+ }
}
const auto resultItemType = ctx.Expr.MakeType<TMultiExprType>(resultItems);
@@ -631,11 +635,8 @@ namespace NTypeAnnImpl {
return IGraphTransformer::TStatus::Ok;
}
-
IGraphTransformer::TStatus GraceJoinCoreWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
- Y_UNUSED(output);
-
- if (!EnsureArgsCount(*input, 7, ctx.Expr)) {
+ if (!EnsureArgsCount(*input, 8, ctx.Expr)) {
return IGraphTransformer::TStatus::Error;
}
@@ -657,8 +658,11 @@ namespace NTypeAnnImpl {
return IGraphTransformer::TStatus::Error;
}
- return GraceJoinCoreWrapperImp(input, *leftItemType->Cast<TMultiExprType>(), *rightItemType->Cast<TMultiExprType>(), ctx);
+ if (const auto status = NormalizeTupleOfAtoms(input, 7U, output, ctx.Expr); IGraphTransformer::TStatus::Ok != status) {
+ return status;
+ }
+ return GraceJoinCoreWrapperImp(input, *leftItemType->Cast<TMultiExprType>(), *rightItemType->Cast<TMultiExprType>(), ctx);
}
diff --git a/ydb/library/yql/core/yql_expr_constraint.cpp b/ydb/library/yql/core/yql_expr_constraint.cpp
index c4e0e53813..6a17cf349d 100644
--- a/ydb/library/yql/core/yql_expr_constraint.cpp
+++ b/ydb/library/yql/core/yql_expr_constraint.cpp
@@ -2414,11 +2414,19 @@ private:
input->AddConstraint(ctx.MakeConstraint<TEmptyConstraintNode>());
}
+ bool leftAny = false, rigthAny = false;
+ core.Flags().Ref().ForEachChild([&](const TExprNode& flag) {
+ if (flag.IsAtom("LeftAny"))
+ leftAny = true;
+ else if (flag.IsAtom("RightAny"))
+ rigthAny = true;
+ });
+
const auto lUnique = core.LeftInput().Ref().GetConstraint<TUniqueConstraintNode>();
const auto rUnique = core.RightInput().Ref().GetConstraint<TUniqueConstraintNode>();
- const bool lOneRow = lUnique && lUnique->HasEqualColumns(GetKeys(core.LeftKeysColumns().Ref()));
- const bool rOneRow = rUnique && rUnique->HasEqualColumns(GetKeys(core.RightKeysColumns().Ref()));
+ const bool lOneRow = lUnique && (leftAny || lUnique->HasEqualColumns(GetKeys(core.LeftKeysColumns().Ref())));
+ const bool rOneRow = rUnique && (rigthAny || rUnique->HasEqualColumns(GetKeys(core.RightKeysColumns().Ref())));
const bool singleSide = joinType.Content().ends_with("Semi") || joinType.Content().ends_with("Only");
diff --git a/ydb/library/yql/dq/opt/dq_opt_join.cpp b/ydb/library/yql/dq/opt/dq_opt_join.cpp
index aca678f719..33185b1fc8 100644
--- a/ydb/library/yql/dq/opt/dq_opt_join.cpp
+++ b/ydb/library/yql/dq/opt/dq_opt_join.cpp
@@ -1202,6 +1202,7 @@ TExprBase DqBuildHashJoin(const TDqJoin& join, EHashJoinMode mode, TExprContext&
return parent;
})
.Seal()
+ .List(7).Seal()
.Seal()
.Build();
break;
diff --git a/ydb/library/yql/providers/common/mkql/yql_provider_mkql.cpp b/ydb/library/yql/providers/common/mkql/yql_provider_mkql.cpp
index 8969d7c3fb..ae9c1dfd74 100644
--- a/ydb/library/yql/providers/common/mkql/yql_provider_mkql.cpp
+++ b/ydb/library/yql/providers/common/mkql/yql_provider_mkql.cpp
@@ -1551,12 +1551,18 @@ TMkqlCommonCallableCompiler::TShared::TShared() {
leftRenames.emplace_back(*GetFieldPosition((s = !s) ? *leftTupleType : *outputTupleType, child.Content())); });
s = false;
node.Child(6)->ForEachChild([&](TExprNode& child){
- rightRenames.emplace_back(*GetFieldPosition((s = !s) ? *rightTupleType : *outputTupleType, child.Content()));
-
- });
+ rightRenames.emplace_back(*GetFieldPosition((s = !s) ? *rightTupleType : *outputTupleType, child.Content())); });
+
+ auto anyJoinSettings = EAnyJoinSettings::None;
+ node.Tail().ForEachChild([&](const TExprNode& flag) {
+ if (flag.IsAtom("LeftAny"))
+ anyJoinSettings = EAnyJoinSettings::Right == anyJoinSettings ? EAnyJoinSettings::Both : EAnyJoinSettings::Left;
+ else if (flag.IsAtom("RightAny"))
+ anyJoinSettings = EAnyJoinSettings::Left == anyJoinSettings ? EAnyJoinSettings::Both : EAnyJoinSettings::Right;
+ });
const auto returnType = BuildType(node, *node.GetTypeAnn(), ctx.ProgramBuilder);
- return ctx.ProgramBuilder.GraceJoin(flowLeft, flowRight, joinKind, leftKeyColumns, rightKeyColumns, leftRenames, rightRenames, returnType);
+ return ctx.ProgramBuilder.GraceJoin(flowLeft, flowRight, joinKind, leftKeyColumns, rightKeyColumns, leftRenames, rightRenames, returnType, anyJoinSettings);
});
@@ -2517,7 +2523,7 @@ TMkqlCommonCallableCompiler::TShared::TShared() {
for (ui32 i = 1; i < node.ChildrenSize(); ++i) {
dependentNodes.push_back(MkqlBuildExpr(*node.Child(i), ctx));
}
-
+
return ctx.ProgramBuilder.PgClone(input, dependentNodes);
});