mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-20 05:05:38 +00:00
fix + tests
This commit is contained in:
parent
765e83db64
commit
eee107fced
@ -332,8 +332,11 @@ void ASTFunction::formatImplWithoutAlias(const FormatSettings & settings, Format
|
|||||||
const auto * literal = arguments->children[0]->as<ASTLiteral>();
|
const auto * literal = arguments->children[0]->as<ASTLiteral>();
|
||||||
const auto * function = arguments->children[0]->as<ASTFunction>();
|
const auto * function = arguments->children[0]->as<ASTFunction>();
|
||||||
const auto * subquery = arguments->children[0]->as<ASTSubquery>();
|
const auto * subquery = arguments->children[0]->as<ASTSubquery>();
|
||||||
bool is_tuple = literal && literal->value.getType() == Field::Types::Tuple;
|
bool is_tuple = (literal && literal->value.getType() == Field::Types::Tuple)
|
||||||
bool is_array = literal && literal->value.getType() == Field::Types::Array;
|
|| (function && function->name == "tuple" && function->arguments && function->arguments->children.size() > 1);
|
||||||
|
bool is_array = (literal && literal->value.getType() == Field::Types::Array)
|
||||||
|
|| (function && function->name == "array");
|
||||||
|
|
||||||
/// Do not add parentheses for tuple and array literal, otherwise extra parens will be added `-((3, 7, 3), 1)` -> `-(((3, 7, 3), 1))`, `-[1]` -> `-([1])`
|
/// Do not add parentheses for tuple and array literal, otherwise extra parens will be added `-((3, 7, 3), 1)` -> `-(((3, 7, 3), 1))`, `-[1]` -> `-([1])`
|
||||||
bool literal_need_parens = literal && !is_tuple && !is_array;
|
bool literal_need_parens = literal && !is_tuple && !is_array;
|
||||||
|
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
--
|
||||||
|
0
|
||||||
|
SELECT NOT 1
|
||||||
|
SELECT NOT 1
|
||||||
|
--
|
||||||
|
SELECT not(1, 1, 1)
|
||||||
|
SELECT not(1, 1, 1)
|
||||||
|
--
|
||||||
|
SELECT NOT tuple(1)
|
||||||
|
SELECT NOT tuple(1)
|
||||||
|
SELECT NOT tuple(1)
|
||||||
|
--
|
||||||
|
SELECT NOT ((1, 1, 1))
|
||||||
|
SELECT NOT ((1, 1, 1))
|
||||||
|
SELECT NOT ((1, 1, 1))
|
||||||
|
SELECT NOT ((1, 1, 1))
|
||||||
|
--
|
||||||
|
SELECT NOT [1]
|
||||||
|
SELECT NOT [1]
|
||||||
|
SELECT NOT [1]
|
||||||
|
SELECT NOT [1]
|
||||||
|
SELECT NOT [1]
|
||||||
|
--
|
||||||
|
SELECT -[1]
|
||||||
|
SELECT -[1]
|
||||||
|
SELECT -[1]
|
||||||
|
SELECT -[1]
|
||||||
|
SELECT -[1]
|
||||||
|
--
|
||||||
|
(-1,-1,-1)
|
||||||
|
SELECT -(1, 1, 1)
|
||||||
|
SELECT -(1, 1, 1)
|
||||||
|
SELECT -(1, 1, 1)
|
||||||
|
SELECT -(1, 1, 1)
|
||||||
|
--
|
||||||
|
((-1,-1,-1))
|
||||||
|
SELECT -tuple((1, 1, 1))
|
||||||
|
SELECT -tuple((1, 1, 1))
|
@ -6,5 +6,56 @@ create table a (`value2` Enum8('Hello' = 1, equals(`Null`, 'World', 2), '!' = 3)
|
|||||||
create table a (x Int8) engine Memory;
|
create table a (x Int8) engine Memory;
|
||||||
create table b empty as a;
|
create table b empty as a;
|
||||||
|
|
||||||
|
SELECT '--';
|
||||||
|
SELECT NOT (1);
|
||||||
|
SELECT formatQuery('SELECT NOT 1');
|
||||||
|
SELECT formatQuery('SELECT NOT (1)');
|
||||||
|
|
||||||
|
SELECT '--';
|
||||||
|
SELECT NOT (1, 1, 1); -- { serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH }
|
||||||
|
SELECT formatQuery('SELECT NOT (1, 1, 1)');
|
||||||
|
SELECT formatQuery('SELECT not(1, 1, 1)');
|
||||||
|
|
||||||
|
SELECT '--';
|
||||||
|
SELECT NOT ((1,)); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT }
|
||||||
|
SELECT NOT tuple(1); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT }
|
||||||
|
SELECT formatQuery('SELECT NOT ((1,))');
|
||||||
|
SELECT formatQuery('SELECT NOT (tuple(1))');
|
||||||
|
SELECT formatQuery('SELECT NOT tuple(1)');
|
||||||
|
|
||||||
|
SELECT '--';
|
||||||
SELECT NOT ((1, 1, 1)); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT }
|
SELECT NOT ((1, 1, 1)); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT }
|
||||||
|
SELECT formatQuery('SELECT NOT ((1, 1, 1))');
|
||||||
|
SELECT formatQuery('SELECT not((1, 1, 1))');
|
||||||
|
SELECT formatQuery('SELECT not tuple(1, 1, 1)');
|
||||||
|
SELECT formatQuery('SELECT not (tuple(1, 1, 1))');
|
||||||
|
|
||||||
|
SELECT '--';
|
||||||
|
SELECT NOT [1]; -- { serverError ILLEGAL_TYPE_OF_ARGUMENT }
|
||||||
|
SELECT NOT [(1)]; -- { serverError ILLEGAL_TYPE_OF_ARGUMENT }
|
||||||
|
SELECT formatQuery('SELECT NOT [1]');
|
||||||
|
SELECT formatQuery('SELECT NOT array(1)');
|
||||||
|
SELECT formatQuery('SELECT NOT (array(1))');
|
||||||
|
SELECT formatQuery('SELECT NOT [(1)]');
|
||||||
|
SELECT formatQuery('SELECT NOT ([1])');
|
||||||
|
|
||||||
|
SELECT '--';
|
||||||
|
SELECT -[1]; -- { serverError ILLEGAL_TYPE_OF_ARGUMENT }
|
||||||
SELECT -[(1)]; -- { serverError ILLEGAL_TYPE_OF_ARGUMENT }
|
SELECT -[(1)]; -- { serverError ILLEGAL_TYPE_OF_ARGUMENT }
|
||||||
|
SELECT formatQuery('SELECT -[1]');
|
||||||
|
SELECT formatQuery('SELECT -array(1)');
|
||||||
|
SELECT formatQuery('SELECT -(array(1))');
|
||||||
|
SELECT formatQuery('SELECT -[(1)]');
|
||||||
|
SELECT formatQuery('SELECT -([1])');
|
||||||
|
|
||||||
|
SELECT '--';
|
||||||
|
SELECT -(1, 1, 1);
|
||||||
|
SELECT formatQuery('SELECT -(1, 1, 1)');
|
||||||
|
SELECT formatQuery('SELECT negate ((1, 1, 1))');
|
||||||
|
SELECT formatQuery('SELECT -tuple(1, 1, 1)');
|
||||||
|
SELECT formatQuery('SELECT -(tuple(1, 1, 1))');
|
||||||
|
|
||||||
|
SELECT '--';
|
||||||
|
SELECT -tuple((1, 1, 1));
|
||||||
|
SELECT formatQuery('SELECT -((1, 1, 1))');
|
||||||
|
SELECT formatQuery('SELECT -tuple((1, 1, 1))');
|
||||||
|
Loading…
Reference in New Issue
Block a user