Skip to content

Commit

Permalink
Merge pull request #62121 from ClickHouse/cherrypick/24.3/f31f338ad0b…
Browse files Browse the repository at this point in the history
…4710804b64d816ee1b97234ec2f01

Cherry pick #62115 to 24.3: Fix external table cannot parse data type Bool
  • Loading branch information
robot-clickhouse committed Mar 31, 2024
2 parents 7f6234d + f31f338 commit 9b5d72f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Core/ExternalTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ void BaseExternalTable::parseStructureFromStructureField(const std::string & arg
for (auto & child : columns_list_raw->children)
{
auto * column = child->as<ASTNameTypePair>();
/// We use `formatWithPossiblyHidingSensitiveData` instead of `getColumnNameWithoutAlias` because `column->type` is an ASTFunction.
/// `getColumnNameWithoutAlias` will return name of the function with `(arguments)` even if arguments is empty.
if (column)
structure.emplace_back(column->name, column->type->getColumnNameWithoutAlias());
structure.emplace_back(column->name, column->type->formatWithPossiblyHidingSensitiveData(0, true, true));
else
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Error while parsing table structure: expected column definition, got {}", child->formatForErrorMessage());
}
Expand All @@ -99,7 +101,7 @@ void BaseExternalTable::parseStructureFromTypesField(const std::string & argumen
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Error while parsing table structure: {}", error);

for (size_t i = 0; i < type_list_raw->children.size(); ++i)
structure.emplace_back("_" + toString(i + 1), type_list_raw->children[i]->getColumnNameWithoutAlias());
structure.emplace_back("_" + toString(i + 1), type_list_raw->children[i]->formatWithPossiblyHidingSensitiveData(0, true, true));
}

void BaseExternalTable::initSampleBlock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ foo 1
bar 2
foo 1
bar 2
true
true
true
[1]
('foo',1)
(1,1)
10 changes: 10 additions & 0 deletions tests/queries/0_stateless/02935_external_table_enum_type.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,13 @@ curl -s "${http_url}temp_structure=x+Enum8('foo'%3D1,'bar'%3D2),y+Int" -F "$(pri
curl -s "${http_url}temp_types=Enum8('foo'%3D1,'bar'%3D2),Int" -F "$(printf 'temp='"bar"'\t2');filename=data1" -F "query=SELECT * FROM temp"
echo -ne 'foo\t1' | ${CLICKHOUSE_CLIENT} --query="select * from tmp" --external --file=- --name=tmp --structure="x Enum8('foo'=1,'bar'=2),y Int"
echo -ne 'bar\t2' | ${CLICKHOUSE_CLIENT} --query="select * from tmp" --external --file=- --name=tmp --types="Enum8('foo'=1,'bar'=2),Int"

# https://github.com/ClickHouse/ClickHouse/issues/62108
echo -ne 'true' | ${CLICKHOUSE_CLIENT} --query="select * from tmp" --external --file=- --name=tmp --structure="x Bool"
echo -ne 'true' | ${CLICKHOUSE_CLIENT} --query="select * from tmp" --external --file=- --name=tmp --types="Bool"

# Test for some complex and custome types
echo -ne 'true' | ${CLICKHOUSE_CLIENT} --query="select * from tmp" --external --file=- --name=tmp --structure="x Nullable(FixedString(4))"
echo -ne '[1]' | ${CLICKHOUSE_CLIENT} --query="select * from tmp" --external --file=- --name=tmp --structure="x Array(UInt8)"
echo -ne '('"'"'foo'"'"',1)' | ${CLICKHOUSE_CLIENT} --query="select * from tmp" --external --file=- --name=tmp --structure="x Tuple(String, UInt8)"
echo -ne '(1,1)' | ${CLICKHOUSE_CLIENT} --query="select * from tmp" --external --file=- --name=tmp --structure="x Point"

0 comments on commit 9b5d72f

Please sign in to comment.