15 package com.cloudera.impala.analysis;
17 import static org.junit.Assert.assertEquals;
18 import static org.junit.Assert.assertNotNull;
19 import static org.junit.Assert.assertTrue;
21 import java.math.BigInteger;
22 import java.util.ArrayList;
23 import java.util.List;
25 import junit.framework.Assert;
39 import com.cloudera.impala.thrift.TExpr;
40 import com.cloudera.impala.thrift.TQueryOptions;
41 import com.google.common.base.Joiner;
42 import com.google.common.base.Preconditions;
43 import com.google.common.base.Predicates;
44 import com.google.common.collect.Lists;
72 ScalarType.createDecimalType(20, 0));
74 ScalarType.createDecimalType(20, 0));
76 BigInteger minMinusOne = BigInteger.valueOf(Long.MIN_VALUE);
77 minMinusOne = minMinusOne.subtract(BigInteger.ONE);
80 BigInteger maxPlusOne = BigInteger.valueOf(Long.MAX_VALUE);
81 maxPlusOne = maxPlusOne.add(BigInteger.ONE);
94 AnalysisError(String.format(
"select %s1", Double.toString(Double.MAX_VALUE)),
95 "Numeric literal '1.7976931348623157E+3081' exceeds maximum range of doubles.");
96 AnalysisError(String.format(
"select %s1", Double.toString(Double.MIN_VALUE)),
97 "Numeric literal '4.9E-3241' underflows minimum resolution of doubles.");
119 Type actualType = selectStmt.resultExprs_.get(0).getType();
120 Assert.assertTrue(
"Expected Type: " + expectedType +
" Actual type: " + actualType,
121 expectedType.equals(actualType));
128 AnalyzesOk(
"select cast ('1970-10-10 10:00:00.123' as timestamp)");
134 AnalyzesOk(
"select * from functional.AllTypes where true");
135 AnalyzesOk(
"select * from functional.AllTypes where false");
136 AnalyzesOk(
"select * from functional.AllTypes where NULL");
137 AnalyzesOk(
"select * from functional.AllTypes where bool_col = true");
138 AnalyzesOk(
"select * from functional.AllTypes where bool_col = false");
139 AnalyzesOk(
"select * from functional.AllTypes where bool_col = NULL");
140 AnalyzesOk(
"select * from functional.AllTypes where NULL = NULL");
141 AnalyzesOk(
"select * from functional.AllTypes where NULL and NULL or NULL");
142 AnalyzesOk(
"select * from functional.AllTypes where true or false");
143 AnalyzesOk(
"select * from functional.AllTypes where true and false");
144 AnalyzesOk(
"select * from functional.AllTypes " +
145 "where true or false and bool_col = false");
146 AnalyzesOk(
"select * from functional.AllTypes " +
147 "where true and false or bool_col = false");
149 AnalyzesOk(
"select bool_col = true from functional.AllTypes");
150 AnalyzesOk(
"select bool_col = false from functional.AllTypes");
151 AnalyzesOk(
"select bool_col = NULL from functional.AllTypes");
152 AnalyzesOk(
"select true or false and bool_col = false from functional.AllTypes");
153 AnalyzesOk(
"select true and false or bool_col = false from functional.AllTypes");
154 AnalyzesOk(
"select NULL or NULL and NULL from functional.AllTypes");
159 AnalyzesOk(
"select * from functional.alltypes where bool_col != true");
160 AnalyzesOk(
"select * from functional.alltypes where tinyint_col <> 1");
161 AnalyzesOk(
"select * from functional.alltypes where smallint_col <= 23");
162 AnalyzesOk(
"select * from functional.alltypes where int_col > 15");
163 AnalyzesOk(
"select * from functional.alltypes where bigint_col >= 17");
164 AnalyzesOk(
"select * from functional.alltypes where float_col < 15.0");
165 AnalyzesOk(
"select * from functional.alltypes where double_col > 7.7");
167 AnalyzesOk(
"select * from functional.alltypes where 1 = 0");
168 AnalyzesOk(
"select * from functional.alltypes where int_col = smallint_col");
169 AnalyzesOk(
"select * from functional.alltypes where bigint_col = float_col");
170 AnalyzesOk(
"select * from functional.alltypes where bool_col = 0");
171 AnalyzesOk(
"select * from functional.alltypes where int_col = cast('0' as int)");
172 AnalyzesOk(
"select * from functional.alltypes where cast(string_col as int) = 15");
174 AnalyzesOk(
"select * from functional.alltypes where bool_col != NULL");
175 AnalyzesOk(
"select * from functional.alltypes where tinyint_col <> NULL");
176 AnalyzesOk(
"select * from functional.alltypes where smallint_col <= NULL");
177 AnalyzesOk(
"select * from functional.alltypes where int_col > NULL");
178 AnalyzesOk(
"select * from functional.alltypes where bigint_col >= NULL");
179 AnalyzesOk(
"select * from functional.alltypes where float_col < NULL");
180 AnalyzesOk(
"select * from functional.alltypes where double_col > NULL");
181 AnalyzesOk(
"select * from functional.alltypes where string_col = NULL");
182 AnalyzesOk(
"select * from functional.alltypes where timestamp_col = NULL");
184 AnalyzesOk(
"select cast('hi' as CHAR(2)) = cast('hi' as CHAR(3))");
185 AnalyzesOk(
"select cast('hi' as CHAR(2)) = 'hi'");
188 AnalysisError(
"select * from functional.alltypes where bool_col = '15'",
189 "operands of type BOOLEAN and STRING are not comparable: bool_col = '15'");
191 AnalysisError(
"select 1 from functional.allcomplextypes where int_array_col = 1",
192 "operands of type ARRAY<INT> and TINYINT are not comparable: int_array_col = 1");
193 AnalysisError(
"select 1 from functional.allcomplextypes where int_map_col = 1",
194 "operands of type MAP<STRING,INT> and TINYINT are not comparable: " +
196 AnalysisError(
"select 1 from functional.allcomplextypes where int_struct_col = 1",
197 "operands of type STRUCT<f1:INT,f2:INT> and TINYINT are not comparable: " +
198 "int_struct_col = 1");
204 "where int_map_col = int_map_col",
205 "operands of type MAP<STRING,INT> and MAP<STRING,INT> are not comparable: " +
206 "int_map_col = int_map_col");
221 "Invalid type cast of TRUE from BOOLEAN to DECIMAL(9,0)");
222 AnalysisError(
"select cast(cast(1 as timestamp) as decimal)",
223 "Invalid type cast of CAST(1 AS TIMESTAMP) from TIMESTAMP to DECIMAL(9,0)");
226 if (type.isNull() || type.isDecimal() || type.isBoolean() || type.isDateType()
227 || type.getPrimitiveType() == PrimitiveType.VARCHAR
231 AnalyzesOk(
"select cast(1.1 as " + type +
")");
232 AnalyzesOk(
"select cast(cast(1 as " + type +
") as decimal)");
237 for (
int scale = 0; scale < precision; ++scale) {
238 Type t = ScalarType.createDecimalType(precision, scale);
245 "Decimal precision must be > 0: 0");
253 " as " + expectedType.
toSql() +
")");
254 Type actualType = selectStmt.resultExprs_.get(0).getType();
255 Assert.assertTrue(
"Expected Type: " + expectedType +
" Actual type: " + actualType,
256 expectedType.equals(actualType));
262 AnalysisError(
"select * from functional.alltypes where tinyint_col = '1'",
263 "operands of type TINYINT and STRING are not comparable: tinyint_col = '1'");
264 AnalysisError(
"select * from functional.alltypes where bool_col = '0'",
265 "operands of type BOOLEAN and STRING are not comparable: bool_col = '0'");
267 AnalysisError(
"select cast('false' as boolean) from functional.alltypes",
268 "Invalid type cast of 'false' from STRING to BOOLEAN");
270 AnalyzesOk(
"select * from functional.alltypes where " +
271 "tinyint_col = cast('0.5' as float)");
272 AnalyzesOk(
"select * from functional.alltypes where " +
273 "smallint_col = cast('0.5' as float)");
274 AnalyzesOk(
"select * from functional.alltypes where int_col = cast('0.5' as float)");
275 AnalyzesOk(
"select * from functional.alltypes where " +
276 "bigint_col = cast('0.5' as float)");
277 AnalyzesOk(
"select 1.0 = cast('" + Double.toString(Double.MIN_VALUE) +
279 AnalyzesOk(
"select 1.0 = cast('-" + Double.toString(Double.MIN_VALUE) +
281 AnalyzesOk(
"select 1.0 = cast('" + Double.toString(Double.MAX_VALUE) +
283 AnalyzesOk(
"select 1.0 = cast('-" + Double.toString(Double.MAX_VALUE) +
286 AnalyzesOk(
"select * from functional.alltypes where " +
287 "tinyint_col = cast('-1' as tinyint)");
288 AnalyzesOk(
"select * from functional.alltypes where " +
289 "tinyint_col = cast('- -1' as tinyint)");
290 AnalyzesOk(
"select * from functional.alltypes where " +
291 "tinyint_col = cast('- - -1' as tinyint)");
292 AnalyzesOk(
"select * from functional.alltypes where " +
293 "tinyint_col = cast('- - - -1' as tinyint)");
295 AnalyzesOk(
"select 1 | cast('" + Byte.toString(Byte.MIN_VALUE) +
"' as int)");
296 AnalyzesOk(
"select 1 | cast('" + Byte.toString(Byte.MAX_VALUE) +
"' as int)");
297 AnalyzesOk(
"select 1 | cast('" + Short.toString(Short.MIN_VALUE) +
"' as int)");
298 AnalyzesOk(
"select 1 | cast('" + Short.toString(Short.MAX_VALUE) +
"' as int)");
299 AnalyzesOk(
"select 1 | cast('" + Integer.toString(Integer.MIN_VALUE) +
"' as int)");
300 AnalyzesOk(
"select 1 | cast('" + Integer.toString(Integer.MAX_VALUE) +
"' as int)");
304 AnalyzesOk(
"select 1 | cast('" + Long.toString(Long.MIN_VALUE + 1) +
"' as bigint)");
305 AnalyzesOk(
"select 1 | cast('" + Long.toString(Long.MAX_VALUE) +
"' as bigint)");
307 AnalyzesOk(
"select * from functional.alltypes where tinyint_col = " +
308 "cast('" + Long.toString(Long.MIN_VALUE) +
"1' as tinyint)");
309 AnalyzesOk(
"select * from functional.alltypes where tinyint_col = " +
310 "cast('" + Long.toString(Long.MAX_VALUE) +
"1' as tinyint)");
311 AnalyzesOk(
"select * from functional.alltypes where tinyint_col = " +
312 "cast('" + Double.toString(Double.MAX_VALUE) +
"1' as tinyint)");
316 AnalyzesOk(
"select * from functional.alltypes where tinyint_col = " +
317 "cast('" + Double.toString(Double.MIN_VALUE) +
"1' as tinyint)");
319 AnalyzesOk(
"select * from functional.alltypes where " +
320 "tinyint_col = cast('--1' as tinyint)");
326 AnalyzesOk(
"select cast(cast('1.234' as decimal) as string)");
329 AnalyzesOk(
"select cast('helloworld' as VARCHAR(3))");
330 AnalyzesOk(
"select cast(cast('helloworld' as VARCHAR(3)) as string)");
331 AnalyzesOk(
"select cast(cast('3.0' as VARCHAR(5)) as float)");
332 AnalyzesOk(
"select NULL = cast('123' as CHAR(3))");
334 "operands of type TIMESTAMP and CHAR(3) are not comparable: " +
335 "now() = CAST('hi' AS CHAR(3))");
340 "Varchar size must be > 0: 0");
342 "Varchar size must be <= 65355: 65356");
344 "Char size must be > 0: 0");
346 "Char size must be <= 255: 256");
359 "(cast('abcde' as CHAR(20)), cast('abcde' as VARCHAR(10)), 'abcde')",
362 "(cast('abcde' as CHAR(20)), cast('abcde' as VARCHAR(10)), 'abcde')",
365 "(cast('abcde' as CHAR(20)), cast('abcde' as VARCHAR(10)), 'abcde')",
377 if (type.isNull())
continue;
380 type = ScalarType.createVarcharType(1);
383 type = ScalarType.createCharType(1);
395 "Unsupported cast to complex type: ARRAY<INT>");
397 "Unsupported cast to complex type: MAP<INT,INT>");
399 "Unsupported cast to complex type: STRUCT<a:INT,b:CHAR(20)>");
404 AnalyzesOk(
"select * from functional.alltypes where string_col like 'test%'");
405 AnalyzesOk(
"select * from functional.alltypes where string_col like string_col");
406 AnalyzesOk(
"select * from functional.alltypes where 'test' like string_col");
407 AnalyzesOk(
"select * from functional.alltypes where string_col rlike 'test%'");
408 AnalyzesOk(
"select * from functional.alltypes where string_col regexp 'test.*'");
409 AnalysisError(
"select * from functional.alltypes where string_col like 5",
410 "right operand of LIKE must be of type STRING");
411 AnalysisError(
"select * from functional.alltypes where 'test' like 5",
412 "right operand of LIKE must be of type STRING");
413 AnalysisError(
"select * from functional.alltypes where int_col like 'test%'",
414 "left operand of LIKE must be of type STRING");
415 AnalysisError(
"select * from functional.alltypes where string_col regexp 'test]['",
416 "invalid regular expression in 'string_col REGEXP 'test][''");
418 String[] likePreds =
new String[] {
"LIKE",
"RLIKE",
"REGEXP"};
419 for (String likePred: likePreds) {
420 AnalyzesOk(String.format(
"select * from functional.alltypes " +
421 "where string_col %s NULL", likePred));
422 AnalyzesOk(String.format(
"select * from functional.alltypes " +
423 "where NULL %s string_col", likePred));
424 AnalyzesOk(String.format(
"select * from functional.alltypes " +
425 "where NULL %s NULL", likePred));
431 AnalyzesOk(
"select * from functional.alltypes where " +
432 "string_col = '5' and int_col = 5");
433 AnalyzesOk(
"select * from functional.alltypes where " +
434 "string_col = '5' or int_col = 5");
435 AnalyzesOk(
"select * from functional.alltypes where (string_col = '5' " +
436 "or int_col = 5) and string_col > '1'");
437 AnalyzesOk(
"select * from functional.alltypes where not string_col = '5'");
438 AnalyzesOk(
"select * from functional.alltypes where int_col = cast('5' as int)");
441 String[] operands =
new String[]{
"true",
"false",
"NULL",
"bool_col" };
442 for (String lop: operands) {
443 for (String rop: operands) {
447 String expr = String.format(
"%s %s %s", lop, op, rop);
448 AnalyzesOk(String.format(
"select %s from functional.alltypes where %s",
452 String notExpr = String.format(
"%s %s", CompoundPredicate.Operator.NOT, lop);
453 AnalyzesOk(String.format(
"select %s from functional.alltypes where %s",
458 AnalysisError(
"select * from functional.alltypes where 1 + 2 and false",
459 "Operand '1 + 2' part of predicate '1 + 2 AND FALSE' should return " +
460 "type 'BOOLEAN' but returns type 'SMALLINT'.");
461 AnalysisError(
"select * from functional.alltypes where 1 + 2 or true",
462 "Operand '1 + 2' part of predicate '1 + 2 OR TRUE' should return " +
463 "type 'BOOLEAN' but returns type 'SMALLINT'.");
464 AnalysisError(
"select * from functional.alltypes where not 1 + 2",
465 "Operand '1 + 2' part of predicate 'NOT 1 + 2' should return " +
466 "type 'BOOLEAN' but returns type 'SMALLINT'.");
467 AnalysisError(
"select * from functional.alltypes where 1 + 2 and true",
468 "Operand '1 + 2' part of predicate '1 + 2 AND TRUE' should return " +
469 "type 'BOOLEAN' but returns type 'SMALLINT'.");
470 AnalysisError(
"select * from functional.alltypes where false and trim('abc')",
471 "Operand 'trim('abc')' part of predicate 'FALSE AND trim('abc')' should " +
472 "return type 'BOOLEAN' but returns type 'STRING'.");
473 AnalysisError(
"select * from functional.alltypes where bool_col or double_col",
474 "Operand 'double_col' part of predicate 'bool_col OR double_col' should " +
475 "return type 'BOOLEAN' but returns type 'DOUBLE'.");
476 AnalysisError(
"select int_array_col or true from functional.allcomplextypes",
477 "Operand 'int_array_col' part of predicate 'int_array_col OR TRUE' should " +
478 "return type 'BOOLEAN' but returns type 'ARRAY<INT>'");
479 AnalysisError(
"select false and int_struct_col from functional.allcomplextypes",
480 "Operand 'int_struct_col' part of predicate 'FALSE AND int_struct_col' should " +
481 "return type 'BOOLEAN' but returns type 'STRUCT<f1:INT,f2:INT>'.");
482 AnalysisError(
"select not int_map_col from functional.allcomplextypes",
483 "Operand 'int_map_col' part of predicate 'NOT int_map_col' should return " +
484 "type 'BOOLEAN' but returns type 'MAP<STRING,INT>'.");
489 AnalyzesOk(
"select * from functional.alltypes where int_col is null");
490 AnalyzesOk(
"select * from functional.alltypes where string_col is not null");
491 AnalyzesOk(
"select * from functional.alltypes where null is not null");
492 AnalyzesOk(
"select 1 from functional.allcomplextypes where int_map_col is null");
497 AnalyzesOk(
"select * from functional.alltypes " +
498 "where tinyint_col between smallint_col and int_col");
499 AnalyzesOk(
"select * from functional.alltypes " +
500 "where tinyint_col not between smallint_col and int_col");
501 AnalyzesOk(
"select * from functional.alltypes " +
502 "where 'abc' between string_col and date_string_col");
503 AnalyzesOk(
"select * from functional.alltypes " +
504 "where 'abc' not between string_col and date_string_col");
506 AnalyzesOk(
"select * from functional.alltypes " +
507 "where string_col = 'abc' and tinyint_col between 10 and 20");
508 AnalyzesOk(
"select * from functional.alltypes " +
509 "where tinyint_col between 10 and 20 and string_col = 'abc'");
510 AnalyzesOk(
"select * from functional.alltypes " +
511 "where bool_col and tinyint_col between 10 and 20 and string_col = 'abc'");
513 AnalyzesOk(
"select * from functional.alltypes " +
514 "where true between false and true and 'b' between 'a' and 'c'");
516 AnalyzesOk(
"select * from functional.alltypes " +
517 "where true between 'b' between 'a' and 'c' and 'bb' between 'aa' and 'cc'");
520 AnalyzesOk(
"select 'abc' like '%a' between true and false");
521 AnalyzesOk(
"select false between (true and true) and (false and true)");
523 AnalyzesOk(
"select * from functional.alltypes " +
524 "where double_col between smallint_col and int_col");
526 AnalyzesOk(
"select * from functional.alltypes " +
527 "where smallint_col between float_col and double_col");
529 AnalyzesOk(
"select * from functional.alltypes " +
530 "where NULL between float_col and double_col");
531 AnalyzesOk(
"select * from functional.alltypes " +
532 "where smallint_col between NULL and double_col");
533 AnalyzesOk(
"select * from functional.alltypes " +
534 "where smallint_col between float_col and NULL");
535 AnalyzesOk(
"select * from functional.alltypes " +
536 "where NULL between NULL and NULL");
539 "where string_col between bool_col and double_col",
540 "Incompatible return types 'STRING' and 'BOOLEAN' " +
541 "of exprs 'string_col' and 'bool_col'.");
543 "where timestamp_col between int_col and double_col",
544 "Incompatible return types 'TIMESTAMP' and 'INT' " +
545 "of exprs 'timestamp_col' and 'int_col'.");
547 "where int_struct_col between 10 and 20",
548 "Incompatible return types 'STRUCT<f1:INT,f2:INT>' and 'TINYINT' " +
549 "of exprs 'int_struct_col' and '10'.");
554 AnalyzesOk(
"select * from functional.alltypes where int_col in (1, 2, 3, 4)");
555 AnalyzesOk(
"select * from functional.alltypes where int_col not in (1, 2, 3, 4)");
556 AnalyzesOk(
"select * from functional.alltypes where " +
557 "string_col in ('a', 'b', 'c', 'd')");
558 AnalyzesOk(
"select * from functional.alltypes where " +
559 "string_col not in ('a', 'b', 'c', 'd')");
561 AnalyzesOk(
"select * from functional.alltypes where " +
562 "true in (bool_col, true and false)");
563 AnalyzesOk(
"select * from functional.alltypes where " +
564 "true not in (bool_col, true and false)");
566 AnalyzesOk(
"select * from functional.alltypes where " +
567 "double_col in (int_col, bigint_col)");
569 AnalyzesOk(
"select * from functional.alltypes where " +
570 "int_col in (double_col, bigint_col)");
572 AnalyzesOk(
"select * from functional.alltypes where " +
573 "!true in (false or true, true and false)");
575 AnalyzesOk(
"select * from functional.alltypes where " +
576 "NULL in (NULL, NULL)");
578 AnalyzesOk(
"select bool_col = (int_col in (1,2)), " +
579 "case when tinyint_col in (10, NULL) then tinyint_col else NULL end " +
580 "from functional.alltypestiny where int_col > (bool_col in (false)) " +
581 "and (int_col in (1,2)) = (select min(bool_col) from functional.alltypes) " +
582 "and (int_col in (3,4)) = (tinyint_col in (4,5))");
585 "string_col in (bool_col, double_col)",
586 "Incompatible return types 'STRING' and 'BOOLEAN' " +
587 "of exprs 'string_col' and 'bool_col'.");
589 "timestamp_col in (int_col, double_col)",
590 "Incompatible return types 'TIMESTAMP' and 'INT' " +
591 "of exprs 'timestamp_col' and 'int_col'.");
593 "timestamp_col in (NULL, int_col)",
594 "Incompatible return types 'TIMESTAMP' and 'INT' " +
595 "of exprs 'timestamp_col' and 'int_col'.");
596 AnalysisError(
"select 1 from functional.allcomplextypes where " +
597 "int_array_col in (id, NULL)",
598 "Incompatible return types 'ARRAY<INT>' and 'INT' " +
599 "of exprs 'int_array_col' and 'id'.");
604 AnalyzesOk(
"select int_col from functional.alltypessmall order by count(*) over () "
606 AnalyzesOk(
"select sum(int_col) over () from functional.alltypes");
607 AnalyzesOk(
"select avg(bigint_col) over (partition by id) from functional.alltypes");
608 AnalyzesOk(
"select count(smallint_col) over (partition by id order by tinyint_col) "
609 +
"from functional.alltypes");
610 AnalyzesOk(
"select min(int_col) over (partition by id order by tinyint_col "
611 +
"rows between unbounded preceding and current row) from functional.alltypes");
612 AnalyzesOk(
"select sum(int_col) over (partition by id order by tinyint_col "
613 +
"rows 2 preceding) from functional.alltypes");
614 AnalyzesOk(
"select sum(int_col) over (partition by id order by tinyint_col "
615 +
"rows between 2 preceding and unbounded following) from functional.alltypes");
616 AnalyzesOk(
"select min(int_col) over (partition by id order by tinyint_col "
617 +
"rows between unbounded preceding and 2 preceding) from functional.alltypes");
618 AnalyzesOk(
"select sum(int_col) over (partition by id order by tinyint_col "
619 +
"rows between 2 following and unbounded following) from functional.alltypes");
625 AnalyzesOk(
"select sum(int_col) over (partition by id order by tinyint_col "
626 +
"rows between 2 preceding and 6 following) from functional.alltypes");
630 AnalyzesOk(
"select sum(int_col) over (partition by id order by tinyint_col "
631 +
"rows between 2 preceding and unbounded following) from functional.alltypes");
632 AnalyzesOk(
"select lead(int_col, 1, null) over "
633 +
"(partition by id order by tinyint_col) from functional.alltypes");
635 +
"(partition by id order by tinyint_col) from functional.alltypes");
637 "select id from functional.alltypes order by rank() over (order by tinyint_col)");
640 AnalyzesOk(
"select sum(count(id)) over (partition by min(int_col) "
641 +
"order by max(bigint_col)) from functional.alltypes group by id, tinyint_col "
642 +
"order by rank() over (order by max(bool_col), tinyint_col)");
643 AnalyzesOk(
"select lead(count(id)) over (order by tinyint_col) "
644 +
"from functional.alltypes group by id, tinyint_col "
645 +
"order by rank() over (order by tinyint_col)");
646 AnalyzesOk(
"select min(count(id)) over (order by tinyint_col) "
647 +
"from functional.alltypes group by id, tinyint_col "
648 +
"order by rank() over (order by tinyint_col)");
651 AnalyzesOk(
"select t1.int_col, COUNT(t1.int_col) OVER (ORDER BY t1.int_col) "
652 +
"FROM functional.alltypes t1 GROUP BY t1.int_col HAVING COUNT(t1.int_col) > 1");
656 "select sum(int_col) over (partition by id order by tinyint_col, int_col "
657 +
"rows between 2 following and 4 following) from functional.alltypes");
659 "select max(int_col) over (partition by id order by tinyint_col, int_col "
660 +
"range between unbounded preceding and current row) "
661 +
"from functional.alltypes");
663 "select sum(int_col) over (partition by id order by tinyint_col, int_col "
664 +
"range between current row and unbounded following) "
665 +
"from functional.alltypes");
667 "select max(int_col) over (partition by id order by tinyint_col, int_col "
668 +
"range between unbounded preceding and unbounded following) "
669 +
"from functional.alltypes");
670 AnalyzesOk(
"select sum(int_col) over (partition by id order by tinyint_col "
671 +
"rows between 4 preceding and 2 preceding) from functional.alltypes");
672 AnalyzesOk(
"select sum(int_col) over (partition by id order by tinyint_col "
673 +
"rows between 2 following and 4 following) from functional.alltypes");
675 +
"2 * min(tinyint_col) over (partition by id order by tinyint_col "
676 +
" rows between unbounded preceding and current row), "
677 +
"concat(max(string_col) over (partition by timestamp_col, int_col "
678 +
" order by tinyint_col, smallint_col "
679 +
" rows between unbounded preceding and current row), "
680 +
"min(string_col) over (partition by timestamp_col, int_col "
681 +
" order by tinyint_col, smallint_col "
682 +
" rows between unbounded preceding and current row)) "
683 +
"from functional.alltypes");
685 "select sum(int_col) over (partition by id order by tinyint_col, int_col "
686 +
"rows between current row and current row) from functional.alltypes");
688 "select sum(int_col) over (partition by id order by tinyint_col, int_col "
689 +
"range between current row and current row) from functional.alltypes",
690 "RANGE is only supported with both the lower and upper bounds UNBOUNDED or one "
691 +
"UNBOUNDED and the other CURRENT ROW.");
692 AnalysisError(
"select sum(int_col) over (partition by id order by tinyint_col "
693 +
"range between 2 following and 2 following) from functional.alltypes",
694 "RANGE is only supported with both the lower and upper bounds UNBOUNDED or one "
695 +
"UNBOUNDED and the other CURRENT ROW.");
698 AnalysisError(
"select max(int_col) over (partition by id order by tinyint_col "
699 +
"rows 2 preceding) from functional.alltypes",
700 "'max(int_col)' is only supported with an UNBOUNDED PRECEDING start bound.");
703 AnalyzesOk(
"select max(id) over (order by id rows between current row and "
704 +
"unbounded following) from functional.alltypes");
705 AnalyzesOk(
"select min(int_col) over (partition by id order by tinyint_col "
706 +
"rows between 2 preceding and unbounded following) from functional.alltypes");
714 "select lead(count(bigint_col)) over (order by tinyint_col) "
715 +
"from functional.alltypes group by id, tinyint_col "
716 +
"order by rank() over (order by smallint_col)",
717 "ORDER BY expression not produced by aggregation output (missing from GROUP "
718 +
"BY clause?): rank() OVER (ORDER BY smallint_col ASC)");
720 AnalysisError(
"select 1, lag(int_col) from functional.alltypes",
721 "Analytic function requires an OVER clause: lag(int_col)");
724 "Analytic expressions require FROM clause");
727 "select distinct int_col, sum(double_col) over () from functional.alltypes",
728 "cannot combine SELECT DISTINCT with analytic functions");
731 "select id, count(*) from functional.alltypes "
732 +
"group by 1, rank() over(order by int_col)",
733 "GROUP BY expression must not contain analytic expressions: rank() OVER "
734 +
"(ORDER BY int_col ASC)");
736 "select id, rank() over(order by int_col), count(*) "
737 +
"from functional.alltypes group by 1, 2",
738 "GROUP BY expression must not contain analytic expressions: rank() OVER "
739 +
"(ORDER BY int_col ASC)");
742 "select id, count(*) from functional.alltypes group by 1 "
743 +
"having rank() over(order by int_col) > 1",
744 "HAVING clause must not contain analytic expressions: rank() OVER "
745 +
"(ORDER BY int_col ASC)");
748 "select id, tinyint_col from functional.alltypes "
749 +
"where row_number() over(order by id) > 1",
750 "WHERE clause must not contain analytic expressions: row_number() OVER "
751 +
"(ORDER BY id ASC)");
754 "select id, tinyint_col, sum(distinct tinyint_col) over(order by id) "
755 +
"from functional.alltypes",
756 "DISTINCT not allowed in analytic function");
759 "select min(id) over (order by tinyint_col) as X from functional.alltypes "
760 +
"group by id, tinyint_col order by rank() over (order by X)",
761 "Nesting of analytic expressions is not allowed");
764 +
"select * from (select sum(t1.year) over ("
765 +
" order by max(t1.id), t1.year "
766 +
" rows between unbounded preceding and 5 preceding) "
767 +
"from functional.alltypes t1 group by t1.year) t1) select * from t");
769 +
"select sum(t1.smallint_col) over () from functional.alltypes t1) "
770 +
"select * from t");
772 AnalyzesOk(
"with t as (select 1 as int_col_1 from functional.alltypesagg t1) "
773 +
"select count(t1.int_col_1) as int_col_1 from t t1 where t1.int_col_1 is null "
774 +
"group by t1.int_col_1 union all "
775 +
"select min(t1.day) over () from functional.alltypesagg t1");
778 "select rank() over (order by 1) from functional.alltypestiny",
779 "Expressions in the ORDER BY clause must not be constant: 1");
781 "select rank() over (partition by 2 order by id) from functional.alltypestiny",
782 "Expressions in the PARTITION BY clause must not be constant: 2");
784 "select rank() over (partition by 2 order by 1) from functional.alltypestiny",
785 "Expressions in the PARTITION BY clause must not be constant: 2");
789 "select sum(int_col) over (partition by id, rank() over (order by int_col) "
790 +
"order by tinyint_col, int_col "
791 +
"rows between 2 following and 4 following) from functional.alltypes",
792 "Nesting of analytic expressions is not allowed");
794 "select lead(rank() over (order by int_col)) over (partition by id "
795 +
"order by tinyint_col, int_col) from functional.alltypes",
796 "Nesting of analytic expressions is not allowed");
798 "select max(int_col) over (partition by id "
799 +
"order by rank() over (order by tinyint_col), int_col) "
800 +
"from functional.alltypes",
801 "Nesting of analytic expressions is not allowed");
805 "select lag(int_col, 10, 5 + 1) over (partition by id, bool_col "
806 +
"order by tinyint_col, int_col) from functional.alltypes");
808 "select lead(string_col, 1, 'default') over ("
809 +
"order by tinyint_col, int_col) from functional.alltypes");
811 "select lag(bool_col, 3) over ("
812 +
"order by id, int_col) from functional.alltypes");
814 "select lead(float_col, 2) over (partition by string_col, timestamp_col "
815 +
"order by tinyint_col, int_col) from functional.alltypes");
817 "select lag(double_col) over ("
818 +
"order by string_col, int_col) from functional.alltypes");
820 "select lead(timestamp_col) over (partition by id "
821 +
"order by tinyint_col, int_col) from functional.alltypes");
824 "select lag(string_col, 'x') over (partition by id "
825 +
"order by tinyint_col, int_col) from functional.alltypes",
826 "No matching function with signature: lag(STRING, STRING)");
829 "select lead(int_col, 1, 'x') over ("
830 +
"order by tinyint_col, int_col) from functional.alltypes",
831 "No matching function with signature: lead(INT, TINYINT, STRING)");
834 "select lag() over (partition by id "
835 +
"order by tinyint_col, int_col) from functional.alltypes",
836 "No matching function with signature: lag()");
839 "select lead(int_col, -1) over ("
840 +
"order by tinyint_col, int_col) from functional.alltypes",
841 "The offset parameter of LEAD/LAG must be a constant positive integer");
843 "select lag(int_col, tinyint_col * 2, 5) over ("
844 +
"order by tinyint_col, int_col) from functional.alltypes",
845 "The offset parameter of LEAD/LAG must be a constant positive integer");
847 "select lag(int_col, 1, int_col) over ("
848 +
"order by tinyint_col, int_col) from functional.alltypes",
849 "The default parameter (parameter 3) of LEAD/LAG must be a constant");
852 AnalysisError(
"select abs(float_col) over (partition by id order by tinyint_col "
853 +
"rows between unbounded preceding and current row) from functional.alltypes",
854 "OVER clause requires aggregate or analytic function: abs(float_col)");
855 AnalysisError(
"select group_concat(string_col) over (order by tinyint_col "
856 +
"rows between unbounded preceding and current row) from functional.alltypes",
857 "Aggregate function 'group_concat(string_col)' not supported with OVER clause.");
860 +
"rows between unbounded preceding and current row) from functional.alltypes",
861 "Windowing clause requires ORDER BY clause");
863 AnalysisError(
"select dense_rank() over (partition by id) from functional.alltypes",
864 "'dense_rank()' requires an ORDER BY clause");
866 AnalysisError(
"select lag(tinyint_col, 1, null) over (partition by id) "
867 +
"from functional.alltypes",
868 "'lag(tinyint_col, 1, NULL)' requires an ORDER BY clause");
870 AnalysisError(
"select row_number() over (partition by id order by tinyint_col "
871 +
"rows between unbounded preceding and current row) from functional.alltypes",
872 "Windowing clause not allowed with 'row_number()'");
874 AnalysisError(
"select lead(tinyint_col, 1, null) over (partition by id "
875 +
"order by tinyint_col rows between unbounded preceding and current row) "
876 +
"from functional.alltypes",
877 "Windowing clause not allowed with 'lead(tinyint_col, 1, NULL)'");
880 AnalysisError(
"select sum(tinyint_col) over (partition by id "
881 +
"order by tinyint_col rows between unbounded following and current row) "
882 +
"from functional.alltypes",
883 "UNBOUNDED FOLLOWING is only allowed for upper bound of BETWEEN");
884 AnalysisError(
"select sum(tinyint_col) over (partition by id "
885 +
"order by tinyint_col rows unbounded following) from functional.alltypes",
886 "UNBOUNDED FOLLOWING is only allowed for upper bound of BETWEEN");
887 AnalysisError(
"select sum(tinyint_col) over (partition by id "
888 +
"order by tinyint_col rows between current row and unbounded preceding) "
889 +
"from functional.alltypes",
890 "UNBOUNDED PRECEDING is only allowed for lower bound of BETWEEN");
891 AnalysisError(
"select sum(tinyint_col) over (partition by id "
892 +
"order by tinyint_col rows 2 following) from functional.alltypes",
893 "FOLLOWING requires a BETWEEN clause");
895 "select sum(tinyint_col) over (partition by id "
896 +
"order by tinyint_col rows between 2 following and current row) "
897 +
"from functional.alltypes",
898 "A lower window bound of FOLLOWING requires that the upper bound also be "
901 "select sum(tinyint_col) over (partition by id "
902 +
"order by tinyint_col rows between current row and 2 preceding) "
903 +
"from functional.alltypes",
904 "An upper window bound of PRECEDING requires that the lower bound also be "
909 "select min(int_col) over (partition by id order by tinyint_col "
910 +
"rows between tinyint_col preceding and current row) "
911 +
"from functional.alltypes",
912 "For ROWS window, the value of a PRECEDING/FOLLOWING offset must be a "
913 +
"constant positive integer: tinyint_col PRECEDING");
915 "select min(int_col) over (partition by id order by tinyint_col "
916 +
"rows between current row and '2' following) from functional.alltypes",
917 "For ROWS window, the value of a PRECEDING/FOLLOWING offset must be a "
918 +
"constant positive integer: '2' FOLLOWING");
920 "select min(int_col) over (partition by id order by tinyint_col "
921 +
"rows between -2 preceding and current row) from functional.alltypes",
922 "For ROWS window, the value of a PRECEDING/FOLLOWING offset must be a "
923 +
"constant positive integer: -2 PRECEDING");
925 "select min(int_col) over (partition by id order by tinyint_col "
926 +
"rows between 2 preceding and 3 preceding) from functional.alltypes",
927 "Offset boundaries are in the wrong order: ROWS BETWEEN 2 PRECEDING AND "
930 "select min(int_col) over (partition by id order by tinyint_col "
931 +
"rows between count(*) preceding and current row) from functional.alltypes",
932 "For ROWS window, the value of a PRECEDING/FOLLOWING offset must be a "
933 +
"constant positive integer: count(*) PRECEDING");
976 for (
Type type1: numericTypes) {
977 for (
Type type2: numericTypes) {
978 Type t = Type.getAssignmentCompatibleType(type1, type2);
981 Type promotedType = compatibleType.getNextResolutionType();
982 boolean inputsNull =
false;
983 if (type1.isNull() && type2.isNull()) {
1014 if ((!type1.isFixedPointType() && !type1.isNull())
1015 || (!type2.isFixedPointType() && !type2.isNull())) {
1037 List<Type> fixedPointTypes =
new ArrayList<Type>(Type.getIntegerTypes());
1039 for (
Type type: fixedPointTypes) {
1041 type.isNull() ? Type.INT : type);
1057 for (
Type type1: types) {
1058 for (
Type type2: types) {
1059 Type compatibleType =
1060 Type.getAssignmentCompatibleType(type1, type2);
1061 typeCastTest(type1, type2,
false, null, cmpOp, compatibleType);
1062 typeCastTest(type1, type2,
true, null, cmpOp, compatibleType);
1076 Preconditions.checkState((arithmeticOp == null) != (cmpOp == null));
1077 boolean arithmeticMode = arithmeticOp != null;
1079 if (type1 != null) {
1081 op1 = typeToLiteralValue_.get(type1);
1083 op1 = TestSchemaUtils.getAllTypesColumn(type1);
1086 String op2 = TestSchemaUtils.getAllTypesColumn(type2);
1087 String queryStr = null;
1088 if (arithmeticMode) {
1089 queryStr =
"select " + op1 +
" " + arithmeticOp.toString() +
" " + op2 +
1090 " AS a from functional.alltypes";
1092 queryStr =
"select int_col from functional.alltypes " +
1093 "where " + op1 +
" " + cmpOp.toString() +
" " + op2;
1097 if (arithmeticMode) {
1098 ArrayList<Expr> selectListExprs = select.getResultExprs();
1099 assertNotNull(selectListExprs);
1100 assertEquals(selectListExprs.size(), 1);
1102 expr = selectListExprs.get(0);
1103 Assert.assertEquals(
"opType= " + opType +
" exprType=" + expr.getType(),
1104 opType, expr.getType());
1107 expr = select.getWhereClause();
1108 if (!expr.
getType().isNull()) {
1114 Type child1Type = expr.getChild(0).getType();
1115 Type child2Type = type1 == null ? null : expr.getChild(1).getType();
1116 Assert.assertTrue(
"opType= " + opType +
" child1Type=" + child1Type,
1117 opType.equals(child1Type) || opType.
isNull() || child1Type.isNull());
1118 if (type1 != null) {
1119 Assert.assertTrue(
"opType= " + opType +
" child2Type=" + child2Type,
1120 opType.equals(child2Type) || opType.
isNull() || child2Type.isNull());
1126 ArrayList<Expr> selectListExprs = select.getResultExprs();
1127 assertNotNull(selectListExprs);
1128 assertEquals(selectListExprs.size(), 1);
1130 Expr expr = selectListExprs.get(0);
1131 assertEquals(
"Expected: " + resultType +
" != " + expr.getType(),
1132 resultType, expr.getType());
1143 checkReturnType(
"select float_col + float_col from functional.alltypestiny",
1145 checkReturnType(
"select int_col + int_col from functional.alltypestiny",
1149 checkReturnType(
"select float_col + 1.1 from functional.alltypestiny",
1163 checkReturnType(
"select float_col + cast(1.1*1.2+1.3 as decimal(2,1)) from "
1167 checkReturnType(
"select 1.0 + float_col + 1.1 from functional.alltypestiny",
1169 checkReturnType(
"select 1.0 + 2.0 + float_col from functional.alltypestiny",
1171 checkReturnType(
"select 1.0 + 2.0 + pi() * float_col from functional.alltypestiny",
1177 checkReturnType(
"select 1.0 + 2.0 + pi()*d1 from functional.decimal_tbl",
1182 " from functional.alltypestiny",
Type.
DOUBLE);
1183 checkReturnType(
"select double_col + 1.23 + float_col + 1.0 + int_col " +
1184 " + bigint_col from functional.alltypestiny",
Type.
DOUBLE);
1189 checkReturnType(
"select t1.int_col + t2.c1 from functional.alltypestiny t1 " +
1191 checkReturnType(
"select 1.1 + t1.int_col + t2.c1 from functional.alltypestiny t1 " +
1203 CastExpr cast = (CastExpr)expr;
1205 Assert.assertFalse(expr.getType() +
" == " + expr.getChild(0).getType(),
1206 expr.
getType().equals(expr.getChild(0).getType()));
1207 Assert.assertFalse(expr.debugString(), expr.getChild(0) instanceof
LiteralExpr);
1210 for (
Expr child: expr.getChildren()) {
1219 AnalysisError(
"select int_col from functional.alltypes where date_col = 'ABCD'",
1220 "Unable to parse string 'ABCD' to date");
1222 "where date_col = 'ABCD-EF-GH'",
1223 "Unable to parse string 'ABCD-EF-GH' to date");
1224 AnalysisError(
"select int_col from functional.alltypes where date_col = '2006'",
1225 "Unable to parse string '2006' to date");
1226 AnalysisError(
"select int_col from functional.alltypes where date_col = '0.5'",
1227 "Unable to parse string '0.5' to date");
1228 AnalysisError(
"select int_col from functional.alltypes where " +
1229 "date_col = '2006-10-10 ABCD'",
1230 "Unable to parse string '2006-10-10 ABCD' to date");
1231 AnalysisError(
"select int_col from functional.alltypes where " +
1232 "date_col = '2006-10-10 12:11:05.ABC'",
1233 "Unable to parse string '2006-10-10 12:11:05.ABC' to date");
1241 "Bitwise operations only allowed on integer types");
1242 AnalysisError(
"select float_col ^ int_col from functional.alltypes",
1243 "Invalid non-integer argument to operation '^'");
1244 AnalysisError(
"select float_col & int_col from functional.alltypes",
1245 "Invalid non-integer argument to operation '&'");
1246 AnalysisError(
"select double_col | bigint_col from functional.alltypes",
1247 "Invalid non-integer argument to operation '|'");
1248 AnalysisError(
"select int_col from functional.alltypes where " +
1249 "float_col & bool_col > 5",
1250 "Arithmetic operation requires numeric operands");
1263 String[] valueTypeCols =
1264 new String[] {
"tinyint_col",
"smallint_col",
"int_col",
"bigint_col",
"NULL"};
1269 for (String col: valueTypeCols) {
1271 AnalyzesOk(
"select timestamp_col + interval " + col +
" " + timeUnit.toString() +
1272 " from functional.alltypes");
1273 AnalyzesOk(
"select timestamp_col - interval " + col +
" " + timeUnit.toString() +
1274 " from functional.alltypes");
1275 AnalyzesOk(
"select NULL - interval " + col +
" " + timeUnit.toString() +
1276 " from functional.alltypes");
1278 AnalyzesOk(
"select interval " + col +
" " + timeUnit.toString() +
1279 " + timestamp_col from functional.alltypes");
1281 AnalyzesOk(
"select date_add(timestamp_col, interval " + col +
" " +
1282 timeUnit.toString() +
") from functional.alltypes");
1283 AnalyzesOk(
"select date_sub(timestamp_col, interval " + col +
" " +
1284 timeUnit.toString() +
") from functional.alltypes");
1285 AnalyzesOk(
"select date_add(NULL, interval " + col +
" " +
1286 timeUnit.toString() +
") from functional.alltypes");
1287 AnalyzesOk(
"select date_sub(NULL, interval " + col +
" " +
1288 timeUnit.toString() +
") from functional.alltypes");
1293 AnalysisError(
"select float_col + interval 10 years from functional.alltypes",
1294 "Operand 'float_col' of timestamp arithmetic expression " +
1295 "'float_col + INTERVAL 10 years' returns type 'FLOAT'. " +
1296 "Expected type 'TIMESTAMP'.");
1297 AnalysisError(
"select string_col + interval 10 years from functional.alltypes",
1298 "Operand 'string_col' of timestamp arithmetic expression " +
1299 "'string_col + INTERVAL 10 years' returns type 'STRING'. " +
1300 "Expected type 'TIMESTAMP'.");
1302 "select int_struct_col + interval 10 years from functional.allcomplextypes",
1303 "Operand 'int_struct_col' of timestamp arithmetic expression " +
1304 "'int_struct_col + INTERVAL 10 years' returns type 'STRUCT<f1:INT,f2:INT>'. " +
1305 "Expected type 'TIMESTAMP'.");
1307 AnalysisError(
"select interval 10 years + float_col from functional.alltypes",
1308 "Operand 'float_col' of timestamp arithmetic expression " +
1309 "'INTERVAL 10 years + float_col' returns type 'FLOAT'. " +
1310 "Expected type 'TIMESTAMP'");
1311 AnalysisError(
"select interval 10 years + string_col from functional.alltypes",
1312 "Operand 'string_col' of timestamp arithmetic expression " +
1313 "'INTERVAL 10 years + string_col' returns type 'STRING'. " +
1314 "Expected type 'TIMESTAMP'");
1316 "select interval 10 years + int_array_col from functional.allcomplextypes",
1317 "Operand 'int_array_col' of timestamp arithmetic expression " +
1318 "'INTERVAL 10 years + int_array_col' returns type 'ARRAY<INT>'. " +
1319 "Expected type 'TIMESTAMP'.");
1321 AnalysisError(
"select date_add(float_col, interval 10 years) " +
1322 "from functional.alltypes",
1323 "Operand 'float_col' of timestamp arithmetic expression " +
1324 "'DATE_ADD(float_col, INTERVAL 10 years)' returns type 'FLOAT'. " +
1325 "Expected type 'TIMESTAMP'.");
1326 AnalysisError(
"select date_add(string_col, interval 10 years) " +
1327 "from functional.alltypes",
1328 "Operand 'string_col' of timestamp arithmetic expression " +
1329 "'DATE_ADD(string_col, INTERVAL 10 years)' returns type 'STRING'. " +
1330 "Expected type 'TIMESTAMP'.");
1331 AnalysisError(
"select date_add(int_map_col, interval 10 years) " +
1332 "from functional.allcomplextypes",
1333 "Operand 'int_map_col' of timestamp arithmetic expression " +
1334 "'DATE_ADD(int_map_col, INTERVAL 10 years)' returns type 'MAP<STRING,INT>'. " +
1335 "Expected type 'TIMESTAMP'.");
1339 AnalysisError(
"select timestamp_col + interval 5.2 years from functional.alltypes",
1340 "Operand '5.2' of timestamp arithmetic expression " +
1341 "'timestamp_col + INTERVAL 5.2 years' returns type 'DECIMAL(2,1)'. " +
1342 "Expected an integer type.");
1343 AnalysisError(
"select cast(0 as timestamp) + interval int_array_col years " +
1344 "from functional.allcomplextypes",
1345 "Operand 'int_array_col' of timestamp arithmetic expression " +
1346 "'CAST(0 AS TIMESTAMP) + INTERVAL int_array_col years' " +
1347 "returns type 'ARRAY<INT>'. Expected an integer type.");
1350 AnalysisError(
"select timestamp_col + interval '10' years from functional.alltypes",
1351 "Operand ''10'' of timestamp arithmetic expression 'timestamp_col + " +
1352 "INTERVAL '10' years' returns type 'STRING'. " +
1353 "Expected an integer type.");
1354 AnalysisError(
"select date_add(timestamp_col, interval '10' years) " +
1355 "from functional.alltypes",
"Operand ''10'' of timestamp arithmetic " +
1356 "expression 'DATE_ADD(timestamp_col, INTERVAL '10' years)' returns " +
1357 "type 'STRING'. Expected an integer type.");
1360 AnalyzesOk(
"select timestamp_col + interval cast('10' as int) years " +
1361 "from functional.alltypes");
1363 AnalysisError(
"select interval 5.2 years + timestamp_col from functional.alltypes",
1364 "Operand '5.2' of timestamp arithmetic expression " +
1365 "'INTERVAL 5.2 years + timestamp_col' returns type 'DECIMAL(2,1)'. " +
1366 "Expected an integer type.");
1368 AnalyzesOk(
"select interval cast('10' as int) years + timestamp_col " +
1369 "from functional.alltypes");
1371 AnalysisError(
"select date_add(timestamp_col, interval 5.2 years) " +
1372 "from functional.alltypes",
1373 "Operand '5.2' of timestamp arithmetic expression " +
1374 "'DATE_ADD(timestamp_col, INTERVAL 5.2 years)' returns type 'DECIMAL(2,1)'. " +
1375 "Expected an integer type.");
1377 AnalyzesOk(
"select date_add(timestamp_col, interval cast('10' as int) years) " +
1378 " from functional.alltypes");
1381 AnalysisError(
"select timestamp_col + interval 10 error from functional.alltypes",
1382 "Invalid time unit 'error' in timestamp arithmetic expression " +
1383 "'timestamp_col + INTERVAL 10 error'.");
1384 AnalysisError(
"select timestamp_col - interval 10 error from functional.alltypes",
1385 "Invalid time unit 'error' in timestamp arithmetic expression " +
1386 "'timestamp_col - INTERVAL 10 error'.");
1388 AnalysisError(
"select interval 10 error + timestamp_col from functional.alltypes",
1389 "Invalid time unit 'error' in timestamp arithmetic expression " +
1390 "'INTERVAL 10 error + timestamp_col'.");
1392 AnalysisError(
"select date_add(timestamp_col, interval 10 error) " +
1393 "from functional.alltypes",
1394 "Invalid time unit 'error' in timestamp arithmetic expression " +
1395 "'DATE_ADD(timestamp_col, INTERVAL 10 error)'.");
1396 AnalysisError(
"select date_sub(timestamp_col, interval 10 error) " +
1397 "from functional.alltypes",
1398 "Invalid time unit 'error' in timestamp arithmetic expression " +
1399 "'DATE_SUB(timestamp_col, INTERVAL 10 error)'.");
1408 AnalysisError(
"select pi(*)",
"Cannot pass '*' to scalar function.");
1410 "Cannot pass 'DISTINCT' to scalar function.");
1411 AnalysisError(
"select * from functional.alltypes where pi(*) = 5",
1412 "Cannot pass '*' to scalar function.");
1415 "Invalid function name: 'a.b.sin'. Expected [dbname].funcname");
1419 AnalyzesOk(
"select precision(cast('1.1' as decimal))");
1422 "No matching function with signature: scale(STRING).");
1424 AnalyzesOk(
"select round(cast('1.1' as decimal), cast(1 as int))");
1426 AnalyzesOk(
"select round(cast('1.1' as decimal), 1)");
1429 AnalysisError(
"select lower(int_struct_col) from functional.allcomplextypes",
1430 "No matching function with signature: lower(STRUCT<f1:INT,f2:INT>).");
1433 AnalyzesOk(
"select extract(year from now())");
1435 "Time unit 'foo' in expression 'EXTRACT(foo FROM now())' is invalid. Expected " +
1436 "one of YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, MILLISECOND, EPOCH.");
1438 "Expression '0' in 'EXTRACT(year FROM 0)' has a return type of TINYINT but a " +
1439 "TIMESTAMP is required.");
1441 "Function functional.extract conflicts with the EXTRACT builtin");
1443 "Function DATE_PART does not accept the keyword FROM");
1451 AnalyzesOk(
"select concat('a', 'b', 'c', 'd')");
1452 AnalyzesOk(
"select concat('a', 'b', 'c', 'd', 'e')");
1455 AnalyzesOk(
"select coalesce(true, false, true)");
1459 AnalyzesOk(
"select coalesce('a', 'b', 'c')");
1462 "No matching function with signature: concat().");
1464 "No matching function with signature: coalesce().");
1476 AnalyzesOk(
"select substring('a', NULL, 2)");
1477 AnalyzesOk(
"select substring('a', 1, NULL)");
1478 AnalyzesOk(
"select substring(NULL, NULL, NULL)");
1481 "No matching function with signature: " +
1482 "substring(TINYINT, NULL_TYPE, NULL_TYPE).");
1484 "No matching function with signature: " +
1485 "substring(NULL_TYPE, STRING, NULL_TYPE).");
1491 AnalyzesOk(
"select concat(NULL, NULL, NULL)");
1494 "No matching function with signature: concat(NULL_TYPE, TINYINT, STRING).");
1496 "No matching function with signature: concat(STRING, NULL_TYPE, TINYINT).");
1498 "No matching function with signature: concat(TINYINT, STRING, NULL_TYPE).");
1504 AnalyzesOk(
"select case when 20 > 10 then 20 else 15 end");
1506 AnalyzesOk(
"select case when 20 > 10 then 20 end");
1508 AnalyzesOk(
"select case when bool_col then 20 else 15 end from functional.alltypes");
1510 AnalyzesOk(
"select case when 20 > 10 then 20 when 1 > 2 then 1.0 else 15 end");
1512 AnalyzesOk(
"select case when 20 > 10 then 20 when 1 > 2 then 1.0 " +
1513 "when 4 < 5 then 2 else 15 end");
1515 AnalysisError(
"select case when 20 then 20 when 1 > 2 then timestamp_col " +
1516 "when 4 < 5 then 2 else 15 end from functional.alltypes",
1517 "When expr '20' is not of type boolean and not castable to type boolean.");
1518 AnalysisError(
"select case when int_array_col then 20 when 1 > 2 then id end " +
1519 "from functional.allcomplextypes",
1520 "When expr 'int_array_col' is not of type boolean and not castable to " +
1523 AnalysisError(
"select case when 20 > 10 then 20 when 1 > 2 then timestamp_col " +
1524 "when 4 < 5 then 2 else 15 end from functional.alltypes",
1525 "Incompatible return types 'TINYINT' and 'TIMESTAMP' " +
1526 "of exprs '20' and 'timestamp_col'.");
1527 AnalysisError(
"select case when 20 > 10 then 20 when 1 > 2 then int_map_col " +
1528 "else 15 end from functional.allcomplextypes",
1529 "Incompatible return types 'TINYINT' and 'MAP<STRING,INT>' of exprs " +
1530 "'20' and 'int_map_col'.");
1533 AnalyzesOk(
"select case int_col when 20 then 30 else 15 end " +
1534 "from functional.alltypes");
1536 AnalyzesOk(
"select case int_col when 20 then 30 end " +
1537 "from functional.alltypes");
1539 AnalyzesOk(
"select case int_col when bigint_col then 30 else 15 end " +
1540 "from functional.alltypes");
1542 AnalyzesOk(
"select case bigint_col when int_col then 30 else 15 end " +
1543 "from functional.alltypes");
1545 AnalyzesOk(
"select case bigint_col when int_col then 30 " +
1546 "when double_col then 1.0 else 15 end from functional.alltypes");
1548 AnalysisError(
"select case bigint_col when timestamp_col then 30 " +
1549 "when double_col then 1.0 else 15 end from functional.alltypes",
1550 "Incompatible return types 'BIGINT' and 'TIMESTAMP' " +
1551 "of exprs 'bigint_col' and 'timestamp_col'.");
1553 AnalysisError(
"select case bigint_col when int_col then 30 " +
1554 "when double_col then timestamp_col else 15 end from functional.alltypes",
1555 "Incompatible return types 'TINYINT' and 'TIMESTAMP' " +
1556 "of exprs '30' and 'timestamp_col'.");
1559 AnalyzesOk(
"select case when true then 1 end");
1560 AnalyzesOk(
"select case when true then 1.0 end");
1561 AnalyzesOk(
"select case when true then 'abc' end");
1562 AnalyzesOk(
"select case when true then cast('2011-01-01 09:01:01' " +
1563 "as timestamp) end");
1565 AnalyzesOk(
"select case NULL when 1 then 2 else 3 end");
1566 AnalyzesOk(
"select case 1 when NULL then 2 else 3 end");
1567 AnalyzesOk(
"select case 1 when 2 then NULL else 3 end");
1568 AnalyzesOk(
"select case 1 when 2 then 3 else NULL end");
1569 AnalyzesOk(
"select case NULL when NULL then NULL else NULL end");
1576 AnalyzesOk(
"select decode(1, 2, true, false)");
1577 AnalyzesOk(
"select decode(null, null, null, null, null, null)");
1579 "CASE WHEN 1 = 2 THEN NULL ELSE 'foo' END",
1580 "decode(1, 2, NULL, 'foo')");
1582 "CASE WHEN 1 = 2 THEN NULL ELSE 4 END",
1583 "decode(1, 2, NULL, 4)");
1585 "CASE WHEN string_col = 'a' THEN 1 WHEN string_col = 'b' THEN 2 ELSE 3 END",
1586 "decode(string_col, 'a', 1, 'b', 2, 3)");
1588 "CASE WHEN int_col IS NULL AND bigint_col IS NULL "
1589 +
"OR int_col = bigint_col THEN tinyint_col ELSE smallint_col END",
1590 "decode(int_col, bigint_col, tinyint_col, smallint_col)");
1592 "CASE WHEN int_col = 1 THEN 1 WHEN int_col IS NULL AND bigint_col IS NULL OR "
1593 +
"int_col = bigint_col THEN 2 WHEN int_col IS NULL THEN 3 ELSE 4 END",
1594 "decode(int_col, 1, 1, bigint_col, 2, NULL, 3, 4)");
1596 "CASE WHEN NULL IS NULL THEN NULL ELSE NULL END",
1597 "decode(null, null, null, null)");
1600 "DECODE in 'decode()' requires at least 3 arguments");
1602 "DECODE in 'decode(1)' requires at least 3 arguments");
1604 "DECODE in 'decode(1, 2)' requires at least 3 arguments");
1606 AnalysisError(
"select decode(distinct 1, 2, 3)",
"Cannot pass 'DISTINCT'");
1608 "operands of type BOOLEAN and STRING are not comparable: TRUE = 'foo'");
1609 AnalysisError(
"select functional.decode(1, 1, 1)",
"functional.decode() unknown");
1618 String sqlTemplate =
"select %s from functional.alltypes";
1622 List<SlotRef> slotRefs = Lists.newArrayList();
1623 caseExpr.collect(Predicates.instanceOf(SlotRef.class), slotRefs);
1624 for (
SlotRef slotRef: slotRefs) {
1625 slotRef.getDesc().setIsMaterialized(
true);
1626 slotRef.getDesc().setByteOffset(0);
1628 TExpr caseThrift = caseExpr.treeToThrift();
1631 (
CaseExpr)stmt.getSelectList().getItems().
get(0).getExpr();
1632 Assert.assertEquals(caseSql, decodeExpr.toCaseSql());
1634 decodeExpr.collect(Predicates.instanceOf(SlotRef.class), slotRefs);
1635 for (
SlotRef slotRef: slotRefs) {
1636 slotRef.getDesc().setIsMaterialized(
true);
1637 slotRef.getDesc().setByteOffset(0);
1639 Assert.assertEquals(caseThrift, decodeExpr.treeToThrift());
1646 AnalyzesOk(
"select if(1 != 2, false, false)");
1647 AnalyzesOk(
"select if(bool_col, false, true) from functional.alltypes");
1648 AnalyzesOk(
"select if(bool_col, int_col, double_col) from functional.alltypes");
1650 AnalyzesOk(
"select if(NULL, false, true) from functional.alltypes");
1651 AnalyzesOk(
"select if(bool_col, NULL, true) from functional.alltypes");
1652 AnalyzesOk(
"select if(bool_col, false, NULL) from functional.alltypes");
1653 AnalyzesOk(
"select if(NULL, NULL, NULL) from functional.alltypes");
1655 AnalysisError(
"select if(true, int_struct_col, int_struct_col) " +
1656 "from functional.allcomplextypes",
1657 "No matching function with signature: " +
1658 "if(BOOLEAN, STRUCT<f1:INT,f2:INT>, STRUCT<f1:INT,f2:INT>).");
1662 "No matching function with signature: if(BOOLEAN, BOOLEAN, BOOLEAN, " +
1665 "No matching function with signature: if(BOOLEAN, BOOLEAN).");
1667 "No matching function with signature: if(BOOLEAN).");
1671 String literal = typeToLiteralValue_.get(t);
1672 AnalyzesOk(String.format(
"select isnull(%s, %s)", literal, literal));
1673 AnalyzesOk(String.format(
"select isnull(%s, NULL)", literal));
1674 AnalyzesOk(String.format(
"select isnull(NULL, %s)", literal));
1678 "No matching function with signature: isnull(TINYINT).");
1680 "No matching function with signature: isnull(TINYINT, TINYINT, TINYINT).");
1683 "No matching function with signature: isnull(STRING, BOOLEAN).");
1685 AnalysisError(
"select isnull(1, int_array_col) from functional.allcomplextypes",
1686 "No matching function with signature: isnull(TINYINT, ARRAY<INT>).");
1694 AnalysisError(
"select functional.udf()",
"functional.udf() unknown");
1700 new ArrayList<Type>(),
Type.
INT, dummyUri, null, null, null));
1703 Type.
INT, dummyUri, null, null, null));
1706 Type.
INT, dummyUri, null, null, null);
1707 varArgsUdf1.setHasVarArgs(
true);
1708 catalog_.addFunction(varArgsUdf1);
1711 Type.
INT, dummyUri, null, null, null);
1712 varArgsUdf2.setHasVarArgs(
true);
1713 catalog_.addFunction(varArgsUdf2);
1716 Type.
INT, dummyUri, null, null, null);
1717 catalog_.addFunction(udf);
1723 AnalyzesOk(
"select udf(cast(1.1 as TINYINT))");
1730 "No matching function with signature: default.udf(TINYINT, TINYINT).");
1735 "No matching function with signature: default.udf(TINYINT, STRING, TINYINT).");
1738 "No matching function with signature: default.udf(DECIMAL(2,1))");
1742 "No matching function with signature: functional.udf(STRING).");
1745 "No matching function with signature: default.udf(TINYINT, TINYINT).");
1746 catalog_.removeFunction(udf);
1752 StringBuilder inPredStr =
new StringBuilder(
"select 1 IN(");
1753 for (
int i = 0; i < Expr.EXPR_CHILDREN_LIMIT - 1; ++i) {
1754 inPredStr.append(i);
1758 inPredStr.append(
", " + 1234);
1760 String.format(
"Exceeded the maximum number of child expressions (%s).\n" +
1762 Expr.EXPR_CHILDREN_LIMIT + 1));
1765 StringBuilder caseExprStr =
new StringBuilder(
"select case");
1766 for (
int i = 0; i < Expr.EXPR_CHILDREN_LIMIT/2; ++i) {
1767 caseExprStr.append(
" when true then 1");
1770 caseExprStr.append(
" when true then 1");
1772 String.format(
"Exceeded the maximum number of child expressions (%s).\n" +
1774 Expr.EXPR_CHILDREN_LIMIT + 2));
1786 " + " + String.valueOf(Long.MAX_VALUE));
1794 catalog_.addFunction(udf);
1798 catalog_.removeFunction(udf);
1811 Expr root = selectStmt.resultExprs_.get(0);
1812 Type actualType = root.getType();
1814 "Expr: " + expr +
" Expected: " + expectedType +
" Actual: " + actualType,
1815 expectedType.equals(actualType));
1820 String decimal_10_0 =
"cast(1 as decimal(10,0))";
1821 String decimal_5_5 =
"cast(1 as decimal(5, 5))";
1822 String decimal_38_34 =
"cast(1 as decimal(38, 34))";
1885 testDecimalExpr(decimal_10_0 +
" + " + decimal_10_0 +
" + " + decimal_10_0,
1887 testDecimalExpr(decimal_10_0 +
" - " + decimal_10_0 +
" * " + decimal_10_0,
1889 testDecimalExpr(decimal_10_0 +
" / " + decimal_10_0 +
" / " + decimal_10_0,
1891 testDecimalExpr(decimal_10_0 +
" % " + decimal_10_0 +
" + " + decimal_10_0,
1922 AnalyzesOk(
"select " + decimal_5_5 +
" = cast(1 as tinyint)");
1923 AnalyzesOk(
"select " + decimal_5_5 +
" != cast(1 as smallint)");
1924 AnalyzesOk(
"select " + decimal_5_5 +
" > cast(1 as int)");
1925 AnalyzesOk(
"select " + decimal_5_5 +
" < cast(1 as bigint)");
1926 AnalyzesOk(
"select " + decimal_5_5 +
" >= cast(1 as float)");
1927 AnalyzesOk(
"select " + decimal_5_5 +
" <= cast(1 as double)");
1930 "Arithmetic operation requires numeric operands: "
1931 +
"CAST(1 AS DECIMAL(5,5)) + 'abcd'");
1932 AnalysisError(
"select " + decimal_5_5 +
" + 'cast(1 as timestamp)'",
1933 "Arithmetic operation requires numeric operands: "
1934 +
"CAST(1 AS DECIMAL(5,5)) + 'cast(1 as timestamp)'");
1937 "operands of type DECIMAL(5,5) and STRING are not comparable: " +
1938 "CAST(1 AS DECIMAL(5,5)) = 'abcd'");
1939 AnalysisError(
"select " + decimal_5_5 +
" > 'cast(1 as timestamp)'",
1940 "operands of type DECIMAL(5,5) and STRING are not comparable: "
1941 +
"CAST(1 AS DECIMAL(5,5)) > 'cast(1 as timestamp)'");
1946 AnalyzesOk(
"select d2 % d5 from functional.decimal_tbl");
1948 AnalyzesOk(
"select d1 from functional.decimal_tbl");
1949 AnalyzesOk(
"select cast(d2 as decimal(1)) from functional.decimal_tbl");
1950 AnalyzesOk(
"select d3 + d4 from functional.decimal_tbl");
1951 AnalyzesOk(
"select d5 - d1 from functional.decimal_tbl");
1952 AnalyzesOk(
"select d2 * d2 from functional.decimal_tbl");
1953 AnalyzesOk(
"select d4 / d1 from functional.decimal_tbl");
1954 AnalyzesOk(
"select d2 % d5 from functional.decimal_tbl");
1957 "Invalid non-integer argument to operation '&': d1 & d1");
1959 "Invalid non-integer argument to operation '|': d1 | d1");
1961 "Invalid non-integer argument to operation '^': d1 ^ d1");
1963 "Bitwise operations only allowed on integer types: ~d1");
1965 AnalyzesOk(
"select d3 = d4 from functional.decimal_tbl");
1966 AnalyzesOk(
"select d5 != d1 from functional.decimal_tbl");
1967 AnalyzesOk(
"select d2 > d2 from functional.decimal_tbl");
1968 AnalyzesOk(
"select d4 >= d1 from functional.decimal_tbl");
1969 AnalyzesOk(
"select d2 < d5 from functional.decimal_tbl");
1970 AnalyzesOk(
"select d2 <= d5 from functional.decimal_tbl");
1978 AnalyzesOk(
"select cast(1 as decimal(1, 0))");
1979 AnalyzesOk(
"select cast(1 as decimal(10, 5))");
1980 AnalyzesOk(
"select cast(1 as decimal(38, 0))");
1981 AnalyzesOk(
"select cast(1 as decimal(38, 38))");
1984 "Decimal precision must be > 0: 0");
1986 "Decimal precision must be <= 38: 39");
1988 "Decimal scale (2) must be <= precision (1)");
1993 AnalyzesOk(
"select abs(cast(1 as decimal))");
1994 AnalyzesOk(
"select abs(cast(-1.1 as decimal(10,3)))");
1996 AnalyzesOk(
"select floor(cast(-1.1 as decimal(10,3)))");
1997 AnalyzesOk(
"select ceil(cast(1.123 as decimal(10,3)))");
1999 AnalyzesOk(
"select round(cast(1.123 as decimal(10,3)))");
2000 AnalyzesOk(
"select round(cast(1.123 as decimal(10,3)), 0)");
2001 AnalyzesOk(
"select round(cast(1.123 as decimal(10,3)), 2)");
2002 AnalyzesOk(
"select round(cast(1.123 as decimal(10,3)), 5)");
2003 AnalyzesOk(
"select round(cast(1.123 as decimal(10,3)), -2)");
2005 AnalyzesOk(
"select truncate(cast(1.123 as decimal(10,3)))");
2006 AnalyzesOk(
"select truncate(cast(1.123 as decimal(10,3)), 0)");
2007 AnalyzesOk(
"select truncate(cast(1.123 as decimal(10,3)), 2)");
2008 AnalyzesOk(
"select truncate(cast(1.123 as decimal(10,3)), 5)");
2009 AnalyzesOk(
"select truncate(cast(1.123 as decimal(10,3)), -1)");
2011 AnalysisError(
"select round(cast(1.123 as decimal(10,3)), 5.1)",
2012 "No matching function with signature: round(DECIMAL(10,3), DECIMAL(2,1))");
2013 AnalysisError(
"select round(cast(1.123 as decimal(30,20)), 40)",
2014 "Cannot round/truncate to scales greater than 38.");
2015 AnalysisError(
"select truncate(cast(1.123 as decimal(10,3)), 40)",
2016 "Cannot round/truncate to scales greater than 38.");
2017 AnalysisError(
"select round(cast(1.123 as decimal(10,3)), NULL)",
2018 "round() cannot be called with a NULL second argument.");
2021 AnalysisError(
"select precision(999999999999999999999999999999999999999.)",
2022 "No matching function with signature: precision(DOUBLE).");
2025 "No matching function with signature: precision(FLOAT)");
2028 "Cannot resolve DECIMAL precision and scale from NULL type.");
2030 "Cannot resolve DECIMAL precision and scale from NULL type.");
2057 StringBuilder exprStr =
new StringBuilder(prefix);
2058 for (
int i = 0; i < Expr.EXPR_DEPTH_LIMIT - 1; ++i) {
2059 exprStr.append(repeatSuffix);
2062 exprStr.append(repeatSuffix);
2064 String.format(
"Exceeded the maximum depth of an expression tree (%s).",
2068 for (
int i = 0; i < Expr.EXPR_DEPTH_LIMIT * 9; ++i) {
2069 exprStr.append(repeatSuffix);
2072 String.format(
"Exceeded the maximum depth of an expression tree (%s).",
2086 String.format(
"Exceeded the maximum depth of an expression tree (%s).",
2091 String.format(
"Exceeded the maximum depth of an expression tree (%s).",
2100 String closeFunc,
int numFuncs) {
2101 StringBuilder exprStr =
new StringBuilder();
2102 for (
int i = 0; i < numFuncs; ++i) {
2103 exprStr.append(openFunc);
2105 exprStr.append(baseArg);
2106 for (
int i = 0; i < numFuncs; ++i) {
2107 exprStr.append(closeFunc);
2109 return exprStr.toString();
2114 TQueryOptions queryOptions =
new TQueryOptions();
2115 queryOptions.setAppx_count_distinct(
true);
2118 List<String> countDistinctFns = Lists.newArrayList();
2120 List<String> allCountDistinctFns = Lists.newArrayList();
2122 Table alltypesTbl = catalog_.getTable(
"functional",
"alltypes");
2123 for (
Column col: alltypesTbl.getColumns()) {
2124 String colName = col.getName();
2127 "select count(distinct %s), sum(distinct smallint_col), " +
2128 "avg(float_col), min(%s) " +
2129 "from functional.alltypes",
2131 countDistinctFns.add(String.format(
"count(distinct %s)", colName));
2134 AnalyzesOk(String.format(
"select %s from functional.alltypes",
2135 Joiner.on(
",").join(countDistinctFns)),
createAnalyzer(queryOptions));
2137 allCountDistinctFns.addAll(countDistinctFns);
2138 countDistinctFns.clear();
2139 Table decimalTbl = catalog_.getTable(
"functional",
"decimal_tbl");
2140 for (
Column col: decimalTbl.getColumns()) {
2141 String colName = col.getName();
2144 "select count(distinct %s), sum(distinct d1), " +
2145 "avg(d2), min(%s) " +
2146 "from functional.decimal_tbl",
2148 countDistinctFns.add(String.format(
"count(distinct %s)", colName));
2151 AnalyzesOk(String.format(
"select %s from functional.decimal_tbl",
2152 Joiner.on(
",").join(countDistinctFns)),
createAnalyzer(queryOptions));
2154 allCountDistinctFns.addAll(countDistinctFns);
2159 "select %s from functional.alltypes cross join functional.decimal_tbl",
2160 Joiner.on(
",").join(countDistinctFns)),
createAnalyzer(queryOptions));
2163 AnalysisError(
"select count(distinct int_col, bigint_col), " +
2164 "count(distinct string_col, float_col) from functional.alltypes",
2166 "all DISTINCT aggregate functions need to have the same set of parameters as " +
2167 "count(DISTINCT int_col, bigint_col); deviating function: " +
2168 "count(DISTINCT string_col, float_col)");
2171 "select avg(distinct int_col), sum(distinct float_col) from functional.alltypes",
2173 "all DISTINCT aggregate functions need to have the same set of parameters as " +
2174 "avg(DISTINCT int_col); deviating function: sum(DISTINCT");
void TestDecimalArithmetic()
void TestExprChildLimit()
void TestTimestampArithmeticExpressions()
void TestComparisonTypeCasts()
void checkCasts(Expr expr)
static final ScalarType NULL
static final ScalarType BIGINT
static final int MAX_PRECISION
void TestFixedPointArithmeticOps()
SelectList getSelectList()
void testNumericLiteral(String literal, Type expectedType)
static final ScalarType STRING
void TestComplexTypeCasts()
Analyzer createAnalyzer(String defaultDb)
void TestFunctionCallExpr()
void checkExprType(String query, Type type)
static final ScalarType BOOLEAN
static final ScalarType DEFAULT_DECIMAL
void DoNotTestStringLiteralToDateCasts()
static ScalarType createVarcharType(int len)
void TestLikePredicates()
void TestConditionalExprs()
void TestCompoundPredicates()
void TestBooleanValueExprs()
static final ScalarType SMALLINT
static ScalarType createCharType(int len)
static final ScalarType FLOAT
ParseNode AnalyzesOk(String stmt)
void TestNumericLiteralMinMaxValues()
void assertCaseEquivalence(String caseSql, String decodeSql)
static final int EXPR_DEPTH_LIMIT
void testExprCast(String literal, Type expectedType)
void TestIsNullPredicates()
void TestExprDepthLimit()
void TestBinaryPredicates()
static final ScalarType DOUBLE
String getNestedFuncExpr(String openFunc, String baseArg, String closeFunc, int numFuncs)
void TestVarArgFunctions()
static final ScalarType TINYINT
static final ScalarType INT
void TestNullFunctionArguments()
void TestDecimalFunctions()
uint64_t Test(T *ht, const ProbeTuple *input, uint64_t num_tuples)
void TestTimestampValueExprs()
void TestDecimalOperators()
void TestBetweenPredicates()
static ScalarType createDecimalType()
void checkReturnType(String stmt, Type resultType)
void TestAppxCountDistinctOption()
void typeCastTest(Type type1, Type type2, boolean op1IsLiteral, ArithmeticExpr.Operator arithmeticOp, BinaryPredicate.Operator cmpOp, Type opType)
void TestNumericLiteralTypeResolution()
void TestArithmeticTypeCasts()
static final int EXPR_CHILDREN_LIMIT
void testInfixExprDepthLimit(String prefix, String repeatSuffix)
void testFuncExprDepthLimit(String openFunc, String baseArg, String closeFunc)
void AnalysisError(String stmt)
void testDecimalExpr(String expr, Type expectedType)
static ArrayList< ScalarType > getSupportedTypes()