@@ -876,6 +876,13 @@ TVector<TKiDataQueryBlock> MakeKiDataQueryBlocks(TExprBase node, const TKiExplor
876
876
return queryBlocks;
877
877
}
878
878
879
+ TString GetShowCreateType (const TExprNode& settings) {
880
+ if (HasSetting (settings, " showCreateTable" )) {
881
+ return " showCreateTable" ;
882
+ }
883
+ return " " ;
884
+ }
885
+
879
886
} // namespace
880
887
881
888
TExprNode::TPtr KiBuildQuery (TExprBase node, TExprContext& ctx, TStringBuf database, TIntrusivePtr<TKikimrTablesData> tablesData,
@@ -953,23 +960,23 @@ TExprNode::TPtr KiBuildQuery(TExprBase node, TExprContext& ctx, TStringBuf datab
953
960
return res;
954
961
}
955
962
956
- TNodeOnNodeOwnedMap showCreateTableReadReplaces ;
957
- VisitExpr (node.Ptr (), [&showCreateTableReadReplaces ](const TExprNode::TPtr& input) -> bool {
963
+ TNodeOnNodeOwnedMap showCreateReadReplacements ;
964
+ VisitExpr (node.Ptr (), [&showCreateReadReplacements ](const TExprNode::TPtr& input) -> bool {
958
965
TExprBase currentNode (input);
959
966
if (auto maybeReadTable = currentNode.Maybe <TKiReadTable>()) {
960
967
auto readTable = maybeReadTable.Cast ();
961
968
for (auto setting : readTable.Settings ()) {
962
969
auto name = setting.Name ().Value ();
963
970
if (name == " showCreateTable" ) {
964
- showCreateTableReadReplaces [input.Get ()] = nullptr ;
971
+ showCreateReadReplacements [input.Get ()] = nullptr ;
965
972
}
966
973
}
967
974
}
968
975
return true ;
969
976
});
970
977
971
- if (!showCreateTableReadReplaces .empty ()) {
972
- for (auto & [input, _] : showCreateTableReadReplaces ) {
978
+ if (!showCreateReadReplacements .empty ()) {
979
+ for (auto & [input, _] : showCreateReadReplacements ) {
973
980
TKiReadTable content (input);
974
981
975
982
TExprNode::TPtr path = ctx.NewCallable (
@@ -983,6 +990,9 @@ TExprNode::TPtr KiBuildQuery(TExprBase node, TExprContext& ctx, TStringBuf datab
983
990
TKikimrKey key (ctx);
984
991
YQL_ENSURE (key.Extract (content.TableKey ().Ref ()));
985
992
993
+ auto type = GetShowCreateType (content.Settings ().Ref ());
994
+ YQL_ENSURE (!type.empty ());
995
+
986
996
auto sysViewRewrittenValue = Build<TCoNameValueTuple>(ctx, node.Pos ())
987
997
.Name ()
988
998
.Build (" sysViewRewritten" )
@@ -991,12 +1001,12 @@ TExprNode::TPtr KiBuildQuery(TExprBase node, TExprContext& ctx, TStringBuf datab
991
1001
.Build ()
992
1002
.Done ();
993
1003
994
- auto showCreateTableValue = Build<TCoNameValueTuple>(ctx, node.Pos ())
1004
+ auto showCreateTypeValue = Build<TCoNameValueTuple>(ctx, node.Pos ())
995
1005
.Name ()
996
- .Build (" showCreateTable " )
1006
+ .Build (type )
997
1007
.Done ();
998
1008
999
- auto showCreateTableRead = Build<TCoRead>(ctx, node.Pos ())
1009
+ auto showCreateRead = Build<TCoRead>(ctx, node.Pos ())
1000
1010
.World <TCoWorld>().Build ()
1001
1011
.DataSource <TCoDataSource>()
1002
1012
.Category (ctx.NewAtom (node.Pos (), KikimrProviderName))
@@ -1009,61 +1019,65 @@ TExprNode::TPtr KiBuildQuery(TExprBase node, TExprContext& ctx, TStringBuf datab
1009
1019
.Add (ctx.NewCallable (node.Pos (), " Void" , {}))
1010
1020
.Add (ctx.NewList (node.Pos (), {}))
1011
1021
.Add (sysViewRewrittenValue)
1012
- .Add (showCreateTableValue )
1022
+ .Add (showCreateTypeValue )
1013
1023
.Build ()
1014
1024
.Done ().Ptr ();
1015
1025
1016
- showCreateTableReadReplaces [input] = showCreateTableRead ;
1026
+ showCreateReadReplacements [input] = showCreateRead ;
1017
1027
}
1018
- auto res = ctx.ReplaceNodes (std::move (node.Ptr ()), showCreateTableReadReplaces );
1028
+ auto res = ctx.ReplaceNodes (std::move (node.Ptr ()), showCreateReadReplacements );
1019
1029
1020
1030
TExprBase resNode (res);
1021
1031
1022
- TNodeOnNodeOwnedMap showCreateTableRightReplaces ;
1023
- VisitExpr (resNode.Ptr (), [&showCreateTableRightReplaces ](const TExprNode::TPtr& input) -> bool {
1032
+ TNodeOnNodeOwnedMap showCreateRightReplacements ;
1033
+ VisitExpr (resNode.Ptr (), [&showCreateRightReplacements ](const TExprNode::TPtr& input) -> bool {
1024
1034
TExprBase currentNode (input);
1025
1035
if (auto rightMaybe = currentNode.Maybe <TCoRight>()) {
1026
1036
auto right = rightMaybe.Cast ();
1027
1037
if (auto maybeRead = right.Input ().Maybe <TCoRead>()) {
1028
1038
auto read = maybeRead.Cast ();
1029
1039
bool isSysViewRewritten = false ;
1030
- bool isShowCreateTable = false ;
1040
+ bool isShowCreate = false ;
1031
1041
for (auto arg : read.FreeArgs ()) {
1032
1042
if (auto tuple = arg.Maybe <TCoNameValueTuple>()) {
1033
1043
auto name = tuple.Cast ().Name ().Value ();
1034
1044
if (name == " sysViewRewritten" ) {
1035
1045
isSysViewRewritten = true ;
1036
1046
} else if (name == " showCreateTable" ) {
1037
- isShowCreateTable = true ;
1047
+ isShowCreate = true ;
1038
1048
}
1039
1049
}
1040
1050
}
1041
- if (isShowCreateTable && isSysViewRewritten) {
1042
- showCreateTableRightReplaces [input.Get ()] = nullptr ;
1051
+ if (isShowCreate && isSysViewRewritten) {
1052
+ showCreateRightReplacements [input.Get ()] = nullptr ;
1043
1053
}
1044
1054
}
1045
1055
}
1046
1056
return true ;
1047
1057
});
1048
1058
1049
- for (auto & [input, _] : showCreateTableRightReplaces ) {
1059
+ for (auto & [input, _] : showCreateRightReplacements ) {
1050
1060
TCoRight right (input);
1051
1061
TCoRead read (right.Input ().Ptr ());
1052
1062
1053
- TString tablePath;
1063
+ TString path;
1064
+ TString pathType;
1054
1065
for (auto arg : read.FreeArgs ()) {
1055
1066
if (auto tuple = arg.Maybe <TCoNameValueTuple>()) {
1056
1067
auto name = tuple.Cast ().Name ().Value ();
1057
1068
if (name == " sysViewRewritten" ) {
1058
- tablePath = tuple.Cast ().Value ().Cast ().Cast <TCoAtom>().StringValue ();
1069
+ path = tuple.Cast ().Value ().Cast ().Cast <TCoAtom>().StringValue ();
1070
+ }
1071
+ if (name == " showCreateTable" ) {
1072
+ pathType = " Table" ;
1059
1073
}
1060
1074
}
1061
1075
}
1062
- YQL_ENSURE (!tablePath .empty (), " Unexpected empty table path for SHOW CREATE TABLE " );
1076
+ YQL_ENSURE (!path .empty (), " Unexpected empty path for SHOW CREATE " << pathType. to_upper () );
1063
1077
1064
- auto tempTablePath = tablesData->GetTempTablePath (tablePath );
1078
+ auto tempTablePath = tablesData->GetTempTablePath (path );
1065
1079
if (tempTablePath) {
1066
- tablePath = tempTablePath.value ();
1080
+ path = tempTablePath.value ();
1067
1081
}
1068
1082
1069
1083
auto showCreateArg = Build<TCoArgument>(ctx, resNode.Pos ())
@@ -1082,7 +1096,7 @@ TExprNode::TPtr KiBuildQuery(TExprBase node, TExprContext& ctx, TStringBuf datab
1082
1096
auto pathCondition = Build<TCoCmpEqual>(ctx, resNode.Pos ())
1083
1097
.Left (columnPath)
1084
1098
.Right <TCoString>()
1085
- .Literal ().Build (tablePath )
1099
+ .Literal ().Build (path )
1086
1100
.Build ()
1087
1101
.Done ();
1088
1102
@@ -1095,7 +1109,7 @@ TExprNode::TPtr KiBuildQuery(TExprBase node, TExprContext& ctx, TStringBuf datab
1095
1109
auto pathTypeCondition = Build<TCoCmpEqual>(ctx, resNode.Pos ())
1096
1110
.Left (columnPathType)
1097
1111
.Right <TCoString>()
1098
- .Literal ().Build (" Table " )
1112
+ .Literal ().Build (pathType )
1099
1113
.Build ()
1100
1114
.Done ();
1101
1115
@@ -1121,7 +1135,7 @@ TExprNode::TPtr KiBuildQuery(TExprBase node, TExprContext& ctx, TStringBuf datab
1121
1135
.Lambda (lambda)
1122
1136
.Done ().Ptr ();
1123
1137
1124
- showCreateTableRightReplaces [input] = filterData;
1138
+ showCreateRightReplacements [input] = filterData;
1125
1139
}
1126
1140
1127
1141
ctx.Step
@@ -1133,7 +1147,7 @@ TExprNode::TPtr KiBuildQuery(TExprBase node, TExprContext& ctx, TStringBuf datab
1133
1147
.Repeat (TExprStep::LoadTablesMetadata)
1134
1148
.Repeat (TExprStep::RewriteIO);
1135
1149
1136
- return ctx.ReplaceNodes (std::move (resNode.Ptr ()), showCreateTableRightReplaces );
1150
+ return ctx.ReplaceNodes (std::move (resNode.Ptr ()), showCreateRightReplacements );
1137
1151
}
1138
1152
1139
1153
TKiExploreTxResults txExplore;
0 commit comments