@@ -2113,6 +2113,125 @@ Y_UNIT_TEST_SUITE(KqpFederatedQuery) {
2113
2113
}
2114
2114
}
2115
2115
2116
+ Y_UNIT_TEST (TestOlapToS3Insert) {
2117
+ const TString root = " /Root/" ;
2118
+ const TString source = " source" ;
2119
+ const TString table1 = " table1" ;
2120
+ const TString table2 = " table2" ;
2121
+ const TString bucket = " bucket" ;
2122
+
2123
+ CreateBucket (bucket);
2124
+
2125
+ auto kikimr = NTestUtils::MakeKikimrRunner ();
2126
+
2127
+ auto tc = kikimr->GetTableClient ();
2128
+ auto session = tc.CreateSession ().GetValueSync ().GetSession ();
2129
+
2130
+ const TString olapTable = " DestinationOlap" ;
2131
+
2132
+ const TString query = fmt::format (R"(
2133
+ CREATE EXTERNAL DATA SOURCE `{source}` WITH (
2134
+ SOURCE_TYPE="ObjectStorage",
2135
+ LOCATION="{location}",
2136
+ AUTH_METHOD="NONE"
2137
+ );
2138
+ CREATE EXTERNAL TABLE `{table1}` (
2139
+ key Int64 NOT NULL,
2140
+ value String NOT NULL,
2141
+ ) WITH (
2142
+ DATA_SOURCE="{source}",
2143
+ LOCATION="/{location_table1}/",
2144
+ FORMAT="csv_with_names"
2145
+ );
2146
+ CREATE EXTERNAL TABLE `{table2}` (
2147
+ key Int64 NOT NULL,
2148
+ value String NOT NULL,
2149
+ year String NOT NULL
2150
+ ) WITH (
2151
+ DATA_SOURCE="{source}",
2152
+ LOCATION="/{location_table2}/",
2153
+ FORMAT="csv_with_names",
2154
+ PARTITIONED_BY="['year']"
2155
+ );
2156
+ CREATE TABLE `{olap_table}` (
2157
+ key Int64 NOT NULL,
2158
+ value String NOT NULL,
2159
+ PRIMARY KEY (key)
2160
+ )
2161
+ WITH (STORE = COLUMN);)" ,
2162
+ " location" _a = GetBucketLocation (bucket),
2163
+ " source" _a = root + source,
2164
+ " table1" _a = root + table1,
2165
+ " table2" _a = root + table2,
2166
+ " location_table1" _a = table1,
2167
+ " location_table2" _a = table2,
2168
+ " olap_table" _a = olapTable
2169
+ );
2170
+ auto result = session.ExecuteSchemeQuery (query).GetValueSync ();
2171
+ UNIT_ASSERT_VALUES_EQUAL_C (result.GetStatus (), NYdb::EStatus::SUCCESS, result.GetIssues ().ToString ());
2172
+
2173
+ auto db = kikimr->GetQueryClient ();
2174
+
2175
+ {
2176
+ const TString sql = fmt::format (R"(
2177
+ INSERT INTO {destination}
2178
+ SELECT key, value FROM {source};)" ,
2179
+ " destination" _a = table1,
2180
+ " source" _a = olapTable);
2181
+
2182
+ auto scriptExecutionOperation = db.ExecuteScript (sql).ExtractValueSync ();
2183
+ UNIT_ASSERT_VALUES_EQUAL_C (scriptExecutionOperation.Status ().GetStatus (), EStatus::SUCCESS, scriptExecutionOperation.Status ().GetIssues ().ToString ());
2184
+ UNIT_ASSERT (scriptExecutionOperation.Metadata ().ExecutionId );
2185
+
2186
+ NYdb::NQuery::TScriptExecutionOperation readyOp = WaitScriptExecutionOperation (scriptExecutionOperation.Id (), kikimr->GetDriver ());
2187
+ UNIT_ASSERT_EQUAL_C (readyOp.Metadata ().ExecStatus , EExecStatus::Completed, readyOp.Status ().GetIssues ().ToString ());
2188
+ }
2189
+
2190
+ {
2191
+ const TString sql = fmt::format (R"(
2192
+ INSERT INTO {destination}
2193
+ SELECT key, value FROM {source} LIMIT 1;)" ,
2194
+ " destination" _a = table1,
2195
+ " source" _a = olapTable);
2196
+
2197
+ auto scriptExecutionOperation = db.ExecuteScript (sql).ExtractValueSync ();
2198
+ UNIT_ASSERT_VALUES_EQUAL_C (scriptExecutionOperation.Status ().GetStatus (), EStatus::SUCCESS, scriptExecutionOperation.Status ().GetIssues ().ToString ());
2199
+ UNIT_ASSERT (scriptExecutionOperation.Metadata ().ExecutionId );
2200
+
2201
+ NYdb::NQuery::TScriptExecutionOperation readyOp = WaitScriptExecutionOperation (scriptExecutionOperation.Id (), kikimr->GetDriver ());
2202
+ UNIT_ASSERT_EQUAL_C (readyOp.Metadata ().ExecStatus , EExecStatus::Completed, readyOp.Status ().GetIssues ().ToString ());
2203
+ }
2204
+
2205
+ {
2206
+ const TString sql = fmt::format (R"(
2207
+ INSERT INTO {destination}
2208
+ SELECT key, value, "2024" AS year FROM {source};)" ,
2209
+ " destination" _a = table2,
2210
+ " source" _a = olapTable);
2211
+
2212
+ auto scriptExecutionOperation = db.ExecuteScript (sql).ExtractValueSync ();
2213
+ UNIT_ASSERT_VALUES_EQUAL_C (scriptExecutionOperation.Status ().GetStatus (), EStatus::SUCCESS, scriptExecutionOperation.Status ().GetIssues ().ToString ());
2214
+ UNIT_ASSERT (scriptExecutionOperation.Metadata ().ExecutionId );
2215
+
2216
+ NYdb::NQuery::TScriptExecutionOperation readyOp = WaitScriptExecutionOperation (scriptExecutionOperation.Id (), kikimr->GetDriver ());
2217
+ UNIT_ASSERT_EQUAL_C (readyOp.Metadata ().ExecStatus , EExecStatus::Completed, readyOp.Status ().GetIssues ().ToString ());
2218
+ }
2219
+
2220
+ {
2221
+ const TString sql = fmt::format (R"(
2222
+ INSERT INTO {destination}
2223
+ SELECT key, value, "2024" AS year FROM {source} LIMIT 1;)" ,
2224
+ " destination" _a = table2,
2225
+ " source" _a = olapTable);
2226
+
2227
+ auto scriptExecutionOperation = db.ExecuteScript (sql).ExtractValueSync ();
2228
+ UNIT_ASSERT_VALUES_EQUAL_C (scriptExecutionOperation.Status ().GetStatus (), EStatus::SUCCESS, scriptExecutionOperation.Status ().GetIssues ().ToString ());
2229
+ UNIT_ASSERT (scriptExecutionOperation.Metadata ().ExecutionId );
2230
+
2231
+ NYdb::NQuery::TScriptExecutionOperation readyOp = WaitScriptExecutionOperation (scriptExecutionOperation.Id (), kikimr->GetDriver ());
2232
+ UNIT_ASSERT_EQUAL_C (readyOp.Metadata ().ExecStatus , EExecStatus::Completed, readyOp.Status ().GetIssues ().ToString ());
2233
+ }
2234
+ }
2116
2235
}
2117
2236
2118
2237
} // namespace NKikimr::NKqp
0 commit comments