Merge pull request #2004 from yandex/CLICKHOUSE-3616

Prohibited non-UInt8 constants in WHERE
This commit is contained in:
alexey-milovidov 2018-03-07 22:07:24 +03:00 committed by GitHub
commit 2daf6be96c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 2 deletions

View File

@ -25,7 +25,20 @@ ConstantFilterDescription::ConstantFilterDescription(const IColumn & column)
if (column.isColumnConst())
{
if (static_cast<const ColumnConst &>(column).getValue<UInt8>())
const ColumnConst & column_const = static_cast<const ColumnConst &>(column);
const IColumn & column_nested = column_const.getDataColumn();
if (!typeid_cast<const ColumnUInt8 *>(&column_nested))
{
const ColumnNullable * column_nested_nullable = typeid_cast<const ColumnNullable *>(&column_nested);
if (!column_nested_nullable || !typeid_cast<const ColumnUInt8 *>(&column_nested_nullable->getNestedColumn()))
{
throw Exception("Illegal type " + column_nested.getName() + " of column for constant filter. Must be UInt8 or Nullable(UInt8).",
ErrorCodes::ILLEGAL_TYPE_OF_COLUMN_FOR_FILTER);
}
}
if (column_const.getValue<UInt64>())
always_true = true;
else
always_false = true;

View File

@ -25,7 +25,7 @@ function pack_unpack_compare()
${CLICKHOUSE_CLIENT} --query "DROP TABLE IF EXISTS test.buf"
${CLICKHOUSE_CLIENT} --query "DROP TABLE IF EXISTS test.buf_file"
rm -f "${CLICKHOUSE_TMP}/$buf_file" stderr
rm -f "$buf_file" stderr
echo $((res_orig - res_db_file)) $((res_orig - res_ch_local1)) $((res_orig - res_ch_local2))
}

View File

@ -1 +1,4 @@
0000-00-00 00:00:00
0
0

View File

@ -10,3 +10,15 @@ $CLICKHOUSE_CLIENT --query="SELECT CAST(0 AS Tuple)" 2>/dev/null || true;
$CLICKHOUSE_CLIENT --query="SELECT CAST(0 AS FixedString)" 2>/dev/null || true;
$CLICKHOUSE_CLIENT --query="SELECT CAST(0 AS Enum)" 2>/dev/null || true;
$CLICKHOUSE_CLIENT --query="SELECT CAST(0 AS DateTime)";
echo
($CLICKHOUSE_CLIENT --query="SELECT * FROM system.one WHERE toString(dummy)" 2>/dev/null && echo "Expected failure") || true;
($CLICKHOUSE_CLIENT --query="SELECT * FROM system.one WHERE toString(1)" 2>/dev/null && echo "Expected failure") || true;
($CLICKHOUSE_CLIENT --query="SELECT * FROM system.one WHERE 256" 2>/dev/null && echo "Expected failure") || true;
($CLICKHOUSE_CLIENT --query="SELECT * FROM system.one WHERE -1" 2>/dev/null && echo "Expected failure") || true;
($CLICKHOUSE_CLIENT --query="SELECT * FROM system.one WHERE CAST(256 AS Nullable(UInt16))" 2>/dev/null && echo "Expected failure") || true;
$CLICKHOUSE_CLIENT --query="SELECT * FROM system.one WHERE CAST(NULL AS Nullable(UInt8))"
$CLICKHOUSE_CLIENT --query="SELECT * FROM system.one WHERE 255"
$CLICKHOUSE_CLIENT --query="SELECT * FROM system.one WHERE CAST(255 AS Nullable(UInt8))"