mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
Implement type inference for INSERT INTO function null()
This commit is contained in:
parent
71dc0f0616
commit
293d0a5d46
@ -21,13 +21,16 @@ void TableFunctionNull::parseArguments(const ASTPtr & ast_function, ContextPtr c
|
||||
{
|
||||
const auto * function = ast_function->as<ASTFunction>();
|
||||
if (!function || !function->arguments)
|
||||
throw Exception("Table function '" + getName() + "' requires 'structure'.", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
||||
throw Exception("Table function '" + getName() + "' requires 'structure'", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
||||
|
||||
const auto & arguments = function->arguments->children;
|
||||
if (arguments.size() != 1)
|
||||
throw Exception("Table function '" + getName() + "' requires 'structure'.", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
||||
if (!arguments.empty() && arguments.size() != 1)
|
||||
throw Exception(
|
||||
"Table function '" + getName() + "' requires 'structure' argument or empty argument",
|
||||
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
||||
|
||||
structure = evaluateConstantExpressionOrIdentifierAsLiteral(arguments[0], context)->as<ASTLiteral>()->value.safeGet<String>();
|
||||
if (!arguments.empty())
|
||||
structure = evaluateConstantExpressionOrIdentifierAsLiteral(arguments[0], context)->as<ASTLiteral>()->value.safeGet<String>();
|
||||
}
|
||||
|
||||
ColumnsDescription TableFunctionNull::getActualTableStructure(ContextPtr context) const
|
||||
@ -37,7 +40,11 @@ ColumnsDescription TableFunctionNull::getActualTableStructure(ContextPtr context
|
||||
|
||||
StoragePtr TableFunctionNull::executeImpl(const ASTPtr & /*ast_function*/, ContextPtr context, const std::string & table_name, ColumnsDescription /*cached_columns*/) const
|
||||
{
|
||||
auto columns = getActualTableStructure(context);
|
||||
ColumnsDescription columns;
|
||||
if (structure != "auto")
|
||||
columns = getActualTableStructure(context);
|
||||
else if (!structure_hint.empty())
|
||||
columns = structure_hint;
|
||||
auto res = StorageNull::create(StorageID(getDatabaseName(), table_name), columns, ConstraintsDescription(), String{});
|
||||
res->startup();
|
||||
return res;
|
||||
|
@ -16,6 +16,10 @@ class TableFunctionNull : public ITableFunction
|
||||
public:
|
||||
static constexpr auto name = "null";
|
||||
std::string getName() const override { return name; }
|
||||
|
||||
bool needStructureHint() const override { return structure == "auto"; }
|
||||
|
||||
void setStructureHint(const ColumnsDescription & structure_hint_) override { structure_hint = structure_hint_; }
|
||||
private:
|
||||
StoragePtr executeImpl(const ASTPtr & ast_function, ContextPtr context, const String & table_name, ColumnsDescription cached_columns) const override;
|
||||
const char * getStorageTypeName() const override { return "Null"; }
|
||||
@ -23,7 +27,8 @@ private:
|
||||
void parseArguments(const ASTPtr & ast_function, ContextPtr context) override;
|
||||
ColumnsDescription getActualTableStructure(ContextPtr context) const override;
|
||||
|
||||
String structure;
|
||||
String structure = "auto";
|
||||
ColumnsDescription structure_hint;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,3 @@
|
||||
INSERT INTO function null() SELECT 1;
|
||||
INSERT INTO function null() SELECT number FROM numbers(10);
|
||||
INSERT INTO function null() SELECT number, toString(number) FROM numbers(10);
|
Loading…
Reference in New Issue
Block a user