1111import org .elasticsearch .xpack .sql .analysis .index .IndexResolution ;
1212import org .elasticsearch .xpack .sql .analysis .index .IndexResolverTests ;
1313import 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 ;
1418import org .elasticsearch .xpack .sql .expression .predicate .conditional .Coalesce ;
1519import org .elasticsearch .xpack .sql .expression .predicate .conditional .Greatest ;
1620import org .elasticsearch .xpack .sql .expression .predicate .conditional .IfNull ;
2327import org .elasticsearch .xpack .sql .type .EsField ;
2428import org .elasticsearch .xpack .sql .type .TypesTests ;
2529
30+ import java .util .Arrays ;
2631import java .util .LinkedHashMap ;
32+ import java .util .Locale ;
2733import java .util .Map ;
2834
2935import static java .util .Collections .emptyMap ;
@@ -471,13 +477,18 @@ public void testInvalidTypeForStringFunction_WithOneArgString() {
471477 }
472478
473479 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)" ));
476485 }
477486
478487 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))" ));
481492 }
482493
483494 public void testInvalidTypeForNumericFunction_WithOneArg () {
@@ -498,10 +509,13 @@ public void testInvalidTypeForStringFunction_WithTwoArgs() {
498509 }
499510
500511 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)" ));
505519 }
506520
507521 public void testInvalidTypeForBooleanFuntion_WithTwoArgs () {
@@ -540,9 +554,13 @@ public void testInvalidTypeForSubString() {
540554
541555 assertEquals ("1:8: second argument of [SUBSTRING('foo', 'bar', 3)] must be [integer], found value ['bar'] type [keyword]" ,
542556 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)" ));
543559
544560 assertEquals ("1:8: third argument of [SUBSTRING('foo', 2, 'bar')] must be [integer], found value ['bar'] type [keyword]" ,
545561 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)" ));
546564 }
547565
548566 public void testInvalidTypeForFunction_WithFourArgs () {
0 commit comments