1
1
#include " yql_pq_mkql_compiler.h"
2
+ #include " yql_pq_helpers.h"
2
3
3
4
#include < ydb/library/yql/providers/pq/common/yql_names.h>
4
5
#include < ydb/library/yql/providers/pq/expr_nodes/yql_pq_expr_nodes.h>
@@ -12,22 +13,6 @@ using namespace NNodes;
12
13
13
14
namespace {
14
15
15
- TMaybeNode<TExprBase> FindSetting (TExprNode::TPtr settings, TStringBuf name) {
16
- const auto maybeSettingsList = TMaybeNode<TCoNameValueTupleList>(settings);
17
- if (!maybeSettingsList) {
18
- return nullptr ;
19
- }
20
- const auto settingsList = maybeSettingsList.Cast ();
21
-
22
- for (size_t i = 0 ; i < settingsList.Size (); ++i) {
23
- TCoNameValueTuple setting = settingsList.Item (i);
24
- if (setting.Name ().Value () == name) {
25
- return setting.Value ();
26
- }
27
- }
28
- return nullptr ;
29
- }
30
-
31
16
bool UseSharedReading (TExprNode::TPtr settings) {
32
17
const auto maybeInnerSettings = FindSetting (settings, " settings" );
33
18
if (!maybeInnerSettings) {
@@ -43,26 +28,42 @@ bool UseSharedReading(TExprNode::TPtr settings) {
43
28
return value.IsAtom () && FromString<bool >(value.Content ());
44
29
}
45
30
31
+ TRuntimeNode WrapSharedReading (const TDqSourceWrapBase &wrapper, NCommon::TMkqlBuildContext& ctx) {
32
+ const auto input = MkqlBuildExpr (wrapper.Input ().Ref (), ctx);
33
+ const auto flow = ctx.ProgramBuilder .ToFlow (input);
34
+
35
+ const TStructExprType* rowType = wrapper.RowType ().Ref ().GetTypeAnn ()->Cast <TTypeExprType>()->GetType ()->Cast <TStructExprType>();
36
+ const auto * finalItemStructType = static_cast <TStructType*>(NCommon::BuildType (wrapper.RowType ().Ref (), *rowType, ctx.ProgramBuilder ));
37
+
38
+ return ctx.ProgramBuilder .ExpandMap (flow, [&](TRuntimeNode item) -> TRuntimeNode::TList {
39
+ TRuntimeNode::TList fields;
40
+ fields.reserve (finalItemStructType->GetMembersCount ());
41
+ for (ui32 i = 0 ; i < finalItemStructType->GetMembersCount (); ++i) {
42
+ fields.push_back (ctx.ProgramBuilder .Member (item, finalItemStructType->GetMemberName (i)));
43
+ }
44
+ return fields;
45
+ });
46
+ }
47
+
46
48
}
47
49
48
50
void RegisterDqPqMkqlCompilers (NCommon::TMkqlCallableCompilerBase& compiler) {
49
51
compiler.ChainCallable (TDqSourceWideWrap::CallableName (),
50
52
[](const TExprNode& node, NCommon::TMkqlBuildContext& ctx) {
51
53
if (const auto wrapper = TDqSourceWideWrap (&node); wrapper.DataSource ().Category ().Value () == PqProviderName) {
54
+ if (const auto maybeSettings = wrapper.Settings ()) {
55
+ if (UseSharedReading (maybeSettings.Cast ().Ptr ())) {
56
+ return WrapSharedReading (wrapper, ctx);
57
+ }
58
+ }
59
+
52
60
const auto wrapped = TryWrapWithParser (wrapper, ctx);
53
61
if (wrapped) {
54
62
return *wrapped;
55
63
}
56
64
57
65
const auto input = MkqlBuildExpr (wrapper.Input ().Ref (), ctx);
58
66
auto flow = ctx.ProgramBuilder .ToFlow (input);
59
-
60
- if (const auto maybeSettings = wrapper.Settings ()) {
61
- if (UseSharedReading (maybeSettings.Cast ().Ptr ())) {
62
- return flow;
63
- }
64
- }
65
-
66
67
return ctx.ProgramBuilder .ExpandMap (flow,
67
68
[&](TRuntimeNode item) -> TRuntimeNode::TList {
68
69
return {item};
0 commit comments