Skip to content

[YQL-16903] Change default value for EmitAggApply and dq.EnableDqReplicate if BlockEngine is enabled #1748

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ydb/library/yql/core/common_opt/yql_co_pgselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1858,7 +1858,8 @@ TExprNode::TPtr BuildAggregationTraits(TPositionHandle pos, bool onWindow, const
extractor = ctx.NewLambda(pos, std::move(arguments), std::move(aggFuncArgs));
}

if (optCtx.Types->PgEmitAggApply && !onWindow) {
const bool blockEngineEnabled = optCtx.Types->BlockEngineMode != EBlockEngineMode::Disable;
if (optCtx.Types->PgEmitAggApply.GetOrElse(blockEngineEnabled) && !onWindow) {
return ctx.Builder(pos)
.Callable("AggApply")
.Atom(0, TString("pg_") + func)
Expand Down
2 changes: 1 addition & 1 deletion ydb/library/yql/core/yql_type_annotation.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ struct TTypeAnnotationContext: public TThrRefBase {
ui32 FolderSubDirsLimit = 1000;
bool UseBlocks = false;
EBlockEngineMode BlockEngineMode = EBlockEngineMode::Disable;
bool PgEmitAggApply = false;
TMaybe<bool> PgEmitAggApply;
IArrowResolver::TPtr ArrowResolver;
ECostBasedOptimizerType CostBasedOptimizer = ECostBasedOptimizerType::Disable;
bool MatchRecognize = false;
Expand Down
5 changes: 5 additions & 0 deletions ydb/library/yql/providers/dq/common/yql_dq_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ struct TDqSettings {
bool IsSpillingEnabled() const {
return SpillingEngine.Get().GetOrElse(TDqSettings::TDefault::SpillingEngine) != ESpillingEngine::Disable;
}

bool IsDqReplicateEnabled(const TTypeAnnotationContext& typesCtx) const {
return EnableDqReplicate.Get().GetOrElse(
typesCtx.BlockEngineMode != EBlockEngineMode::Disable || TDqSettings::TDefault::EnableDqReplicate);
}
};

struct TDqConfiguration: public TDqSettings, public NCommon::TSettingDispatcher {
Expand Down
4 changes: 2 additions & 2 deletions ydb/library/yql/providers/dq/opt/logical_optimize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class TDqsLogicalOptProposalTransformer : public TOptimizeTransformerBase {
TMaybeNode<TExprBase> UnorderedOverDqReadWrap(TExprBase node, TExprContext& ctx, const TGetParents& getParents) const {
const auto unordered = node.Cast<TCoUnorderedBase>();
if (const auto maybeRead = unordered.Input().Maybe<TDqReadWrapBase>().Input()) {
if (Config->EnableDqReplicate.Get().GetOrElse(TDqSettings::TDefault::EnableDqReplicate)) {
if (Config->IsDqReplicateEnabled(TypesCtx)) {
const TParentsMap* parentsMap = getParents();
auto parentsIt = parentsMap->find(unordered.Input().Raw());
YQL_ENSURE(parentsIt != parentsMap->cend());
Expand All @@ -127,7 +127,7 @@ class TDqsLogicalOptProposalTransformer : public TOptimizeTransformerBase {
TMaybeNode<TExprBase> ExtractMembersOverDqReadWrap(TExprBase node, TExprContext& ctx, const TGetParents& getParents) {
auto extract = node.Cast<TCoExtractMembers>();
if (const auto maybeRead = extract.Input().Maybe<TDqReadWrap>().Input()) {
if (Config->EnableDqReplicate.Get().GetOrElse(TDqSettings::TDefault::EnableDqReplicate)) {
if (Config->IsDqReplicateEnabled(TypesCtx)) {
const TParentsMap* parentsMap = getParents();
auto parentsIt = parentsMap->find(extract.Input().Raw());
YQL_ENSURE(parentsIt != parentsMap->cend());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TDqDataProviderSink: public TDataProviderBase {
, PhysicalFinalizingTransformer([] () { return CreateDqsFinalizingOptTransformer(); })
, TypeAnnotationTransformer([state] () {
return CreateDqsDataSinkTypeAnnotationTransformer(
state->TypeCtx, state->Settings->EnableDqReplicate.Get().GetOrElse(TDqSettings::TDefault::EnableDqReplicate));
state->TypeCtx, state->Settings->IsDqReplicateEnabled(*state->TypeCtx));
})
, ConstraintsTransformer([] () { return CreateDqDataSinkConstraintTransformer(); })
, RecaptureTransformer([state] () { return CreateDqsRecaptureTransformer(state); })
Expand Down
9 changes: 7 additions & 2 deletions ydb/library/yql/sql/v1/aggregation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ namespace {
}
return false;
}

bool ShouldEmitAggApply(const TContext& ctx) {
const bool blockEngineEnabled = ctx.BlockEngineEnable || ctx.BlockEngineForce;
return ctx.EmitAggApply.GetOrElse(blockEngineEnabled);
}
}

static const THashSet<TString> AggApplyFuncs = {
Expand Down Expand Up @@ -58,7 +63,7 @@ class TAggregationFactory : public IAggregation {

protected:
bool InitAggr(TContext& ctx, bool isFactory, ISource* src, TAstListNode& node, const TVector<TNodePtr>& exprs) override {
if (!ctx.EmitAggApply) {
if (!ShouldEmitAggApply(ctx)) {
AggApplyName = "";
}

Expand Down Expand Up @@ -1349,7 +1354,7 @@ class TPGFactoryAggregation final : public TAggregationFactory {
Y_UNUSED(many);
Y_UNUSED(ctx);
Y_UNUSED(allowAggApply);
if (ctx.EmitAggApply && allowAggApply && AggMode != EAggregateMode::OverWindow) {
if (ShouldEmitAggApply(ctx) && allowAggApply && AggMode != EAggregateMode::OverWindow) {
return Y("AggApply",
Q("pg_" + to_lower(PgFunc)), Y("ListItemType", type), Lambda);
}
Expand Down
2 changes: 1 addition & 1 deletion ydb/library/yql/sql/v1/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ THashMap<TStringBuf, TPragmaField> CTX_PRAGMA_FIELDS = {
{"FlexibleTypes", &TContext::FlexibleTypes},
{"AnsiCurrentRow", &TContext::AnsiCurrentRow},
{"EmitStartsWith", &TContext::EmitStartsWith},
{"EmitAggApply", &TContext::EmitAggApply},
{"AnsiLike", &TContext::AnsiLike},
{"UseBlocks", &TContext::UseBlocks},
{"BlockEngineEnable", &TContext::BlockEngineEnable},
Expand All @@ -67,6 +66,7 @@ typedef TMaybe<bool> TContext::*TPragmaMaybeField;
THashMap<TStringBuf, TPragmaMaybeField> CTX_PRAGMA_MAYBE_FIELDS = {
{"AnsiRankForNullableKeys", &TContext::AnsiRankForNullableKeys},
{"AnsiInForEmptyOrNullableItemsCollections", &TContext::AnsiInForEmptyOrNullableItemsCollections},
{"EmitAggApply", &TContext::EmitAggApply},
{"CompactGroupBy", &TContext::CompactGroupBy},
};

Expand Down
2 changes: 1 addition & 1 deletion ydb/library/yql/sql/v1/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ namespace NSQLTranslationV1 {
NYql::TWarningPolicy WarningPolicy;
TString PqReadByRtmrCluster;
bool EmitStartsWith = true;
bool EmitAggApply = false;
TMaybe<bool> EmitAggApply;
bool UseBlocks = false;
bool AnsiLike = false;
bool FeatureR010 = false; //Row pattern recognition: FROM clause
Expand Down