Skip to content

Commit 5fe3ee7

Browse files
committed
YQ RD enable LLVM in purecalc filters (ydb-platform#11442)
1 parent 5fe3c6f commit 5fe3ee7

File tree

15 files changed

+121
-35
lines changed

15 files changed

+121
-35
lines changed

ydb/core/fq/libs/row_dispatcher/actors_factory.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
#include <ydb/core/fq/libs/row_dispatcher/topic_session.h>
44

5-
#include <ydb/library/yql/public/purecalc/common/interface.h>
6-
75
namespace NFq::NRowDispatcher {
86

97

@@ -19,7 +17,7 @@ struct TActorFactory : public IActorFactory {
1917
ui32 partitionId,
2018
NYdb::TDriver driver,
2119
std::shared_ptr<NYdb::ICredentialsProviderFactory> credentialsProviderFactory,
22-
NYql::NPureCalc::IProgramFactoryPtr pureCalcProgramFactory,
20+
IPureCalcProgramFactory::TPtr pureCalcProgramFactory,
2321
const ::NMonitoring::TDynamicCounterPtr& counters,
2422
const NYql::IPqGateway::TPtr& pqGateway) const override {
2523

ydb/core/fq/libs/row_dispatcher/actors_factory.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#pragma once
22

3+
#include "common.h"
4+
35
#include <ydb/core/fq/libs/config/protos/row_dispatcher.pb.h>
46
#include <util/generic/ptr.h>
57
#include <ydb/library/actors/core/actor.h>
68
#include <ydb/public/sdk/cpp/client/ydb_driver/driver.h>
79
#include <ydb/library/yql/providers/pq/provider/yql_pq_gateway.h>
8-
#include <ydb/library/yql/public/purecalc/common/fwd.h>
910

1011
namespace NFq::NRowDispatcher {
1112

@@ -21,7 +22,7 @@ struct IActorFactory : public TThrRefBase {
2122
ui32 partitionId,
2223
NYdb::TDriver driver,
2324
std::shared_ptr<NYdb::ICredentialsProviderFactory> credentialsProviderFactory,
24-
NYql::NPureCalc::IProgramFactoryPtr pureCalcProgramFactory,
25+
IPureCalcProgramFactory::TPtr pureCalcProgramFactory,
2526
const ::NMonitoring::TDynamicCounterPtr& counters,
2627
const NYql::IPqGateway::TPtr& pqGateway) const = 0;
2728
};
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include "common.h"
2+
3+
#include <util/system/mutex.h>
4+
5+
#include <ydb/library/yql/public/purecalc/common/interface.h>
6+
7+
namespace NFq {
8+
9+
namespace {
10+
11+
class TPureCalcProgramFactory : public IPureCalcProgramFactory {
12+
public:
13+
TPureCalcProgramFactory() {
14+
CreateFactory({.EnabledLLVM = false});
15+
CreateFactory({.EnabledLLVM = true});
16+
}
17+
18+
NYql::NPureCalc::IProgramFactoryPtr GetFactory(const TSettings& settings) const override {
19+
const auto it = ProgramFactories.find(settings);
20+
Y_ENSURE(it != ProgramFactories.end());
21+
return it->second;
22+
}
23+
24+
private:
25+
void CreateFactory(const TSettings& settings) {
26+
ProgramFactories.insert({settings, NYql::NPureCalc::MakeProgramFactory(
27+
NYql::NPureCalc::TProgramFactoryOptions()
28+
.SetLLVMSettings(settings.EnabledLLVM ? "ON" : "OFF")
29+
)});
30+
}
31+
32+
private:
33+
std::map<TSettings, NYql::NPureCalc::IProgramFactoryPtr> ProgramFactories;
34+
};
35+
36+
} // anonymous namespace
37+
38+
IPureCalcProgramFactory::TPtr CreatePureCalcProgramFactory() {
39+
return MakeIntrusive<TPureCalcProgramFactory>();
40+
}
41+
42+
} // namespace NFq
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#pragma once
2+
3+
#include <util/generic/ptr.h>
4+
5+
#include <ydb/library/yql/public/purecalc/common/fwd.h>
6+
7+
namespace NFq {
8+
9+
class IPureCalcProgramFactory : public TThrRefBase {
10+
public:
11+
using TPtr = TIntrusivePtr<IPureCalcProgramFactory>;
12+
13+
struct TSettings {
14+
bool EnabledLLVM = false;
15+
16+
std::strong_ordering operator<=>(const TSettings& other) const = default;
17+
};
18+
19+
public:
20+
virtual NYql::NPureCalc::IProgramFactoryPtr GetFactory(const TSettings& settings) const = 0;
21+
};
22+
23+
IPureCalcProgramFactory::TPtr CreatePureCalcProgramFactory();
24+
25+
} // namespace NFq

ydb/core/fq/libs/row_dispatcher/json_filter.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,15 @@ class TJsonFilter::TImpl {
264264
const TVector<TString>& types,
265265
const TString& whereFilter,
266266
TCallback callback,
267-
NYql::NPureCalc::IProgramFactoryPtr pureCalcProgramFactory)
268-
: Sql(GenerateSql(whereFilter)) {
267+
IPureCalcProgramFactory::TPtr pureCalcProgramFactory,
268+
const IPureCalcProgramFactory::TSettings& factorySettings)
269+
: Sql(GenerateSql(whereFilter, factorySettings)) {
269270
Y_ENSURE(columns.size() == types.size(), "Number of columns and types should by equal");
270271

271272
// Program should be stateless because input values
272273
// allocated on another allocator and should be released
273274
LOG_ROW_DISPATCHER_DEBUG("Creating program...");
274-
Program = pureCalcProgramFactory->MakePushStreamProgram(
275+
Program = pureCalcProgramFactory->GetFactory(factorySettings)->MakePushStreamProgram(
275276
TFilterInputSpec(MakeInputSchema(columns, types)),
276277
TFilterOutputSpec(MakeOutputSchema()),
277278
Sql,
@@ -291,8 +292,9 @@ class TJsonFilter::TImpl {
291292
}
292293

293294
private:
294-
TString GenerateSql(const TString& whereFilter) {
295+
TString GenerateSql(const TString& whereFilter, const IPureCalcProgramFactory::TSettings& factorySettings) {
295296
TStringStream str;
297+
str << "PRAGMA config.flags(\"LLVM\", \"" << (factorySettings.EnabledLLVM ? "ON" : "OFF") << "\");\n";
296298
str << "$filtered = SELECT * FROM Input " << whereFilter << ";\n";
297299

298300
str << "SELECT " << OffsetFieldName << ", Unwrap(Json::SerializeJson(Yson::From(RemoveMembers(TableRow(), [\"" << OffsetFieldName;
@@ -312,8 +314,9 @@ TJsonFilter::TJsonFilter(
312314
const TVector<TString>& types,
313315
const TString& whereFilter,
314316
TCallback callback,
315-
NYql::NPureCalc::IProgramFactoryPtr pureCalcProgramFactory)
316-
: Impl(std::make_unique<TJsonFilter::TImpl>(columns, types, whereFilter, callback, pureCalcProgramFactory)) {
317+
IPureCalcProgramFactory::TPtr pureCalcProgramFactory,
318+
const IPureCalcProgramFactory::TSettings& factorySettings)
319+
: Impl(std::make_unique<TJsonFilter::TImpl>(columns, types, whereFilter, callback, pureCalcProgramFactory, factorySettings)) {
317320
}
318321

319322
TJsonFilter::~TJsonFilter() {
@@ -332,8 +335,9 @@ std::unique_ptr<TJsonFilter> NewJsonFilter(
332335
const TVector<TString>& types,
333336
const TString& whereFilter,
334337
TCallback callback,
335-
NYql::NPureCalc::IProgramFactoryPtr pureCalcProgramFactory) {
336-
return std::unique_ptr<TJsonFilter>(new TJsonFilter(columns, types, whereFilter, callback, pureCalcProgramFactory));
338+
IPureCalcProgramFactory::TPtr pureCalcProgramFactory,
339+
const IPureCalcProgramFactory::TSettings& factorySettings) {
340+
return std::unique_ptr<TJsonFilter>(new TJsonFilter(columns, types, whereFilter, callback, pureCalcProgramFactory, factorySettings));
337341
}
338342

339343
} // namespace NFq

ydb/core/fq/libs/row_dispatcher/json_filter.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#pragma once
22

3+
#include "common.h"
4+
35
#include <ydb/library/yql/minikql/computation/mkql_computation_node_holders.h>
4-
#include <ydb/library/yql/public/purecalc/common/fwd.h>
56

67
namespace NFq {
78

@@ -15,7 +16,8 @@ class TJsonFilter {
1516
const TVector<TString>& types,
1617
const TString& whereFilter,
1718
TCallback callback,
18-
NYql::NPureCalc::IProgramFactoryPtr pureCalcProgramFactory);
19+
IPureCalcProgramFactory::TPtr pureCalcProgramFactory,
20+
const IPureCalcProgramFactory::TSettings& factorySettings);
1921

2022
~TJsonFilter();
2123

@@ -32,6 +34,7 @@ std::unique_ptr<TJsonFilter> NewJsonFilter(
3234
const TVector<TString>& types,
3335
const TString& whereFilter,
3436
TJsonFilter::TCallback callback,
35-
NYql::NPureCalc::IProgramFactoryPtr pureCalcProgramFactory);
37+
IPureCalcProgramFactory::TPtr pureCalcProgramFactory,
38+
const IPureCalcProgramFactory::TSettings& factorySettings);
3639

3740
} // namespace NFq

ydb/core/fq/libs/row_dispatcher/row_dispatcher.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "row_dispatcher.h"
2+
#include "common.h"
23
#include "coordinator.h"
34

45
#include <ydb/library/actors/core/actorid.h>
@@ -214,7 +215,7 @@ class TRowDispatcher : public TActorBootstrapped<TRowDispatcher> {
214215

215216
NConfig::TRowDispatcherConfig Config;
216217
NKikimr::TYdbCredentialsProviderFactory CredentialsProviderFactory;
217-
NYql::NPureCalc::IProgramFactoryPtr PureCalcProgramFactory;
218+
IPureCalcProgramFactory::TPtr PureCalcProgramFactory;
218219
TYqSharedResources::TPtr YqSharedResources;
219220
TMaybe<TActorId> CoordinatorActorId;
220221
TSet<TActorId> CoordinatorChangedSubscribers;
@@ -362,7 +363,7 @@ TRowDispatcher::TRowDispatcher(
362363
const NYql::IPqGateway::TPtr& pqGateway)
363364
: Config(config)
364365
, CredentialsProviderFactory(credentialsProviderFactory)
365-
, PureCalcProgramFactory(NYql::NPureCalc::MakeProgramFactory(NYql::NPureCalc::TProgramFactoryOptions()))
366+
, PureCalcProgramFactory(CreatePureCalcProgramFactory())
366367
, YqSharedResources(yqSharedResources)
367368
, CredentialsFactory(credentialsFactory)
368369
, LogPrefix("RowDispatcher: ")

ydb/core/fq/libs/row_dispatcher/topic_session.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class TTopicSession : public TActorBootstrapped<TTopicSession> {
156156
ui32 PartitionId;
157157
NYdb::TDriver Driver;
158158
std::shared_ptr<NYdb::ICredentialsProviderFactory> CredentialsProviderFactory;
159-
NYql::NPureCalc::IProgramFactoryPtr PureCalcProgramFactory;
159+
IPureCalcProgramFactory::TPtr PureCalcProgramFactory;
160160
NYql::ITopicClient::TPtr TopicClient;
161161
std::shared_ptr<NYdb::NTopic::IReadSession> ReadSession;
162162
const i64 BufferSize;
@@ -187,7 +187,7 @@ class TTopicSession : public TActorBootstrapped<TTopicSession> {
187187
ui32 partitionId,
188188
NYdb::TDriver driver,
189189
std::shared_ptr<NYdb::ICredentialsProviderFactory> credentialsProviderFactory,
190-
NYql::NPureCalc::IProgramFactoryPtr pureCalcProgramFactory,
190+
IPureCalcProgramFactory::TPtr pureCalcProgramFactory,
191191
const ::NMonitoring::TDynamicCounterPtr& counters,
192192
const NYql::IPqGateway::TPtr& pqGateway);
193193

@@ -278,7 +278,7 @@ TTopicSession::TTopicSession(
278278
ui32 partitionId,
279279
NYdb::TDriver driver,
280280
std::shared_ptr<NYdb::ICredentialsProviderFactory> credentialsProviderFactory,
281-
NYql::NPureCalc::IProgramFactoryPtr pureCalcProgramFactory,
281+
IPureCalcProgramFactory::TPtr pureCalcProgramFactory,
282282
const ::NMonitoring::TDynamicCounterPtr& counters,
283283
const NYql::IPqGateway::TPtr& pqGateway)
284284
: TopicPath(topicPath)
@@ -734,10 +734,11 @@ void TTopicSession::Handle(NFq::TEvRowDispatcher::TEvStartSession::TPtr& ev) {
734734
std::forward_as_tuple(ev)).first->second;
735735
UpdateFieldsIds(clientInfo);
736736

737-
TString predicate = clientInfo.Settings.GetSource().GetPredicate();
737+
const auto& source = clientInfo.Settings.GetSource();
738+
TString predicate = source.GetPredicate();
738739

739740
// TODO: remove this when the re-parsing is removed from pq read actor
740-
if (predicate.empty() && HasJsonColumns(clientInfo.Settings.GetSource())) {
741+
if (predicate.empty() && HasJsonColumns(source)) {
741742
predicate = "WHERE TRUE";
742743
}
743744

@@ -749,7 +750,9 @@ void TTopicSession::Handle(NFq::TEvRowDispatcher::TEvStartSession::TPtr& ev) {
749750
[&, actorId = clientInfo.ReadActorId](ui64 offset, const TString& json){
750751
Send(SelfId(), new NFq::TEvPrivate::TEvDataAfterFilteration(offset, json, actorId));
751752
},
752-
PureCalcProgramFactory);
753+
PureCalcProgramFactory,
754+
{.EnabledLLVM = source.GetEnabledLLVM()}
755+
);
753756
} else {
754757
ClientsWithoutPredicate.insert(ev->Sender);
755758
}
@@ -987,7 +990,7 @@ std::unique_ptr<NActors::IActor> NewTopicSession(
987990
ui32 partitionId,
988991
NYdb::TDriver driver,
989992
std::shared_ptr<NYdb::ICredentialsProviderFactory> credentialsProviderFactory,
990-
NYql::NPureCalc::IProgramFactoryPtr pureCalcProgramFactory,
993+
IPureCalcProgramFactory::TPtr pureCalcProgramFactory,
991994
const ::NMonitoring::TDynamicCounterPtr& counters,
992995
const NYql::IPqGateway::TPtr& pqGateway) {
993996
return std::unique_ptr<NActors::IActor>(new TTopicSession(topicPath, endpoint, database, config, rowDispatcherActorId, partitionId, std::move(driver), credentialsProviderFactory, pureCalcProgramFactory, counters, pqGateway));

ydb/core/fq/libs/row_dispatcher/topic_session.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#pragma once
22

3+
#include "common.h"
4+
35
#include <ydb/core/fq/libs/config/protos/row_dispatcher.pb.h>
46
#include <ydb/core/fq/libs/config/protos/common.pb.h>
57
#include <ydb/core/fq/libs/shared_resources/shared_resources.h>
@@ -8,7 +10,6 @@
810

911
#include <ydb/library/yql/providers/pq/proto/dq_io.pb.h>
1012
#include <ydb/library/yql/providers/pq/provider/yql_pq_gateway.h>
11-
#include <ydb/library/yql/public/purecalc/common/fwd.h>
1213

1314
#include <ydb/library/actors/core/actor.h>
1415

@@ -25,7 +26,7 @@ std::unique_ptr<NActors::IActor> NewTopicSession(
2526
ui32 partitionId,
2627
NYdb::TDriver driver,
2728
std::shared_ptr<NYdb::ICredentialsProviderFactory> credentialsProviderFactory,
28-
NYql::NPureCalc::IProgramFactoryPtr pureCalcProgramFactory,
29+
IPureCalcProgramFactory::TPtr pureCalcProgramFactory,
2930
const ::NMonitoring::TDynamicCounterPtr& counters,
3031
const NYql::IPqGateway::TPtr& pqGateway);
3132

ydb/core/fq/libs/row_dispatcher/ut/json_filter_ut.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
#include <ydb/core/fq/libs/ydb/ydb.h>
44
#include <ydb/core/fq/libs/events/events.h>
55

6+
#include <ydb/core/fq/libs/row_dispatcher/common.h>
67
#include <ydb/core/fq/libs/row_dispatcher/json_filter.h>
78

89
#include <ydb/core/testlib/actors/test_runtime.h>
910
#include <ydb/core/testlib/basics/helpers.h>
1011
#include <ydb/core/testlib/actor_helpers.h>
1112

1213
#include <ydb/library/yql/minikql/mkql_string_util.h>
13-
#include <ydb/library/yql/public/purecalc/common/interface.h>
1414

1515
#include <library/cpp/testing/unittest/registar.h>
1616

@@ -23,7 +23,7 @@ class TFixture : public NUnitTest::TBaseFixture {
2323

2424
public:
2525
TFixture()
26-
: PureCalcProgramFactory(NYql::NPureCalc::MakeProgramFactory(NYql::NPureCalc::TProgramFactoryOptions()))
26+
: PureCalcProgramFactory(CreatePureCalcProgramFactory())
2727
, Runtime(true)
2828
, Alloc(__LOCATION__, NKikimr::TAlignedPagePoolCounters(), true, false)
2929
{}
@@ -65,7 +65,8 @@ class TFixture : public NUnitTest::TBaseFixture {
6565
types,
6666
whereFilter,
6767
callback,
68-
PureCalcProgramFactory);
68+
PureCalcProgramFactory,
69+
{.EnabledLLVM = false});
6970
}
7071

7172
const NKikimr::NMiniKQL::TUnboxedValueVector* MakeVector(size_t size, std::function<NYql::NUdf::TUnboxedValuePod(size_t)> valueCreator) {
@@ -100,7 +101,7 @@ class TFixture : public NUnitTest::TBaseFixture {
100101
});
101102
}
102103

103-
NYql::NPureCalc::IProgramFactoryPtr PureCalcProgramFactory;
104+
IPureCalcProgramFactory::TPtr PureCalcProgramFactory;
104105
NActors::TTestActorRuntime Runtime;
105106
TActorSystemStub ActorSystemStub;
106107
std::unique_ptr<NFq::TJsonFilter> Filter;

0 commit comments

Comments
 (0)