Skip to content

Commit

Permalink
More clear statement on binary comparison expressions. Add some test …
Browse files Browse the repository at this point in the history
…cases.
  • Loading branch information
viirya committed Aug 9, 2017
1 parent 9895843 commit 1369fd5
Show file tree
Hide file tree
Showing 3 changed files with 311 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -504,12 +504,14 @@ object Equality {
usage = "expr1 _FUNC_ expr2 - Returns true if `expr1` equals `expr2`, or false otherwise.",
arguments = """
Arguments:
* expr1, expr2 - the two expressions must be same type.
* expr1, expr2 - the two expressions must be same type or can be casted to a common type.
""",
examples = """
Examples:
> SELECT 2 _FUNC_ 2;
true
> SELECT 1 _FUNC_ '1';
true
> SELECT true _FUNC_ NULL;
NULL
> SELECT NULL _FUNC_ NULL;
Expand Down Expand Up @@ -551,12 +553,14 @@ case class EqualTo(left: Expression, right: Expression)
""",
arguments = """
Arguments:
* expr1, expr2 - the two expressions must be same type.
* expr1, expr2 - the two expressions must be same type or can be casted to a common type.
""",
examples = """
Examples:
> SELECT 2 _FUNC_ 2;
true
> SELECT 1 _FUNC_ '1';
true
> SELECT true _FUNC_ NULL;
false
> SELECT NULL _FUNC_ NULL;
Expand Down Expand Up @@ -612,12 +616,14 @@ case class EqualNullSafe(left: Expression, right: Expression) extends BinaryComp
usage = "expr1 _FUNC_ expr2 - Returns true if `expr1` is less than `expr2`.",
arguments = """
Arguments:
* expr1, expr2 - the two expressions must be same type which must be a type that can be ordered/compared.
* expr1, expr2 - the two expressions must be same type or can be casted to a common type, and must be a type that can be ordered/compared.
""",
examples = """
Examples:
> SELECT 1 _FUNC_ 2;
true
> SELECT 1.1 _FUNC_ '1';
false
> SELECT to_date('2009-07-30 04:17:52') _FUNC_ to_date('2009-07-30 04:17:52');
false
> SELECT to_date('2009-07-30 04:17:52') _FUNC_ to_date('2009-08-01 04:17:52');
Expand All @@ -641,12 +647,14 @@ case class LessThan(left: Expression, right: Expression)
usage = "expr1 _FUNC_ expr2 - Returns true if `expr1` is less than or equal to `expr2`.",
arguments = """
Arguments:
* expr1, expr2 - the two expressions must be same type which must be a type that can be ordered/compared.
* expr1, expr2 - the two expressions must be same type or can be casted to a common type, and must be a type that can be ordered/compared.
""",
examples = """
Examples:
> SELECT 2 _FUNC_ 2;
true
> SELECT 1.0 _FUNC_ '1';
true
> SELECT to_date('2009-07-30 04:17:52') _FUNC_ to_date('2009-07-30 04:17:52');
true
> SELECT to_date('2009-07-30 04:17:52') _FUNC_ to_date('2009-08-01 04:17:52');
Expand All @@ -670,12 +678,14 @@ case class LessThanOrEqual(left: Expression, right: Expression)
usage = "expr1 _FUNC_ expr2 - Returns true if `expr1` is greater than `expr2`.",
arguments = """
Arguments:
* expr1, expr2 - the two expressions must be same type which must be a type that can be ordered/compared.
* expr1, expr2 - the two expressions must be same type or can be casted to a common type, and must be a type that can be ordered/compared.
""",
examples = """
Examples:
> SELECT 2 _FUNC_ 1;
true
> SELECT 2 _FUNC_ '1.1';
true
> SELECT to_date('2009-07-30 04:17:52') _FUNC_ to_date('2009-07-30 04:17:52');
false
> SELECT to_date('2009-07-30 04:17:52') _FUNC_ to_date('2009-08-01 04:17:52');
Expand All @@ -696,15 +706,17 @@ case class GreaterThan(left: Expression, right: Expression)

// scalastyle:off line.size.limit
@ExpressionDescription(
usage = "expr1 _FUNC_ expr2 - Returns true if `expr1` is greater than `expr2`.",
usage = "expr1 _FUNC_ expr2 - Returns true if `expr1` is greater than or equal to `expr2`.",
arguments = """
Arguments:
* expr1, expr2 - the two expressions must be same type which must be a type that can be ordered/compared.
* expr1, expr2 - the two expressions must be same type or can be casted to a common type, and must be a type that can be ordered/compared.
""",
examples = """
Examples:
> SELECT 2 _FUNC_ 1;
true
> SELECT 2.0 _FUNC_ '2.1';
false
> SELECT to_date('2009-07-30 04:17:52') _FUNC_ to_date('2009-07-30 04:17:52');
true
> SELECT to_date('2009-07-30 04:17:52') _FUNC_ to_date('2009-08-01 04:17:52');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
-- In
select 1 in(1, 2, 3);
select 1 in(2, 3, 4);
select named_struct('a', 1, 'b', 2) in(named_struct('a', 1, 'b', 1), named_struct('a', 1, 'b', 3));
select named_struct('a', 1, 'b', 2) in(named_struct('a', 1, 'b', 2), named_struct('a', 1, 'b', 3));

-- EqualTo
select 1 = 1;
select 1 = '1';
select 1.0 = '1';

-- GreaterThan
select 1 > '1';
select 2 > '1.0';
select 2 > '2.0';
select 2 > '2.2';
select to_date('2009-07-30 04:17:52') > to_date('2009-07-30 04:17:52');
select to_date('2009-07-30 04:17:52') > '2009-07-30 04:17:52';

-- GreaterThanOrEqual
select 1 >= '1';
select 2 >= '1.0';
select 2 >= '2.0';
select 2.0 >= '2.2';
select to_date('2009-07-30 04:17:52') >= to_date('2009-07-30 04:17:52');
select to_date('2009-07-30 04:17:52') >= '2009-07-30 04:17:52';

-- LessThan
select 1 < '1';
select 2 < '1.0';
select 2 < '2.0';
select 2.0 < '2.2';
select to_date('2009-07-30 04:17:52') < to_date('2009-07-30 04:17:52');
select to_date('2009-07-30 04:17:52') < '2009-07-30 04:17:52';

-- LessThanOrEqual
select 1 <= '1';
select 2 <= '1.0';
select 2 <= '2.0';
select 2.0 <= '2.2';
select to_date('2009-07-30 04:17:52') <= to_date('2009-07-30 04:17:52');
select to_date('2009-07-30 04:17:52') <= '2009-07-30 04:17:52';
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
-- Automatically generated by SQLQueryTestSuite
-- Number of queries: 31


-- !query 0
select 1 in(1, 2, 3)
-- !query 0 schema
struct<(1 IN (1, 2, 3)):boolean>
-- !query 0 output
true


-- !query 1
select 1 in(2, 3, 4)
-- !query 1 schema
struct<(1 IN (2, 3, 4)):boolean>
-- !query 1 output
false


-- !query 2
select named_struct('a', 1, 'b', 2) in(named_struct('a', 1, 'b', 1), named_struct('a', 1, 'b', 3))
-- !query 2 schema
struct<(named_struct(a, 1, b, 2) IN (named_struct(a, 1, b, 1), named_struct(a, 1, b, 3))):boolean>
-- !query 2 output
false


-- !query 3
select named_struct('a', 1, 'b', 2) in(named_struct('a', 1, 'b', 2), named_struct('a', 1, 'b', 3))
-- !query 3 schema
struct<(named_struct(a, 1, b, 2) IN (named_struct(a, 1, b, 2), named_struct(a, 1, b, 3))):boolean>
-- !query 3 output
true


-- !query 4
select 1 = 1
-- !query 4 schema
struct<(1 = 1):boolean>
-- !query 4 output
true


-- !query 5
select 1 = '1'
-- !query 5 schema
struct<(1 = CAST(1 AS INT)):boolean>
-- !query 5 output
true


-- !query 6
select 1.0 = '1'
-- !query 6 schema
struct<(1.0 = CAST(1 AS DECIMAL(2,1))):boolean>
-- !query 6 output
true


-- !query 7
select 1 > '1'
-- !query 7 schema
struct<(1 > CAST(1 AS INT)):boolean>
-- !query 7 output
false


-- !query 8
select 2 > '1.0'
-- !query 8 schema
struct<(2 > CAST(1.0 AS INT)):boolean>
-- !query 8 output
true


-- !query 9
select 2 > '2.0'
-- !query 9 schema
struct<(2 > CAST(2.0 AS INT)):boolean>
-- !query 9 output
false


-- !query 10
select 2 > '2.2'
-- !query 10 schema
struct<(2 > CAST(2.2 AS INT)):boolean>
-- !query 10 output
false


-- !query 11
select to_date('2009-07-30 04:17:52') > to_date('2009-07-30 04:17:52')
-- !query 11 schema
struct<(to_date('2009-07-30 04:17:52') > to_date('2009-07-30 04:17:52')):boolean>
-- !query 11 output
false


-- !query 12
select to_date('2009-07-30 04:17:52') > '2009-07-30 04:17:52'
-- !query 12 schema
struct<(CAST(to_date('2009-07-30 04:17:52') AS STRING) > 2009-07-30 04:17:52):boolean>
-- !query 12 output
false


-- !query 13
select 1 >= '1'
-- !query 13 schema
struct<(1 >= CAST(1 AS INT)):boolean>
-- !query 13 output
true


-- !query 14
select 2 >= '1.0'
-- !query 14 schema
struct<(2 >= CAST(1.0 AS INT)):boolean>
-- !query 14 output
true


-- !query 15
select 2 >= '2.0'
-- !query 15 schema
struct<(2 >= CAST(2.0 AS INT)):boolean>
-- !query 15 output
true


-- !query 16
select 2.0 >= '2.2'
-- !query 16 schema
struct<(2.0 >= CAST(2.2 AS DECIMAL(2,1))):boolean>
-- !query 16 output
false


-- !query 17
select to_date('2009-07-30 04:17:52') >= to_date('2009-07-30 04:17:52')
-- !query 17 schema
struct<(to_date('2009-07-30 04:17:52') >= to_date('2009-07-30 04:17:52')):boolean>
-- !query 17 output
true


-- !query 18
select to_date('2009-07-30 04:17:52') >= '2009-07-30 04:17:52'
-- !query 18 schema
struct<(CAST(to_date('2009-07-30 04:17:52') AS STRING) >= 2009-07-30 04:17:52):boolean>
-- !query 18 output
false


-- !query 19
select 1 < '1'
-- !query 19 schema
struct<(1 < CAST(1 AS INT)):boolean>
-- !query 19 output
false


-- !query 20
select 2 < '1.0'
-- !query 20 schema
struct<(2 < CAST(1.0 AS INT)):boolean>
-- !query 20 output
false


-- !query 21
select 2 < '2.0'
-- !query 21 schema
struct<(2 < CAST(2.0 AS INT)):boolean>
-- !query 21 output
false


-- !query 22
select 2.0 < '2.2'
-- !query 22 schema
struct<(2.0 < CAST(2.2 AS DECIMAL(2,1))):boolean>
-- !query 22 output
true


-- !query 23
select to_date('2009-07-30 04:17:52') < to_date('2009-07-30 04:17:52')
-- !query 23 schema
struct<(to_date('2009-07-30 04:17:52') < to_date('2009-07-30 04:17:52')):boolean>
-- !query 23 output
false


-- !query 24
select to_date('2009-07-30 04:17:52') < '2009-07-30 04:17:52'
-- !query 24 schema
struct<(CAST(to_date('2009-07-30 04:17:52') AS STRING) < 2009-07-30 04:17:52):boolean>
-- !query 24 output
true


-- !query 25
select 1 <= '1'
-- !query 25 schema
struct<(1 <= CAST(1 AS INT)):boolean>
-- !query 25 output
true


-- !query 26
select 2 <= '1.0'
-- !query 26 schema
struct<(2 <= CAST(1.0 AS INT)):boolean>
-- !query 26 output
false


-- !query 27
select 2 <= '2.0'
-- !query 27 schema
struct<(2 <= CAST(2.0 AS INT)):boolean>
-- !query 27 output
true


-- !query 28
select 2.0 <= '2.2'
-- !query 28 schema
struct<(2.0 <= CAST(2.2 AS DECIMAL(2,1))):boolean>
-- !query 28 output
true


-- !query 29
select to_date('2009-07-30 04:17:52') <= to_date('2009-07-30 04:17:52')
-- !query 29 schema
struct<(to_date('2009-07-30 04:17:52') <= to_date('2009-07-30 04:17:52')):boolean>
-- !query 29 output
true


-- !query 30
select to_date('2009-07-30 04:17:52') <= '2009-07-30 04:17:52'
-- !query 30 schema
struct<(CAST(to_date('2009-07-30 04:17:52') AS STRING) <= 2009-07-30 04:17:52):boolean>
-- !query 30 output
true

0 comments on commit 1369fd5

Please sign in to comment.