| 2608 | } |
| 2609 | |
| 2610 | bool TCPHandler::processData(QueryState & state, bool scalar) |
| 2611 | { |
| 2612 | initBlockInput(state); |
| 2613 | |
| 2614 | /// The name of the temporary table for writing data, default to empty string |
| 2615 | auto temporary_id = StorageID::createEmpty(); |
| 2616 | readStringBinary(temporary_id.table_name, *in); |
| 2617 | |
| 2618 | /// Read one block from the network and write it down |
| 2619 | Block block = state.block_in->read(); |
| 2620 | |
| 2621 | if (block.empty()) |
| 2622 | return false; |
| 2623 | |
| 2624 | if (scalar) |
| 2625 | { |
| 2626 | /// Scalar value |
| 2627 | state.query_context->addScalar(temporary_id.table_name, block); |
| 2628 | } |
| 2629 | else if (!state.need_receive_data_for_insert && !state.need_receive_data_for_input) |
| 2630 | { |
| 2631 | /// Data for external tables |
| 2632 | |
| 2633 | auto resolved = state.query_context->tryResolveStorageID(temporary_id, Context::ResolveExternal); |
| 2634 | StoragePtr storage; |
| 2635 | /// If such a table does not exist, create it. |
| 2636 | if (resolved) |
| 2637 | { |
| 2638 | storage = DatabaseCatalog::instance().getTable(resolved, state.query_context); |
| 2639 | } |
| 2640 | else |
| 2641 | { |
| 2642 | NamesAndTypesList columns = block.getNamesAndTypesList(); |
| 2643 | auto temporary_table = TemporaryTableHolder(state.query_context, ColumnsDescription(columns), {}); |
| 2644 | storage = temporary_table.getTable(); |
| 2645 | state.query_context->addExternalTable(temporary_id.table_name, std::move(temporary_table)); |
| 2646 | } |
| 2647 | auto metadata_snapshot = storage->getInMemoryMetadataPtr(state.query_context, false); |
| 2648 | /// The data will be written directly to the table. |
| 2649 | QueryPipeline temporary_table_out(storage->write(ASTPtr(), metadata_snapshot, state.query_context, /*async_insert=*/false)); |
| 2650 | PushingPipelineExecutor executor(temporary_table_out); |
| 2651 | executor.start(); |
| 2652 | executor.push(block); |
| 2653 | executor.finish(); |
| 2654 | } |
| 2655 | else if (state.need_receive_data_for_input) |
| 2656 | { |
| 2657 | /// 'input' table function. |
| 2658 | state.block_for_input = block; |
| 2659 | } |
| 2660 | else |
| 2661 | { |
| 2662 | /// INSERT query. |
| 2663 | state.block_for_insert = block; |
| 2664 | } |
| 2665 | |
| 2666 | return true; |
| 2667 | } |
nothing calls this directly
no test coverage detected