Skip to content

Commit 340bba0

Browse files
committed
Fix YT provider direct dependency on DQ via CBO
commit_hash:134201d428f9541bb6990e2d65a7bbcf65d74e25
1 parent 0f8ebb5 commit 340bba0

File tree

12 files changed

+95
-12
lines changed

12 files changed

+95
-12
lines changed

yql/essentials/core/cbo/cbo_optimizer_new.h

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ struct TCardinalityHints {
7676

7777
double ApplyHint(double originalValue) {
7878
Applied = true;
79-
79+
8080
switch (Operation) {
8181
case Add:
8282
return originalValue + Value;
@@ -122,7 +122,7 @@ struct TJoinOrderHints {
122122

123123
virtual TVector<TString> Labels() = 0;
124124
bool IsRelation() { return Type == Relation; }
125-
bool IsJoin() { return Type == Join; }
125+
bool IsJoin() { return Type == Join; }
126126
virtual ~ITreeNode() = default;
127127

128128
ui32 Type;
@@ -136,7 +136,7 @@ struct TJoinOrderHints {
136136
this->Type = ITreeNode::Join;
137137
}
138138

139-
TVector<TString> Labels() override {
139+
TVector<TString> Labels() override {
140140
auto labels = Lhs->Labels();
141141
auto rhsLabels = Rhs->Labels();
142142
labels.insert(labels.end(), std::make_move_iterator(rhsLabels.begin()), std::make_move_iterator(rhsLabels.end()));
@@ -179,12 +179,12 @@ struct TOptimizerHints {
179179

180180
TVector<TString> GetUnappliedString();
181181

182-
/*
182+
/*
183183
* The function accepts string with three type of expressions: array of (JoinAlgo | Card | JoinOrder):
184184
* 1) JoinAlgo(t1 t2 ... tn Map | Grace | Lookup) to change join algo for join, where these labels take part
185185
* 2) Card(t1 t2 ... tn (*|/|+|-) Number) to change cardinality for join, where these labels take part or labels only
186186
* 3) JoinOrder( (t1 t2) (t3 (t4 ...)) ) - fixate this join subtree in the general join tree
187-
*/
187+
*/
188188
static TOptimizerHints Parse(const TString&);
189189
};
190190

@@ -299,14 +299,35 @@ struct TJoinOptimizerNode : public IBaseOptimizerNode {
299299
};
300300

301301
struct IOptimizerNew {
302+
using TPtr = std::shared_ptr<IOptimizerNew>;
302303
IProviderContext& Pctx;
303304

304305
IOptimizerNew(IProviderContext& ctx) : Pctx(ctx) {}
305306
virtual ~IOptimizerNew() = default;
306307
virtual std::shared_ptr<TJoinOptimizerNode> JoinSearch(
307-
const std::shared_ptr<TJoinOptimizerNode>& joinTree,
308+
const std::shared_ptr<TJoinOptimizerNode>& joinTree,
308309
const TOptimizerHints& hints = {}
309310
) = 0;
310311
};
311312

313+
struct TExprContext;
314+
315+
class IOptimizerFactory : private TNonCopyable {
316+
public:
317+
using TPtr = std::shared_ptr<IOptimizerFactory>;
318+
using TLogger = std::function<void(const TString&)>;
319+
320+
virtual ~IOptimizerFactory() = default;
321+
322+
struct TNativeSettings {
323+
ui32 MaxDPhypDPTableSize = 100000;
324+
};
325+
virtual IOptimizerNew::TPtr MakeJoinCostBasedOptimizerNative(IProviderContext& pctx, TExprContext& ctx, const TNativeSettings& settings) const = 0;
326+
327+
struct TPGSettings {
328+
TLogger Logger = [](const TString&){};
329+
};
330+
virtual IOptimizerNew::TPtr MakeJoinCostBasedOptimizerPG(IProviderContext& pctx, TExprContext& ctx, const TPGSettings& settings) const = 0;
331+
};
332+
312333
} // namespace NYql
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include "cbo_simple.h"
2+
3+
#include <yql/essentials/utils/yql_panic.h>
4+
#include <yql/essentials/parser/pg_wrapper/interface/optimizer.h>
5+
6+
namespace NYql {
7+
8+
namespace {
9+
10+
class TSimpleOptimizerFactory : public IOptimizerFactory {
11+
public:
12+
virtual IOptimizerNew::TPtr MakeJoinCostBasedOptimizerNative(IProviderContext& pctx, TExprContext& ctx, const TNativeSettings& settings) const override {
13+
Y_UNUSED(pctx);
14+
Y_UNUSED(ctx);
15+
Y_UNUSED(settings);
16+
YQL_ENSURE(false, "Native CBO is not supported here");
17+
Y_UNREACHABLE();
18+
}
19+
20+
virtual IOptimizerNew::TPtr MakeJoinCostBasedOptimizerPG(IProviderContext& pctx, TExprContext& ctx, const TPGSettings& settings) const override {
21+
return IOptimizerNew::TPtr(MakePgOptimizerNew(pctx, ctx, settings.Logger));
22+
}
23+
};
24+
25+
}
26+
27+
IOptimizerFactory::TPtr MakeSimpleCBOOptimizerFactory() {
28+
return std::make_shared<TSimpleOptimizerFactory>();
29+
}
30+
31+
} // namespace NYql
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#pragma once
2+
3+
#include <yql/essentials/core/cbo/cbo_optimizer_new.h>
4+
5+
namespace NYql {
6+
7+
IOptimizerFactory::TPtr MakeSimpleCBOOptimizerFactory();
8+
9+
} // namespace NYql
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
LIBRARY()
2+
3+
SRCS(
4+
cbo_simple.cpp
5+
)
6+
7+
PEERDIR(
8+
yql/essentials/parser/pg_wrapper/interface
9+
yql/essentials/utils
10+
)
11+
12+
END()

yql/essentials/core/cbo/ya.make

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ GENERATE_ENUM_SERIALIZATION(cbo_optimizer_new.h)
99

1010
END()
1111

12+
RECURSE(
13+
simple
14+
)
15+
1216
RECURSE_FOR_TESTS(
1317
ut
1418
)
15-

yql/essentials/core/extract_predicate/ut/extract_predicate_ut.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <yql/essentials/sql/sql.h>
1111
#include <yql/essentials/ast/yql_ast_annotation.h>
1212
#include <yql/essentials/ast/yql_expr.h>
13+
#include <yql/essentials/core/cbo/simple/cbo_simple.h>
1314
#include <yql/essentials/core/type_ann/type_ann_core.h>
1415
#include <yql/essentials/core/type_ann/type_ann_expr.h>
1516
#include <yql/essentials/core/ut_common/yql_ut_common.h>
@@ -154,7 +155,7 @@ Y_UNIT_TEST_SUITE(TYqlExtractPredicate) {
154155
auto ytGateway = CreateYtFileGateway(yqlNativeServices);
155156

156157
TVector<TDataProviderInitializer> dataProvidersInit;
157-
dataProvidersInit.push_back(GetYtNativeDataProviderInitializer(ytGateway));
158+
dataProvidersInit.push_back(GetYtNativeDataProviderInitializer(ytGateway, MakeSimpleCBOOptimizerFactory()));
158159
TProgramFactory factory(true, funcReg, 0ULL, dataProvidersInit, "ut");
159160

160161
TProgramPtr program = factory.Create("-stdin-", Src);

yql/essentials/core/extract_predicate/ut/ya.make

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ PEERDIR(
2222
contrib/ydb/library/yql/providers/yt/provider
2323
contrib/ydb/library/yql/providers/yt/codec/codegen
2424
contrib/ydb/library/yql/providers/yt/comp_nodes/llvm14
25+
yql/essentials/core/cbo/simple
2526
yql/essentials/minikql/comp_nodes/llvm14
2627
yql/essentials/minikql/invoke_builtins/llvm14
2728
yql/essentials/sql/pg

yql/essentials/core/ut/ya.make

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ PEERDIR(
2222
library/cpp/yson/node
2323
yql/essentials/ast
2424
yql/essentials/core
25+
yql/essentials/core/cbo/simple
2526
yql/essentials/core/facade
2627
yql/essentials/core/services
2728
yql/essentials/core/services/mounts

yql/essentials/core/ut/yql_execution_ut.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <yql/essentials/ast/yql_ast_annotation.h>
66
#include <yql/essentials/ast/yql_expr.h>
7+
#include <yql/essentials/core/cbo/simple/cbo_simple.h>
78
#include <yql/essentials/core/type_ann/type_ann_core.h>
89
#include <yql/essentials/core/yql_expr_optimize.h>
910
#include <yql/essentials/core/yql_expr_type_annotation.h>
@@ -58,7 +59,7 @@ namespace NYql {
5859
auto ytGateway = CreateYtFileGateway(yqlNativeServices);
5960

6061
TVector<TDataProviderInitializer> dataProvidersInit;
61-
dataProvidersInit.push_back(GetYtNativeDataProviderInitializer(ytGateway));
62+
dataProvidersInit.push_back(GetYtNativeDataProviderInitializer(ytGateway, MakeSimpleCBOOptimizerFactory()));
6263
TProgramFactory factory(true, funcReg, 0ULL, dataProvidersInit, "ut");
6364

6465
TProgramPtr program = factory.Create("-stdin-", Src);

yql/essentials/core/ut/yql_qplayer_ut.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <contrib/ydb/library/yql/providers/yt/provider/yql_yt_provider.h>
33
#include <contrib/ydb/library/yql/providers/yt/gateway/file/yql_yt_file.h>
44
#include <contrib/ydb/library/yql/providers/yt/gateway/file/yql_yt_file_services.h>
5+
#include <yql/essentials/core/cbo/simple/cbo_simple.h>
56
#include <yql/essentials/core/facade/yql_facade.h>
67
#include <yql/essentials/core/qplayer/storage/memory/yql_qstorage_memory.h>
78
#include <yql/essentials/providers/common/udf_resolve/yql_simple_udf_resolver.h>
@@ -82,7 +83,7 @@ bool RunProgram(bool replay, const TString& query, const TQContext& qContext, co
8283
auto ytGateway = CreateYtFileGateway(yqlNativeServices);
8384

8485
TVector<TDataProviderInitializer> dataProvidersInit;
85-
dataProvidersInit.push_back(GetYtNativeDataProviderInitializer(ytGateway));
86+
dataProvidersInit.push_back(GetYtNativeDataProviderInitializer(ytGateway, MakeSimpleCBOOptimizerFactory()));
8687

8788
TExprContext modulesCtx;
8889
IModuleResolver::TPtr moduleResolver;
@@ -113,7 +114,7 @@ bool RunProgram(bool replay, const TString& query, const TQContext& qContext, co
113114
for (const auto& x : runSettings.Credentials) {
114115
credentials->AddCredential(x.first, x.second);
115116
}
116-
117+
117118
factory.SetCredentials(credentials);
118119
}
119120

0 commit comments

Comments
 (0)