MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / getTable

Method getTable

src/Interpreters/InterpreterInsertQuery.cpp:143–199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

141}
142
143StoragePtr InterpreterInsertQuery::getTable(ASTInsertQuery & query)
144{
145 auto current_context = getContext();
146
147 if (query.table_function)
148 {
149 const auto & factory = TableFunctionFactory::instance();
150 TableFunctionPtr table_function_ptr = factory.get(query.table_function, current_context);
151
152 /// If table function needs structure hint from select query
153 /// we can create a temporary pipeline and get the header.
154 if (query.select && table_function_ptr->needStructureHint())
155 {
156 SharedHeader header_block;
157 auto select_query_options = SelectQueryOptions(QueryProcessingStage::Complete, 1);
158
159 if (current_context->getSettingsRef()[Setting::allow_experimental_analyzer])
160 {
161 header_block = InterpreterSelectQueryAnalyzer::getSampleBlock(query.select, current_context, select_query_options);
162 }
163 else
164 {
165 ASTPtr input_function;
166 query.tryFindInputFunction(input_function);
167 if (input_function)
168 throw Exception(ErrorCodes::QUERY_IS_PROHIBITED, "Schema inference is not supported with allow_experimental_analyzer=0 for INSERT INTO FUNCTION ... SELECT FROM input()");
169
170 InterpreterSelectWithUnionQuery interpreter_select{
171 query.select, current_context, select_query_options};
172 auto tmp_pipeline = interpreter_select.buildQueryPipeline();
173 header_block = tmp_pipeline.getSharedHeader();
174 }
175
176 ColumnsDescription structure_hint{header_block->getNamesAndTypesList()};
177 table_function_ptr->setStructureHint(structure_hint);
178 }
179
180 table_function_ptr->setPartitionBy(query.partition_by);
181
182 return table_function_ptr->execute(query.table_function, current_context, table_function_ptr->getName(),
183 /* cached_columns */ {}, /* use_global_context */ false, /* is_insert_query */true);
184 }
185
186 if (query.table_id)
187 {
188 query.table_id = current_context->resolveStorageID(query.table_id);
189 }
190 else
191 {
192 /// Insert query parser does not fill table_id because table and
193 /// database can be parameters and be filled after parsing.
194 StorageID local_table_id(query.getDatabase(), query.getTable());
195 query.table_id = current_context->resolveStorageID(local_table_id);
196 }
197
198 return DatabaseCatalog::instance().getTable(query.table_id, current_context);
199}
200

Calls 15

tryFindInputFunctionMethod · 0.80
getSharedHeaderMethod · 0.80
resolveStorageIDMethod · 0.80
SelectQueryOptionsClass · 0.70
getSampleBlockFunction · 0.70
ExceptionClass · 0.70
getContextFunction · 0.50
getMethod · 0.45
needStructureHintMethod · 0.45
buildQueryPipelineMethod · 0.45
getNamesAndTypesListMethod · 0.45
setStructureHintMethod · 0.45

Tested by

no test coverage detected