Allow insert select for files with formats without schema inference

This commit is contained in:
avogar 2022-04-13 20:02:52 +00:00
parent 6a165787a6
commit ae88549c4f
4 changed files with 4 additions and 24 deletions

View File

@ -94,7 +94,7 @@ ColumnsDescription readSchemaFromFormat(
}
}
else
throw Exception(ErrorCodes::BAD_ARGUMENTS, "{} file format doesn't support schema inference", format_name);
throw Exception(ErrorCodes::BAD_ARGUMENTS, "{} file format doesn't support schema inference. You must specify the structure manually", format_name);
return ColumnsDescription(names_and_types);
}

View File

@ -25,24 +25,6 @@ namespace ErrorCodes
extern const int BAD_ARGUMENTS;
}
namespace
{
void checkIfFormatSupportsAutoStructure(const String & name, const String & format)
{
if (name == "file" && format == "Distributed")
return;
if (FormatFactory::instance().checkIfFormatHasAnySchemaReader(format))
return;
throw Exception(
"Table function '" + name
+ "' allows automatic structure determination only for formats that support schema inference and for Distributed format in table function "
"'file'",
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
}
}
void ITableFunctionFileLike::parseArguments(const ASTPtr & ast_function, ContextPtr context)
{
/// Parse args
@ -68,18 +50,13 @@ void ITableFunctionFileLike::parseArguments(const ASTPtr & ast_function, Context
format = FormatFactory::instance().getFormatFromFileName(filename, true);
if (args.size() <= 2)
{
checkIfFormatSupportsAutoStructure(getName(), format);
return;
}
if (args.size() != 3 && args.size() != 4)
throw Exception("Table function '" + getName() + "' requires 1, 2, 3 or 4 arguments: filename, format (default auto), structure (default auto) and compression method (default auto)",
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
structure = args[2]->as<ASTLiteral &>().value.safeGet<String>();
if (structure == "auto")
checkIfFormatSupportsAutoStructure(getName(), format);
if (structure.empty())
throw Exception(ErrorCodes::BAD_ARGUMENTS,

View File

@ -0,0 +1,2 @@
insert into function file('02269_data', 'RowBinary') select 1;
select * from file('02269_data', 'RowBinary', 'x UInt8');