SQL: [tests] Fix select csv spec and enable it (#35239)
Also, replace `||` and `&&` with `OR` and `AND` as the former are not SQL standard operators.
This commit is contained in:
parent
c2766b65cf
commit
fd82813660
|
@ -29,6 +29,7 @@ public abstract class CsvSpecTestCase extends SpecBaseIntegrationTestCase {
|
||||||
public static List<Object[]> readScriptSpec() throws Exception {
|
public static List<Object[]> readScriptSpec() throws Exception {
|
||||||
Parser parser = specParser();
|
Parser parser = specParser();
|
||||||
List<Object[]> tests = new ArrayList<>();
|
List<Object[]> tests = new ArrayList<>();
|
||||||
|
tests.addAll(readScriptSpec("/select.csv-spec", parser));
|
||||||
tests.addAll(readScriptSpec("/command.csv-spec", parser));
|
tests.addAll(readScriptSpec("/command.csv-spec", parser));
|
||||||
tests.addAll(readScriptSpec("/fulltext.csv-spec", parser));
|
tests.addAll(readScriptSpec("/fulltext.csv-spec", parser));
|
||||||
tests.addAll(readScriptSpec("/agg.csv-spec", parser));
|
tests.addAll(readScriptSpec("/agg.csv-spec", parser));
|
||||||
|
|
|
@ -2,101 +2,110 @@
|
||||||
inWithLiterals
|
inWithLiterals
|
||||||
SELECT 1 IN (1, 2, 3), 1 IN (2, 3);
|
SELECT 1 IN (1, 2, 3), 1 IN (2, 3);
|
||||||
|
|
||||||
1 IN (1, 2, 3) | 1 IN (2, 3)
|
1 IN (1, 2, 3):b | 1 IN (2, 3):b
|
||||||
-----------------+-------------
|
-------------------+-------------
|
||||||
true |false
|
true |false
|
||||||
;
|
;
|
||||||
|
|
||||||
inWithLiteralsAndFunctions
|
inWithLiteralsAndFunctions
|
||||||
SELECT 1 IN (2 - 1, 2, 3), abs(-1) IN (2, 3, abs(4 - 5));
|
SELECT 1 IN (2 - 1, 2, 3), abs(-1) IN (2, 3, abs(4 - 5));
|
||||||
|
|
||||||
1 IN (1, 2, 3) | 1 IN (2, 3)
|
1 IN (2 - 1, 2, 3) | ABS(-1) IN (2, 3, ABS(4 - 5))
|
||||||
-----------------+-------------
|
---------------------+------------------------------
|
||||||
true |false
|
true |true
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
inWithLiteralsAndNegation
|
inWithLiteralsAndNegation
|
||||||
SELECT NOT 1 IN (1, 1 + 1, 3), NOT 1 IN (2, 3);
|
SELECT 1 NOT IN (1, 1 + 1, 3), 1 NOT IN (2, 3);
|
||||||
|
|
||||||
1 IN (1, 2, 3) | 1 IN (2, 3)
|
NOT(1 IN (1, 1 + 1, 3)) | NOT(1 IN (2, 3))
|
||||||
-----------------+-------------
|
--------------------------+-----------------
|
||||||
false |true
|
false |true
|
||||||
;
|
;
|
||||||
|
|
||||||
|
// Need to CAST as STRING since for boolean types the jdbc CSV translates null -> false
|
||||||
inWithNullHandling
|
inWithNullHandling
|
||||||
SELECT 2 IN (1, null, 3), 3 IN (1, null, 3), null IN (1, null, 3), null IN (1, 2, 3);
|
SELECT CAST(2 IN (1, null, 3) AS STRING), CAST(3 IN (1, null, 3) AS STRING), CAST(null IN (1, null, 3) AS STRING), CAST(null IN (1, 2, 3) AS STRING);
|
||||||
|
|
||||||
2 IN (1, null, 3) | 3 IN (1, null, 3) | null IN (1, null, 3) | null IN (1, 2, 3)
|
CAST(2 IN (1, null, 3) AS VARCHAR):s | CAST(3 IN (1, null, 3) AS VARCHAR):s | CAST(null IN (1, null, 3) AS VARCHAR):s | CAST(null IN (1, 2, 3) AS VARCHAR):s
|
||||||
--------------------+--------------------+-----------------------+-------------------
|
---------------------------------------+--------------------------------------+------------------------------------------+--------------------------------------
|
||||||
null |true |null | null
|
null |true |null |null
|
||||||
;
|
;
|
||||||
|
|
||||||
inWithNullHandlingAndNegation
|
inWithNullHandlingAndNegation
|
||||||
SELECT NOT 2 IN (1, null, 3), NOT 3 IN (1, null, 3), NOT null IN (1, null, 3), NOT null IN (1, 2, 3);
|
SELECT CAST(NOT 2 IN (1, null, 3) AS STRING), CAST(3 NOT IN (1, null, 3) AS STRING), CAST(NOT null IN (1, null, 3) AS STRING), CAST(null NOT IN (1, 2, 3) AS STRING);
|
||||||
|
|
||||||
NOT 2 IN (1, null, 3) | NOT 3 IN (1, null, 3) | NOT null IN (1, null, 3) | null IN (1, 2, 3)
|
CAST(NOT(2 IN (1, null, 3)) AS VARCHAR):s | CAST(NOT(3 IN (1, null, 3)) AS VARCHAR):s | CAST(NOT(null IN (1, null, 3)) AS VARCHAR):s | CAST(NOT(null IN (1, 2, 3)) AS VARCHAR):s
|
||||||
------------------------+------------------------+---------------------------+--------------------
|
--------------------------------------------+--------------------------------------------+-----------------------------------------------+-------------------------------------------
|
||||||
null |false |null | null
|
null |false |null |null
|
||||||
;
|
;
|
||||||
|
|
||||||
//
|
//
|
||||||
// SELECT with IN and table columns
|
// SELECT with IN and table columns
|
||||||
//
|
//
|
||||||
inWithTableColumn
|
inWithTableColumn
|
||||||
SELECT emp_no IN (10000, 10001, 10002) FROM test_emp ORDER BY 1;
|
SELECT emp_no IN (10000, 10001, 10002) FROM test_emp WHERE emp_no BETWEEN 10001 AND 10004 ORDER BY emp_no;
|
||||||
|
|
||||||
emp_no
|
emp_no IN (10000, 10001, 10002):b
|
||||||
-------
|
----------------------------------
|
||||||
10001
|
true
|
||||||
10002
|
true
|
||||||
|
false
|
||||||
|
false
|
||||||
;
|
;
|
||||||
|
|
||||||
inWithTableColumnAndFunction
|
inWithTableColumnAndFunction
|
||||||
SELECT emp_no IN (10000, 10000 + 1, abs(-10000 - 2)) FROM test_emp;
|
SELECT emp_no IN (10000, 10000 + 1, abs(-10000 - 2)) FROM test_emp WHERE emp_no BETWEEN 10001 AND 10004 ORDER BY emp_no;
|
||||||
|
|
||||||
emp_no
|
emp_no IN (10000, 10000 + 1, ABS(-10000 - 2)):b
|
||||||
-------
|
------------------------------------------------
|
||||||
10001
|
true
|
||||||
10002
|
true
|
||||||
|
false
|
||||||
|
false
|
||||||
;
|
;
|
||||||
|
|
||||||
inWithTableColumnAndNegation
|
inWithTableColumnAndNegation
|
||||||
SELECT emp_no NOT IN (10000, 10000 + 1, 10002) FROM test_emp ORDER BY 1 LIMIT 3;
|
SELECT emp_no NOT IN (10000, 10000 + 1, 10002) FROM test_emp WHERE emp_no BETWEEN 10001 AND 10004 ORDER BY emp_no;
|
||||||
|
|
||||||
emp_no
|
NOT(emp_no IN (10000, 10000 + 1, 10002)):b
|
||||||
-------
|
-------------------------------------------
|
||||||
10003
|
false
|
||||||
10004
|
false
|
||||||
10005
|
true
|
||||||
|
true
|
||||||
;
|
;
|
||||||
|
|
||||||
inWithTableColumnAndComplexFunctions
|
inWithTableColumnAndComplexFunctions
|
||||||
SELECT 1 IN (1, abs(2 - 4), 3) OR emp_no NOT IN (10000, 10000 + 1, 10002) FROM test_emp ORDER BY 1 LIMIT 3;
|
SELECT emp_no IN (1, abs(1 - 10002), 3) OR emp_no NOT IN (10000, 10000 + 2, 10003) FROM test_emp WHERE emp_no BETWEEN 10001 AND 10004 ORDER BY emp_no;
|
||||||
|
|
||||||
emp_no
|
(emp_no IN (1, ABS(1 - 10002), 3)) OR (NOT(emp_no IN (10000, 10000 + 2, 10003))):b
|
||||||
-------
|
----------------------------------------------------------------------------------
|
||||||
10003
|
true
|
||||||
10004
|
false
|
||||||
10005
|
false
|
||||||
|
true
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
|
// Need to CAST as STRING since for boolean types the jdbc CSV translates null -> false
|
||||||
inWithTableColumnAndNullHandling
|
inWithTableColumnAndNullHandling
|
||||||
SELECT emp_no, birth_date in (CAST('2018-10-01T00:00:00Z' AS TIMESTAMP), CAST('1959-10-01T00:00:00Z' AS TIMESTAMP)), birth_date in (CAST('2018-10-01T00:00:00Z' AS TIMESTAMP), null, CAST('1959-10-01T00:00:00Z' AS TIMESTAMP)) FROM test_emp WHERE emp_no = 10038 OR emp_no = 10039 OR emp_no = 10040 ORDER BY 1;
|
SELECT emp_no, CAST(languages IN (2, 3) AS STRING), CAST(languages IN (2, null, 3) AS STRING) FROM test_emp WHERE emp_no BETWEEN 10018 AND 10020 ORDER BY emp_no;
|
||||||
|
|
||||||
emp_no | birth_date in (CAST('2018-10-01T00:00:00Z' AS TIMESTAMP), CAST('1959-10-01T00:00:00Z' AS TIMESTAMP)) | birth_date in (CAST('2018-10-01T00:00:00Z' AS TIMESTAMP), null, CAST('1959-10-01T00:00:00Z' AS TIMESTAMP))
|
|
||||||
--------+-------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------
|
|
||||||
10038 | true | true
|
|
||||||
10039 | null | null
|
|
||||||
10040 | false | null
|
|
||||||
|
|
||||||
|
emp_no:i | CAST(languages IN (2, 3) AS VARCHAR):s | CAST(languages IN (2, null, 3) AS VARCHAR):s
|
||||||
|
----------+-----------------------------------------+----------------------------------------------
|
||||||
|
10018 |true |true
|
||||||
|
10019 |false |null
|
||||||
|
10020 |null |null
|
||||||
|
;
|
||||||
|
|
||||||
inWithTableColumnAndNullHandlingAndNegation
|
inWithTableColumnAndNullHandlingAndNegation
|
||||||
SELECT emp_no, NOT birth_date in (CAST('2018-10-01T00:00:00Z' AS TIMESTAMP), CAST('1959-10-01T00:00:00Z' AS TIMESTAMP)), NOT birth_date in (CAST('2018-10-01T00:00:00Z' AS TIMESTAMP), null, CAST('1959-10-01T00:00:00Z' AS TIMESTAMP)) FROM test_emp WHERE emp_no = 10038 OR emp_no = 10039 OR emp_no = 10040 ORDER BY 1;
|
SELECT emp_no, CAST(languages NOT IN (2, 3) AS STRING), CAST(NOT languages IN (2, null, 3) AS STRING) FROM test_emp WHERE emp_no BETWEEN 10018 AND 10020 ORDER BY emp_no;
|
||||||
|
|
||||||
emp_no | NOT birth_date in (CAST('2018-10-01T00:00:00Z' AS TIMESTAMP), CAST('1959-10-01T00:00:00Z' AS TIMESTAMP)) | NOT birth_date in (CAST('2018-10-01T00:00:00Z' AS TIMESTAMP), null, CAST('1959-10-01T00:00:00Z' AS TIMESTAMP))
|
emp_no:i | CAST(NOT(languages IN (2, 3)) AS VARCHAR):s | CAST(NOT(languages IN (2, null, 3)) AS VARCHAR):s
|
||||||
--------+-----------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------
|
----------+----------------------------------------------+---------------------------------------------------
|
||||||
10038 | false | false
|
10018 |false |false
|
||||||
10039 | null | null
|
10019 |true |null
|
||||||
10040 | true | null
|
10020 |null |null
|
||||||
|
;
|
||||||
|
|
|
@ -27,7 +27,7 @@ public class BinaryLogicProcessor extends FunctionalBinaryProcessor<Boolean, Boo
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return Boolean.logicalAnd(l.booleanValue(), r.booleanValue());
|
return Boolean.logicalAnd(l.booleanValue(), r.booleanValue());
|
||||||
}, "&&"),
|
}, "AND"),
|
||||||
OR((l, r) -> {
|
OR((l, r) -> {
|
||||||
if (Boolean.TRUE.equals(l) || Boolean.TRUE.equals(r)) {
|
if (Boolean.TRUE.equals(l) || Boolean.TRUE.equals(r)) {
|
||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
|
@ -36,7 +36,7 @@ public class BinaryLogicProcessor extends FunctionalBinaryProcessor<Boolean, Boo
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return Boolean.logicalOr(l.booleanValue(), r.booleanValue());
|
return Boolean.logicalOr(l.booleanValue(), r.booleanValue());
|
||||||
}, "||");
|
}, "OR");
|
||||||
|
|
||||||
private final BiFunction<Boolean, Boolean, Boolean> process;
|
private final BiFunction<Boolean, Boolean, Boolean> process;
|
||||||
private final String symbol;
|
private final String symbol;
|
||||||
|
|
|
@ -90,7 +90,7 @@ public class In extends NamedExpression implements ScriptWeaver {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String name() {
|
public String name() {
|
||||||
StringJoiner sj = new StringJoiner(", ", " IN(", ")");
|
StringJoiner sj = new StringJoiner(", ", " IN (", ")");
|
||||||
list.forEach(e -> sj.add(Expressions.name(e)));
|
list.forEach(e -> sj.add(Expressions.name(e)));
|
||||||
return Expressions.name(value) + sj.toString();
|
return Expressions.name(value) + sj.toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -197,7 +197,7 @@ public class QueryTranslatorTests extends ESTestCase {
|
||||||
assertFalse(condition.foldable());
|
assertFalse(condition.foldable());
|
||||||
SqlIllegalArgumentException ex = expectThrows(SqlIllegalArgumentException.class, () -> QueryTranslator.toQuery(condition, false));
|
SqlIllegalArgumentException ex = expectThrows(SqlIllegalArgumentException.class, () -> QueryTranslator.toQuery(condition, false));
|
||||||
assertEquals("Line 1:52: Comparisons against variables are not (currently) supported; " +
|
assertEquals("Line 1:52: Comparisons against variables are not (currently) supported; " +
|
||||||
"offender [keyword] in [keyword IN(foo, bar, keyword)]", ex.getMessage());
|
"offender [keyword] in [keyword IN (foo, bar, keyword)]", ex.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testTranslateInExpression_WhereClause_Painless() {
|
public void testTranslateInExpression_WhereClause_Painless() {
|
||||||
|
|
Loading…
Reference in New Issue