MCPcopy Create free account
hub / github.com/ByConity/ByConity / getSampleBlock

Method getSampleBlock

src/Interpreters/InterpreterInsertQuery.cpp:256–298  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

254}
255
256Block InterpreterInsertQuery::getSampleBlock(
257 const ASTInsertQuery & query, const StoragePtr & table, const StorageMetadataPtr & metadata_snapshot) const
258{
259 /// If the query does not include information about columns
260 if (!query.columns)
261 {
262 if (no_destination)
263 return metadata_snapshot->getSampleBlockWithVirtuals(table->getVirtuals());
264 else
265 return metadata_snapshot->getSampleBlockNonMaterialized();
266 }
267
268 Block table_sample_non_materialized;
269 if (no_destination)
270 table_sample_non_materialized = metadata_snapshot->getSampleBlockWithVirtuals(table->getVirtuals());
271 else
272 table_sample_non_materialized = metadata_snapshot->getSampleBlockNonMaterialized(/*include_func_columns*/ true);
273
274 Block table_sample = metadata_snapshot->getSampleBlock(/*include_func_columns*/ true);
275
276 const auto columns_ast = processColumnTransformers(getContext()->getCurrentDatabase(), table, metadata_snapshot, query.columns);
277
278 /// Form the block based on the column names from the query
279 Block res;
280 for (const auto & identifier : columns_ast->children)
281 {
282 std::string current_name = identifier->getColumnName();
283
284 /// The table does not have a column with that name
285 if (!table_sample.has(current_name))
286 throw Exception(
287 "No such column " + current_name + " in table " + table->getStorageID().getNameForLogs(),
288 ErrorCodes::NO_SUCH_COLUMN_IN_TABLE);
289
290 if (!allow_materialized && !table_sample_non_materialized.has(current_name))
291 throw Exception("Cannot insert column " + current_name + ", because it is MATERIALIZED column.", ErrorCodes::ILLEGAL_COLUMN);
292 if (res.has(current_name))
293 throw Exception("Column " + current_name + " specified more than once", ErrorCodes::DUPLICATE_COLUMN);
294
295 res.insert(ColumnWithTypeAndName(table_sample.getByName(current_name).type, current_name));
296 }
297 return res;
298}
299
300
301/** A query that just reads all data without any complex computations or filetering.

Callers

nothing calls this directly

Calls 13

getCurrentDatabaseMethod · 0.80
getByNameMethod · 0.80
ExceptionClass · 0.70
getVirtualsMethod · 0.45
getColumnNameMethod · 0.45
hasMethod · 0.45
getNameForLogsMethod · 0.45
getStorageIDMethod · 0.45

Tested by

no test coverage detected