Skip to content

Commit b6c969c

Browse files
authored
Block decimal kernels (*, /, %) (#8340)
1 parent 5bea5d8 commit b6c969c

File tree

22 files changed

+679
-58
lines changed

22 files changed

+679
-58
lines changed

ydb/library/yql/core/peephole_opt/yql_opt_peephole_physical.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5760,7 +5760,7 @@ bool CollectBlockRewrites(const TMultiExprType* multiInputType, bool keepInputCo
57605760
std::string_view arrowFunctionName;
57615761
const bool rewriteAsIs = node->IsCallable({"AssumeStrict", "AssumeNonStrict", "Likely"});
57625762
if (node->IsList() || rewriteAsIs ||
5763-
node->IsCallable({"And", "Or", "Xor", "Not", "Coalesce", "Exists", "If", "Just", "AsStruct", "Member", "Nth", "ToPg", "FromPg", "PgResolvedCall", "PgResolvedOp"}))
5763+
node->IsCallable({"DecimalMul", "DecimalDiv", "DecimalMod", "And", "Or", "Xor", "Not", "Coalesce", "Exists", "If", "Just", "AsStruct", "Member", "Nth", "ToPg", "FromPg", "PgResolvedCall", "PgResolvedOp"}))
57645764
{
57655765
if (node->IsCallable() && !IsSupportedAsBlockType(node->Pos(), *node->GetTypeAnn(), ctx, types, true)) {
57665766
return true;

ydb/library/yql/core/type_ann/type_ann_blocks.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,10 @@ IGraphTransformer::TStatus BlockLogicalWrapper(const TExprNode::TPtr& input, TEx
331331
return IGraphTransformer::TStatus::Ok;
332332
}
333333

334+
IGraphTransformer::TStatus BlockDecimalBinaryWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
335+
return DecimalBinaryWrapperBase(input, output, ctx, /*blocks=*/ true);
336+
}
337+
334338
IGraphTransformer::TStatus BlockIfWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
335339
Y_UNUSED(output);
336340
if (!EnsureArgsCount(*input, 3U, ctx.Expr)) {

ydb/library/yql/core/type_ann/type_ann_blocks.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ namespace NTypeAnnImpl {
3737
IGraphTransformer::TStatus BlockPgOpWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
3838
IGraphTransformer::TStatus BlockPgCallWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
3939
IGraphTransformer::TStatus BlockExtendWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
40+
IGraphTransformer::TStatus BlockDecimalBinaryWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
4041

4142
} // namespace NTypeAnnImpl
4243
} // namespace NYql

ydb/library/yql/core/type_ann/type_ann_core.cpp

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2719,22 +2719,33 @@ namespace NTypeAnnImpl {
27192719
return IGraphTransformer::TStatus::Ok;
27202720
}
27212721

2722-
IGraphTransformer::TStatus DecimalBinaryWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
2722+
IGraphTransformer::TStatus DecimalBinaryWrapperBase(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx, bool blocks) {
27232723
if (!EnsureArgsCount(*input, 2, ctx.Expr)) {
27242724
return IGraphTransformer::TStatus::Error;
27252725
}
27262726

27272727
const TDataExprType* dataType[2];
27282728
bool isOptional[2];
27292729
bool haveOptional = false;
2730+
bool allScalars = true;
27302731
const TDataExprType* commonType = nullptr;
27312732
for (ui32 i = 0; i < 2; ++i) {
27322733
if (IsNull(*input->Child(i))) {
27332734
output = input->ChildPtr(i);
27342735
return IGraphTransformer::TStatus::Repeat;
27352736
}
27362737

2737-
if (!EnsureDataOrOptionalOfData(*input->Child(i), isOptional[i], dataType[i], ctx.Expr)) {
2738+
const TTypeAnnotationNode* itemType = input->Child(i)->GetTypeAnn();
2739+
if (blocks) {
2740+
if (!EnsureBlockOrScalarType(*input->Child(i), ctx.Expr)) {
2741+
return IGraphTransformer::TStatus::Error;
2742+
}
2743+
bool isScalar;
2744+
itemType = GetBlockItemType(*itemType, isScalar);
2745+
allScalars = allScalars && isScalar;
2746+
}
2747+
2748+
if (!EnsureDataOrOptionalOfData(input->Child(i)->Pos(), itemType, isOptional[i], dataType[i], ctx.Expr)) {
27382749
return IGraphTransformer::TStatus::Error;
27392750
}
27402751

@@ -2780,10 +2791,22 @@ namespace NTypeAnnImpl {
27802791
resultType = ctx.Expr.MakeType<TOptionalExprType>(resultType);
27812792
}
27822793

2783-
input->SetTypeAnn(resultType);
2794+
if (blocks) {
2795+
if (allScalars) {
2796+
input->SetTypeAnn(ctx.Expr.MakeType<TScalarExprType>(resultType));
2797+
} else {
2798+
input->SetTypeAnn(ctx.Expr.MakeType<TBlockExprType>(resultType));
2799+
}
2800+
} else {
2801+
input->SetTypeAnn(resultType);
2802+
}
27842803
return IGraphTransformer::TStatus::Ok;
27852804
}
27862805

2806+
IGraphTransformer::TStatus DecimalBinaryWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
2807+
return DecimalBinaryWrapperBase(input, output, ctx, /*block = */ false);
2808+
}
2809+
27872810
IGraphTransformer::TStatus CountBitsWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
27882811
if (!EnsureArgsCount(*input, 1, ctx.Expr)) {
27892812
return IGraphTransformer::TStatus::Error;
@@ -12600,6 +12623,10 @@ template <NKikimr::NUdf::EDataSlot DataSlot>
1260012623
Functions["ReplicateScalar"] = &ReplicateScalarWrapper;
1260112624
Functions["BlockPgResolvedOp"] = &BlockPgOpWrapper;
1260212625
Functions["BlockPgResolvedCall"] = &BlockPgCallWrapper;
12626+
Functions["BlockDecimalMul"] = &BlockDecimalBinaryWrapper;
12627+
Functions["BlockDecimalMod"] = &BlockDecimalBinaryWrapper;
12628+
Functions["BlockDecimalDiv"] = &BlockDecimalBinaryWrapper;
12629+
1260312630
ExtFunctions["BlockFunc"] = &BlockFuncWrapper;
1260412631
ExtFunctions["BlockBitCast"] = &BlockBitCastWrapper;
1260512632

ydb/library/yql/core/type_ann/type_ann_impl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ namespace NTypeAnnImpl {
3434
IGraphTransformer::TStatus EquiJoinWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
3535
IGraphTransformer::TStatus CombineCoreWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
3636
IGraphTransformer::TStatus GroupingCoreWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
37+
IGraphTransformer::TStatus DecimalBinaryWrapperBase(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx, bool blocks);
3738

3839
TMaybe<ui32> FindOrReportMissingMember(TStringBuf memberName, TPositionHandle pos, const TStructExprType& structType, TExprContext& ctx);
3940

0 commit comments

Comments
 (0)