11
11
import org .elasticsearch .xpack .sql .analysis .index .IndexResolution ;
12
12
import org .elasticsearch .xpack .sql .analysis .index .IndexResolverTests ;
13
13
import org .elasticsearch .xpack .sql .expression .function .FunctionRegistry ;
14
+ import org .elasticsearch .xpack .sql .expression .function .scalar .math .Round ;
15
+ import org .elasticsearch .xpack .sql .expression .function .scalar .math .Truncate ;
16
+ import org .elasticsearch .xpack .sql .expression .function .scalar .string .Char ;
17
+ import org .elasticsearch .xpack .sql .expression .function .scalar .string .Space ;
14
18
import org .elasticsearch .xpack .sql .expression .predicate .conditional .Coalesce ;
15
19
import org .elasticsearch .xpack .sql .expression .predicate .conditional .Greatest ;
16
20
import org .elasticsearch .xpack .sql .expression .predicate .conditional .IfNull ;
23
27
import org .elasticsearch .xpack .sql .type .EsField ;
24
28
import org .elasticsearch .xpack .sql .type .TypesTests ;
25
29
30
+ import java .util .Arrays ;
26
31
import java .util .LinkedHashMap ;
32
+ import java .util .Locale ;
27
33
import java .util .Map ;
28
34
29
35
import static java .util .Collections .emptyMap ;
@@ -473,13 +479,18 @@ public void testInvalidTypeForStringFunction_WithOneArgString() {
473
479
}
474
480
475
481
public void testInvalidTypeForStringFunction_WithOneArgNumeric () {
476
- assertEquals ("1:8: argument of [CHAR('foo')] must be [integer], found value ['foo'] type [keyword]" ,
477
- error ("SELECT CHAR('foo')" ));
482
+ String functionName = randomFrom (Arrays .asList (Char .class , Space .class )).getSimpleName ().toUpperCase (Locale .ROOT );
483
+ assertEquals ("1:8: argument of [" + functionName + "('foo')] must be [integer], found value ['foo'] type [keyword]" ,
484
+ error ("SELECT " + functionName + "('foo')" ));
485
+ assertEquals ("1:8: argument of [" + functionName + "(1.2)] must be [integer], found value [1.2] type [double]" ,
486
+ error ("SELECT " + functionName + "(1.2)" ));
478
487
}
479
488
480
489
public void testInvalidTypeForNestedStringFunctions_WithOneArg () {
481
- assertEquals ("1:14: argument of [CHAR('foo')] must be [integer], found value ['foo'] type [keyword]" ,
482
- error ("SELECT ASCII(CHAR('foo'))" ));
490
+ assertEquals ("1:15: argument of [SPACE('foo')] must be [integer], found value ['foo'] type [keyword]" ,
491
+ error ("SELECT LENGTH(SPACE('foo'))" ));
492
+ assertEquals ("1:15: argument of [SPACE(1.2)] must be [integer], found value [1.2] type [double]" ,
493
+ error ("SELECT LENGTH(SPACE(1.2))" ));
483
494
}
484
495
485
496
public void testInvalidTypeForNumericFunction_WithOneArg () {
@@ -500,10 +511,13 @@ public void testInvalidTypeForStringFunction_WithTwoArgs() {
500
511
}
501
512
502
513
public void testInvalidTypeForNumericFunction_WithTwoArgs () {
503
- assertEquals ("1:8: first argument of [TRUNCATE('foo', 2)] must be [numeric], found value ['foo'] type [keyword]" ,
504
- error ("SELECT TRUNCATE('foo', 2)" ));
505
- assertEquals ("1:8: second argument of [TRUNCATE(1.2, 'bar')] must be [integer], found value ['bar'] type [keyword]" ,
506
- error ("SELECT TRUNCATE(1.2, 'bar')" ));
514
+ String functionName = randomFrom (Arrays .asList (Round .class , Truncate .class )).getSimpleName ().toUpperCase (Locale .ROOT );
515
+ assertEquals ("1:8: first argument of [" + functionName + "('foo', 2)] must be [numeric], found value ['foo'] type [keyword]" ,
516
+ error ("SELECT " + functionName + "('foo', 2)" ));
517
+ assertEquals ("1:8: second argument of [" + functionName + "(1.2, 'bar')] must be [integer], found value ['bar'] type [keyword]" ,
518
+ error ("SELECT " + functionName + "(1.2, 'bar')" ));
519
+ assertEquals ("1:8: second argument of [" + functionName + "(1.2, 3.4)] must be [integer], found value [3.4] type [double]" ,
520
+ error ("SELECT " + functionName + "(1.2, 3.4)" ));
507
521
}
508
522
509
523
public void testInvalidTypeForBooleanFuntion_WithTwoArgs () {
@@ -542,9 +556,13 @@ public void testInvalidTypeForSubString() {
542
556
543
557
assertEquals ("1:8: second argument of [SUBSTRING('foo', 'bar', 3)] must be [integer], found value ['bar'] type [keyword]" ,
544
558
error ("SELECT SUBSTRING('foo', 'bar', 3)" ));
559
+ assertEquals ("1:8: second argument of [SUBSTRING('foo', 1.2, 3)] must be [integer], found value [1.2] type [double]" ,
560
+ error ("SELECT SUBSTRING('foo', 1.2, 3)" ));
545
561
546
562
assertEquals ("1:8: third argument of [SUBSTRING('foo', 2, 'bar')] must be [integer], found value ['bar'] type [keyword]" ,
547
563
error ("SELECT SUBSTRING('foo', 2, 'bar')" ));
564
+ assertEquals ("1:8: third argument of [SUBSTRING('foo', 2, 3.4)] must be [integer], found value [3.4] type [double]" ,
565
+ error ("SELECT SUBSTRING('foo', 2, 3.4)" ));
548
566
}
549
567
550
568
public void testInvalidTypeForFunction_WithFourArgs () {
0 commit comments