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 ;
@@ -471,13 +477,18 @@ public void testInvalidTypeForStringFunction_WithOneArgString() {
471
477
}
472
478
473
479
public void testInvalidTypeForStringFunction_WithOneArgNumeric () {
474
- assertEquals ("1:8: argument of [CHAR('foo')] must be [integer], found value ['foo'] type [keyword]" ,
475
- error ("SELECT CHAR('foo')" ));
480
+ String functionName = randomFrom (Arrays .asList (Char .class , Space .class )).getSimpleName ().toUpperCase (Locale .ROOT );
481
+ assertEquals ("1:8: argument of [" + functionName + "('foo')] must be [integer], found value ['foo'] type [keyword]" ,
482
+ error ("SELECT " + functionName + "('foo')" ));
483
+ assertEquals ("1:8: argument of [" + functionName + "(1.2)] must be [integer], found value [1.2] type [double]" ,
484
+ error ("SELECT " + functionName + "(1.2)" ));
476
485
}
477
486
478
487
public void testInvalidTypeForNestedStringFunctions_WithOneArg () {
479
- assertEquals ("1:14: argument of [CHAR('foo')] must be [integer], found value ['foo'] type [keyword]" ,
480
- error ("SELECT ASCII(CHAR('foo'))" ));
488
+ assertEquals ("1:15: argument of [SPACE('foo')] must be [integer], found value ['foo'] type [keyword]" ,
489
+ error ("SELECT LENGTH(SPACE('foo'))" ));
490
+ assertEquals ("1:15: argument of [SPACE(1.2)] must be [integer], found value [1.2] type [double]" ,
491
+ error ("SELECT LENGTH(SPACE(1.2))" ));
481
492
}
482
493
483
494
public void testInvalidTypeForNumericFunction_WithOneArg () {
@@ -498,10 +509,13 @@ public void testInvalidTypeForStringFunction_WithTwoArgs() {
498
509
}
499
510
500
511
public void testInvalidTypeForNumericFunction_WithTwoArgs () {
501
- assertEquals ("1:8: first argument of [TRUNCATE('foo', 2)] must be [numeric], found value ['foo'] type [keyword]" ,
502
- error ("SELECT TRUNCATE('foo', 2)" ));
503
- assertEquals ("1:8: second argument of [TRUNCATE(1.2, 'bar')] must be [integer], found value ['bar'] type [keyword]" ,
504
- error ("SELECT TRUNCATE(1.2, 'bar')" ));
512
+ String functionName = randomFrom (Arrays .asList (Round .class , Truncate .class )).getSimpleName ().toUpperCase (Locale .ROOT );
513
+ assertEquals ("1:8: first argument of [" + functionName + "('foo', 2)] must be [numeric], found value ['foo'] type [keyword]" ,
514
+ error ("SELECT " + functionName + "('foo', 2)" ));
515
+ assertEquals ("1:8: second argument of [" + functionName + "(1.2, 'bar')] must be [integer], found value ['bar'] type [keyword]" ,
516
+ error ("SELECT " + functionName + "(1.2, 'bar')" ));
517
+ assertEquals ("1:8: second argument of [" + functionName + "(1.2, 3.4)] must be [integer], found value [3.4] type [double]" ,
518
+ error ("SELECT " + functionName + "(1.2, 3.4)" ));
505
519
}
506
520
507
521
public void testInvalidTypeForBooleanFuntion_WithTwoArgs () {
@@ -540,9 +554,13 @@ public void testInvalidTypeForSubString() {
540
554
541
555
assertEquals ("1:8: second argument of [SUBSTRING('foo', 'bar', 3)] must be [integer], found value ['bar'] type [keyword]" ,
542
556
error ("SELECT SUBSTRING('foo', 'bar', 3)" ));
557
+ assertEquals ("1:8: second argument of [SUBSTRING('foo', 1.2, 3)] must be [integer], found value [1.2] type [double]" ,
558
+ error ("SELECT SUBSTRING('foo', 1.2, 3)" ));
543
559
544
560
assertEquals ("1:8: third argument of [SUBSTRING('foo', 2, 'bar')] must be [integer], found value ['bar'] type [keyword]" ,
545
561
error ("SELECT SUBSTRING('foo', 2, 'bar')" ));
562
+ assertEquals ("1:8: third argument of [SUBSTRING('foo', 2, 3.4)] must be [integer], found value [3.4] type [double]" ,
563
+ error ("SELECT SUBSTRING('foo', 2, 3.4)" ));
546
564
}
547
565
548
566
public void testInvalidTypeForFunction_WithFourArgs () {
0 commit comments