| 300 | } |
| 301 | |
| 302 | String CnchStorageCommonHelper::getCreateQueryForCloudTable( |
| 303 | const String & query, |
| 304 | const String & local_table_name, |
| 305 | const ContextPtr & /*context*/, |
| 306 | bool enable_staging_area, |
| 307 | const std::optional<StorageID> & cnch_storage_id, |
| 308 | const Strings & engine_args, |
| 309 | const String & local_database_name, |
| 310 | WorkerEngineType engine_type) const |
| 311 | { |
| 312 | ParserCreateQuery parser; |
| 313 | ASTPtr ast = parseQuery(parser, query.data(), query.data() + query.size(), "", 0, DBMS_DEFAULT_MAX_PARSER_DEPTH); |
| 314 | |
| 315 | auto & create_query = ast->as<ASTCreateQuery &>(); |
| 316 | create_query.table = local_table_name; |
| 317 | if (!local_database_name.empty()) |
| 318 | create_query.database = local_database_name; |
| 319 | |
| 320 | replaceCnchWithCloud( |
| 321 | create_query.storage, |
| 322 | cnch_storage_id.value_or(table_id).getDatabaseName(), |
| 323 | cnch_storage_id.value_or(table_id).getTableName(), |
| 324 | engine_type, |
| 325 | engine_args); |
| 326 | |
| 327 | // perhaps better to enable if_not_exists by default |
| 328 | if (engine_type == WorkerEngineType::DICT) |
| 329 | create_query.if_not_exists = true; |
| 330 | |
| 331 | if (enable_staging_area) |
| 332 | modifyOrAddSetting(create_query, "cloud_enable_staging_area", Field(UInt64(1))); |
| 333 | |
| 334 | WriteBufferFromOwnString statement_buf; |
| 335 | formatAST(create_query, statement_buf, false); |
| 336 | writeChar('\n', statement_buf); |
| 337 | LOG_TRACE( |
| 338 | &Poco::Logger::get("getCreateQueryForCloudTable"), "create query for cloud table is {}", statement_buf.str()); |
| 339 | return statement_buf.str(); |
| 340 | } |
| 341 | |
| 342 | bool CnchStorageCommonHelper::forwardQueryToServerIfNeeded(ContextPtr query_context, const StorageID & storage_id, const String & query_to_forward, bool need_process_entry) const |
| 343 | { |