Skip to content

Commit

Permalink
Block decimal kernels (*, /, %) (#8340)
Browse files Browse the repository at this point in the history
  • Loading branch information
resetius authored Sep 11, 2024
1 parent 5bea5d8 commit b6c969c
Show file tree
Hide file tree
Showing 22 changed files with 679 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5760,7 +5760,7 @@ bool CollectBlockRewrites(const TMultiExprType* multiInputType, bool keepInputCo
std::string_view arrowFunctionName;
const bool rewriteAsIs = node->IsCallable({"AssumeStrict", "AssumeNonStrict", "Likely"});
if (node->IsList() || rewriteAsIs ||
node->IsCallable({"And", "Or", "Xor", "Not", "Coalesce", "Exists", "If", "Just", "AsStruct", "Member", "Nth", "ToPg", "FromPg", "PgResolvedCall", "PgResolvedOp"}))
node->IsCallable({"DecimalMul", "DecimalDiv", "DecimalMod", "And", "Or", "Xor", "Not", "Coalesce", "Exists", "If", "Just", "AsStruct", "Member", "Nth", "ToPg", "FromPg", "PgResolvedCall", "PgResolvedOp"}))
{
if (node->IsCallable() && !IsSupportedAsBlockType(node->Pos(), *node->GetTypeAnn(), ctx, types, true)) {
return true;
Expand Down
4 changes: 4 additions & 0 deletions ydb/library/yql/core/type_ann/type_ann_blocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,10 @@ IGraphTransformer::TStatus BlockLogicalWrapper(const TExprNode::TPtr& input, TEx
return IGraphTransformer::TStatus::Ok;
}

IGraphTransformer::TStatus BlockDecimalBinaryWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
return DecimalBinaryWrapperBase(input, output, ctx, /*blocks=*/ true);
}

IGraphTransformer::TStatus BlockIfWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
Y_UNUSED(output);
if (!EnsureArgsCount(*input, 3U, ctx.Expr)) {
Expand Down
1 change: 1 addition & 0 deletions ydb/library/yql/core/type_ann/type_ann_blocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace NTypeAnnImpl {
IGraphTransformer::TStatus BlockPgOpWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
IGraphTransformer::TStatus BlockPgCallWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
IGraphTransformer::TStatus BlockExtendWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
IGraphTransformer::TStatus BlockDecimalBinaryWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);

} // namespace NTypeAnnImpl
} // namespace NYql
33 changes: 30 additions & 3 deletions ydb/library/yql/core/type_ann/type_ann_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2719,22 +2719,33 @@ namespace NTypeAnnImpl {
return IGraphTransformer::TStatus::Ok;
}

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

const TDataExprType* dataType[2];
bool isOptional[2];
bool haveOptional = false;
bool allScalars = true;
const TDataExprType* commonType = nullptr;
for (ui32 i = 0; i < 2; ++i) {
if (IsNull(*input->Child(i))) {
output = input->ChildPtr(i);
return IGraphTransformer::TStatus::Repeat;
}

if (!EnsureDataOrOptionalOfData(*input->Child(i), isOptional[i], dataType[i], ctx.Expr)) {
const TTypeAnnotationNode* itemType = input->Child(i)->GetTypeAnn();
if (blocks) {
if (!EnsureBlockOrScalarType(*input->Child(i), ctx.Expr)) {
return IGraphTransformer::TStatus::Error;
}
bool isScalar;
itemType = GetBlockItemType(*itemType, isScalar);
allScalars = allScalars && isScalar;
}

if (!EnsureDataOrOptionalOfData(input->Child(i)->Pos(), itemType, isOptional[i], dataType[i], ctx.Expr)) {
return IGraphTransformer::TStatus::Error;
}

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

input->SetTypeAnn(resultType);
if (blocks) {
if (allScalars) {
input->SetTypeAnn(ctx.Expr.MakeType<TScalarExprType>(resultType));
} else {
input->SetTypeAnn(ctx.Expr.MakeType<TBlockExprType>(resultType));
}
} else {
input->SetTypeAnn(resultType);
}
return IGraphTransformer::TStatus::Ok;
}

IGraphTransformer::TStatus DecimalBinaryWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
return DecimalBinaryWrapperBase(input, output, ctx, /*block = */ false);
}

IGraphTransformer::TStatus CountBitsWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
if (!EnsureArgsCount(*input, 1, ctx.Expr)) {
return IGraphTransformer::TStatus::Error;
Expand Down Expand Up @@ -12600,6 +12623,10 @@ template <NKikimr::NUdf::EDataSlot DataSlot>
Functions["ReplicateScalar"] = &ReplicateScalarWrapper;
Functions["BlockPgResolvedOp"] = &BlockPgOpWrapper;
Functions["BlockPgResolvedCall"] = &BlockPgCallWrapper;
Functions["BlockDecimalMul"] = &BlockDecimalBinaryWrapper;
Functions["BlockDecimalMod"] = &BlockDecimalBinaryWrapper;
Functions["BlockDecimalDiv"] = &BlockDecimalBinaryWrapper;

ExtFunctions["BlockFunc"] = &BlockFuncWrapper;
ExtFunctions["BlockBitCast"] = &BlockBitCastWrapper;

Expand Down
1 change: 1 addition & 0 deletions ydb/library/yql/core/type_ann/type_ann_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace NTypeAnnImpl {
IGraphTransformer::TStatus EquiJoinWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
IGraphTransformer::TStatus CombineCoreWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
IGraphTransformer::TStatus GroupingCoreWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
IGraphTransformer::TStatus DecimalBinaryWrapperBase(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx, bool blocks);

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

Expand Down
Loading

0 comments on commit b6c969c

Please sign in to comment.