@@ -149,6 +149,16 @@ void FillTablesMap(const TKqpTable& table, const TCoAtomList& columns,
149
149
}
150
150
}
151
151
152
+ void FillTablesMap (const TKqpTable& table, const TVector<TStringBuf>& columns,
153
+ THashMap<TStringBuf, THashSet<TStringBuf>>& tablesMap)
154
+ {
155
+ FillTablesMap (table, tablesMap);
156
+
157
+ for (const auto & column : columns) {
158
+ tablesMap[table.Path ()].emplace (column);
159
+ }
160
+ }
161
+
152
162
void FillTable (const TKikimrTableMetadata& tableMeta, THashSet<TStringBuf>&& columns,
153
163
NKqpProto::TKqpPhyTable& tableProto)
154
164
{
@@ -808,7 +818,7 @@ class TKqpQueryCompiler : public IKqpQueryCompiler {
808
818
YQL_ENSURE (maybeSinkNode);
809
819
auto sinkNode = maybeSinkNode.Cast ();
810
820
auto * sinkProto = stageProto.AddSinks ();
811
- FillSink (sinkNode, sinkProto, tablesMap, ctx);
821
+ FillSink (sinkNode, sinkProto, tablesMap, stage, ctx);
812
822
sinkProto->SetOutputIndex (FromString (TStringBuf (sinkNode.Index ())));
813
823
814
824
if (IsTableSink (sinkNode.DataSink ().Cast <TCoDataSink>().Category ())) {
@@ -1074,19 +1084,34 @@ class TKqpQueryCompiler : public IKqpQueryCompiler {
1074
1084
}
1075
1085
}
1076
1086
1077
- void FillKqpSink (const TDqSink& sink, NKqpProto::TKqpSink* protoSink, THashMap<TStringBuf, THashSet<TStringBuf>>& tablesMap) {
1087
+ void FillKqpSink (const TDqSink& sink, NKqpProto::TKqpSink* protoSink, THashMap<TStringBuf, THashSet<TStringBuf>>& tablesMap, const TDqPhyStage& stage ) {
1078
1088
if (auto settings = sink.Settings ().Maybe <TKqpTableSinkSettings>()) {
1079
1089
NKqpProto::TKqpInternalSink& internalSinkProto = *protoSink->MutableInternalSink ();
1080
1090
internalSinkProto.SetType (TString (NYql::KqpTableSinkName));
1081
1091
NKikimrKqp::TKqpTableSinkSettings settingsProto;
1082
- FillTablesMap (settings.Table ().Cast (), settings.Columns ().Cast (), tablesMap);
1092
+
1093
+ const auto & tupleType = stage.Ref ().GetTypeAnn ()->Cast <TTupleExprType>();
1094
+ YQL_ENSURE (tupleType);
1095
+ YQL_ENSURE (tupleType->GetSize () == 1 );
1096
+ const auto & listType = tupleType->GetItems ()[0 ]->Cast <TListExprType>();
1097
+ YQL_ENSURE (listType);
1098
+ const auto & structType = listType->GetItemType ()->Cast <TStructExprType>();
1099
+ YQL_ENSURE (structType);
1100
+
1101
+ TVector<TStringBuf> columns;
1102
+ columns.reserve (structType->GetSize ());
1103
+ for (const auto & item : structType->GetItems ()) {
1104
+ columns.emplace_back (item->GetName ());
1105
+ }
1106
+
1107
+ FillTablesMap (settings.Table ().Cast (), columns, tablesMap);
1083
1108
FillTableId (settings.Table ().Cast (), *settingsProto.MutableTable ());
1084
1109
1085
1110
const auto tableMeta = TablesData->ExistingTable (Cluster, settings.Table ().Cast ().Path ()).Metadata ;
1086
1111
1087
- auto fillColumnProto = [] (TString columnName, const NYql::TKikimrColumnMetadata* column, NKikimrKqp::TKqpColumnMetadataProto* columnProto ) {
1112
+ auto fillColumnProto = [] (TStringBuf columnName, const NYql::TKikimrColumnMetadata* column, NKikimrKqp::TKqpColumnMetadataProto* columnProto ) {
1088
1113
columnProto->SetId (column->Id );
1089
- columnProto->SetName (columnName);
1114
+ columnProto->SetName (TString ( columnName) );
1090
1115
columnProto->SetTypeId (column->TypeInfo .GetTypeId ());
1091
1116
1092
1117
if (NScheme::NTypeIds::IsParametrizedType (column->TypeInfo .GetTypeId ())) {
@@ -1096,16 +1121,15 @@ class TKqpQueryCompiler : public IKqpQueryCompiler {
1096
1121
1097
1122
for (const auto & columnName : tableMeta->KeyColumnNames ) {
1098
1123
const auto columnMeta = tableMeta->Columns .FindPtr (columnName);
1099
- YQL_ENSURE (columnMeta != nullptr , " Unknown column in sink: \" " + columnName + " \" " );
1124
+ YQL_ENSURE (columnMeta != nullptr , " Unknown column in sink: \" " + TString ( columnName) + " \" " );
1100
1125
1101
1126
auto keyColumnProto = settingsProto.AddKeyColumns ();
1102
1127
fillColumnProto (columnName, columnMeta, keyColumnProto);
1103
1128
}
1104
1129
1105
- for (const auto & column : settings.Columns ().Cast ()) {
1106
- const auto columnName = column.StringValue ();
1130
+ for (const auto & columnName : columns) {
1107
1131
const auto columnMeta = tableMeta->Columns .FindPtr (columnName);
1108
- YQL_ENSURE (columnMeta != nullptr , " Unknown column in sink: \" " + columnName + " \" " );
1132
+ YQL_ENSURE (columnMeta != nullptr , " Unknown column in sink: \" " + TString ( columnName) + " \" " );
1109
1133
1110
1134
auto columnProto = settingsProto.AddColumns ();
1111
1135
fillColumnProto (columnName, columnMeta, columnProto);
@@ -1141,11 +1165,11 @@ class TKqpQueryCompiler : public IKqpQueryCompiler {
1141
1165
|| dataSinkCategory == NYql::KqpTableSinkName;
1142
1166
}
1143
1167
1144
- void FillSink (const TDqSink& sink, NKqpProto::TKqpSink* protoSink, THashMap<TStringBuf, THashSet<TStringBuf>>& tablesMap, TExprContext& ctx) {
1168
+ void FillSink (const TDqSink& sink, NKqpProto::TKqpSink* protoSink, THashMap<TStringBuf, THashSet<TStringBuf>>& tablesMap, const TDqPhyStage& stage, TExprContext& ctx) {
1145
1169
Y_UNUSED (ctx);
1146
1170
const TStringBuf dataSinkCategory = sink.DataSink ().Cast <TCoDataSink>().Category ();
1147
1171
if (IsTableSink (dataSinkCategory)) {
1148
- FillKqpSink (sink, protoSink, tablesMap);
1172
+ FillKqpSink (sink, protoSink, tablesMap, stage );
1149
1173
} else {
1150
1174
// Delegate sink filling to dq integration of specific provider
1151
1175
const auto provider = TypesCtx.DataSinkMap .find (dataSinkCategory);
0 commit comments