summaryrefslogtreecommitdiffstats
path: root/yql/essentials/public/purecalc/common/transformations/align_output_schema.cpp
diff options
context:
space:
mode:
authorvvvv <[email protected]>2025-10-08 11:41:14 +0300
committervvvv <[email protected]>2025-10-08 12:20:42 +0300
commitd73f13cfdb331365ddad0da51ec36e0a3e4cf187 (patch)
tree88cab10170ce9aa3389be7f1a09247386dcf5ebd /yql/essentials/public/purecalc/common/transformations/align_output_schema.cpp
parentf377d8ad9e0741cd904c1d4934afdf24af517d93 (diff)
YQL-20086 public
commit_hash:68b0c2e9c2960587af7d57ecedcb38f4d05890b7
Diffstat (limited to 'yql/essentials/public/purecalc/common/transformations/align_output_schema.cpp')
-rw-r--r--yql/essentials/public/purecalc/common/transformations/align_output_schema.cpp184
1 files changed, 91 insertions, 93 deletions
diff --git a/yql/essentials/public/purecalc/common/transformations/align_output_schema.cpp b/yql/essentials/public/purecalc/common/transformations/align_output_schema.cpp
index f11195bf756..47806d6846e 100644
--- a/yql/essentials/public/purecalc/common/transformations/align_output_schema.cpp
+++ b/yql/essentials/public/purecalc/common/transformations/align_output_schema.cpp
@@ -10,117 +10,115 @@ using namespace NYql;
using namespace NYql::NPureCalc;
namespace {
- class TOutputAligner : public TSyncTransformerBase {
- private:
- const TTypeAnnotationNode* OutputStruct_;
- bool AcceptsBlocks_;
- EProcessorMode ProcessorMode_;
- const TTypeAnnotationContext& TypeCtx_;
-
- public:
- explicit TOutputAligner(
- const TTypeAnnotationNode* outputStruct,
- bool acceptsBlocks,
- EProcessorMode processorMode,
- const TTypeAnnotationContext& typeCtx
- )
- : OutputStruct_(outputStruct)
- , AcceptsBlocks_(acceptsBlocks)
- , ProcessorMode_(processorMode)
- , TypeCtx_(typeCtx)
- {
- }
-
- public:
- TStatus DoTransform(TExprNode::TPtr input, TExprNode::TPtr& output, TExprContext& ctx) final {
- output = input;
-
- const auto* expectedType = MakeExpectedType(ctx);
- const auto* expectedItemType = MakeExpectedItemType();
- const auto* actualType = MakeActualType(input);
- const auto* actualItemType = MakeActualItemType(input);
-
- // XXX: Tweak the obtained expression type, is the spec supports blocks:
- // 1. Remove "_yql_block_length" attribute, since it's for internal usage.
- // 2. Strip block container from the type to store its internal type.
- if (AcceptsBlocks_) {
- Y_ENSURE(actualItemType->GetKind() == ETypeAnnotationKind::Struct);
- actualItemType = UnwrapBlockStruct(actualItemType->Cast<TStructExprType>(), ctx);
- if (ProcessorMode_ == EProcessorMode::PullList) {
- actualType = ctx.MakeType<TListExprType>(actualItemType);
- } else {
- actualType = ctx.MakeType<TStreamExprType>(actualItemType);
- }
- }
-
- if (!ValidateOutputType(actualItemType, expectedItemType, ctx, TypeCtx_)) {
- return TStatus::Error;
- }
-
- if (!expectedType) {
- return TStatus::Ok;
- }
-
- auto status = TryConvertTo(output, *actualType, *expectedType, ctx, TypeCtx_);
-
- if (status.Level == IGraphTransformer::TStatus::Repeat) {
- status = IGraphTransformer::TStatus(IGraphTransformer::TStatus::Repeat, true);
+class TOutputAligner: public TSyncTransformerBase {
+private:
+ const TTypeAnnotationNode* OutputStruct_;
+ bool AcceptsBlocks_;
+ EProcessorMode ProcessorMode_;
+ const TTypeAnnotationContext& TypeCtx_;
+
+public:
+ explicit TOutputAligner(
+ const TTypeAnnotationNode* outputStruct,
+ bool acceptsBlocks,
+ EProcessorMode processorMode,
+ const TTypeAnnotationContext& typeCtx)
+ : OutputStruct_(outputStruct)
+ , AcceptsBlocks_(acceptsBlocks)
+ , ProcessorMode_(processorMode)
+ , TypeCtx_(typeCtx)
+ {
+ }
+
+public:
+ TStatus DoTransform(TExprNode::TPtr input, TExprNode::TPtr& output, TExprContext& ctx) final {
+ output = input;
+
+ const auto* expectedType = MakeExpectedType(ctx);
+ const auto* expectedItemType = MakeExpectedItemType();
+ const auto* actualType = MakeActualType(input);
+ const auto* actualItemType = MakeActualItemType(input);
+
+ // XXX: Tweak the obtained expression type, is the spec supports blocks:
+ // 1. Remove "_yql_block_length" attribute, since it's for internal usage.
+ // 2. Strip block container from the type to store its internal type.
+ if (AcceptsBlocks_) {
+ Y_ENSURE(actualItemType->GetKind() == ETypeAnnotationKind::Struct);
+ actualItemType = UnwrapBlockStruct(actualItemType->Cast<TStructExprType>(), ctx);
+ if (ProcessorMode_ == EProcessorMode::PullList) {
+ actualType = ctx.MakeType<TListExprType>(actualItemType);
+ } else {
+ actualType = ctx.MakeType<TStreamExprType>(actualItemType);
}
-
- return status;
}
- void Rewind() final {
+ if (!ValidateOutputType(actualItemType, expectedItemType, ctx, TypeCtx_)) {
+ return TStatus::Error;
}
- private:
- const TTypeAnnotationNode* MakeExpectedType(TExprContext& ctx) {
- if (!OutputStruct_) {
- return nullptr;
- }
+ if (!expectedType) {
+ return TStatus::Ok;
+ }
- switch (ProcessorMode_) {
- case EProcessorMode::PullList:
- return ctx.MakeType<TListExprType>(OutputStruct_);
- case EProcessorMode::PullStream:
- case EProcessorMode::PushStream:
- return ctx.MakeType<TStreamExprType>(OutputStruct_);
- }
+ auto status = TryConvertTo(output, *actualType, *expectedType, ctx, TypeCtx_);
- Y_ABORT("Unexpected");
+ if (status.Level == IGraphTransformer::TStatus::Repeat) {
+ status = IGraphTransformer::TStatus(IGraphTransformer::TStatus::Repeat, true);
}
- const TTypeAnnotationNode* MakeExpectedItemType() {
- return OutputStruct_;
+ return status;
+ }
+
+ void Rewind() final {
+ }
+
+private:
+ const TTypeAnnotationNode* MakeExpectedType(TExprContext& ctx) {
+ if (!OutputStruct_) {
+ return nullptr;
}
- const TTypeAnnotationNode* MakeActualType(TExprNode::TPtr& input) {
- return input->GetTypeAnn();
+ switch (ProcessorMode_) {
+ case EProcessorMode::PullList:
+ return ctx.MakeType<TListExprType>(OutputStruct_);
+ case EProcessorMode::PullStream:
+ case EProcessorMode::PushStream:
+ return ctx.MakeType<TStreamExprType>(OutputStruct_);
}
- const TTypeAnnotationNode* MakeActualItemType(TExprNode::TPtr& input) {
- auto actualType = MakeActualType(input);
- switch (actualType->GetKind()) {
- case ETypeAnnotationKind::Stream:
- Y_ENSURE(ProcessorMode_ != EProcessorMode::PullList,
- "processor mode mismatches the actual container type");
- return actualType->Cast<TStreamExprType>()->GetItemType();
- case ETypeAnnotationKind::List:
- Y_ENSURE(ProcessorMode_ == EProcessorMode::PullList,
- "processor mode mismatches the actual container type");
- return actualType->Cast<TListExprType>()->GetItemType();
- default:
- Y_ABORT("unexpected return type");
- }
+ Y_ABORT("Unexpected");
+ }
+
+ const TTypeAnnotationNode* MakeExpectedItemType() {
+ return OutputStruct_;
+ }
+
+ const TTypeAnnotationNode* MakeActualType(TExprNode::TPtr& input) {
+ return input->GetTypeAnn();
+ }
+
+ const TTypeAnnotationNode* MakeActualItemType(TExprNode::TPtr& input) {
+ auto actualType = MakeActualType(input);
+ switch (actualType->GetKind()) {
+ case ETypeAnnotationKind::Stream:
+ Y_ENSURE(ProcessorMode_ != EProcessorMode::PullList,
+ "processor mode mismatches the actual container type");
+ return actualType->Cast<TStreamExprType>()->GetItemType();
+ case ETypeAnnotationKind::List:
+ Y_ENSURE(ProcessorMode_ == EProcessorMode::PullList,
+ "processor mode mismatches the actual container type");
+ return actualType->Cast<TListExprType>()->GetItemType();
+ default:
+ Y_ABORT("unexpected return type");
}
- };
-}
+ }
+};
+} // namespace
TAutoPtr<IGraphTransformer> NYql::NPureCalc::MakeOutputAligner(
const TTypeAnnotationNode* outputStruct,
bool acceptsBlocks,
EProcessorMode processorMode,
- const TTypeAnnotationContext& typeCtx
-) {
+ const TTypeAnnotationContext& typeCtx) {
return new TOutputAligner(outputStruct, acceptsBlocks, processorMode, typeCtx);
}