Skip to content

Commit ecf0de3

Browse files
authored
SQL: Lowercase the datatypes in validation error msgs (elastic#37524)
To follow the ES convention display the datatypes in lowercase in error messages thrown during validation if `IN` and conditional functions.
1 parent 4e72f3c commit ecf0de3

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/analysis/analyzer/Verifier.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ private static void validateInExpression(LogicalPlan p, Set<Failure> localFailur
636636
for (Expression value : in.list()) {
637637
if (areTypesCompatible(dt, value.dataType()) == false) {
638638
localFailures.add(fail(value, "expected data type [%s], value provided is of type [%s]",
639-
dt, value.dataType()));
639+
dt.esType, value.dataType().esType));
640640
return;
641641
}
642642
}
@@ -657,7 +657,7 @@ private static void validateConditional(LogicalPlan p, Set<Failure> localFailure
657657
} else {
658658
if (areTypesCompatible(dt, child.dataType()) == false) {
659659
localFailures.add(fail(child, "expected data type [%s], value provided is of type [%s]",
660-
dt, child.dataType()));
660+
dt.esType, child.dataType().esType));
661661
return;
662662
}
663663
}
@@ -676,4 +676,4 @@ private static boolean areTypesCompatible(DataType left, DataType right) {
676676
(left.isNumeric() && right.isNumeric());
677677
}
678678
}
679-
}
679+
}

x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/analysis/analyzer/VerifierErrorMessagesTests.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -333,42 +333,42 @@ public void testHavingOnScalar() {
333333
}
334334

335335
public void testInWithDifferentDataTypes_SelectClause() {
336-
assertEquals("1:17: expected data type [INTEGER], value provided is of type [KEYWORD]",
336+
assertEquals("1:17: expected data type [integer], value provided is of type [keyword]",
337337
error("SELECT 1 IN (2, '3', 4)"));
338338
}
339339

340340
public void testInNestedWithDifferentDataTypes_SelectClause() {
341-
assertEquals("1:27: expected data type [INTEGER], value provided is of type [KEYWORD]",
341+
assertEquals("1:27: expected data type [integer], value provided is of type [keyword]",
342342
error("SELECT 1 = 1 OR 1 IN (2, '3', 4)"));
343343
}
344344

345345
public void testInWithDifferentDataTypesFromLeftValue_SelectClause() {
346-
assertEquals("1:14: expected data type [INTEGER], value provided is of type [KEYWORD]",
346+
assertEquals("1:14: expected data type [integer], value provided is of type [keyword]",
347347
error("SELECT 1 IN ('foo', 'bar')"));
348348
}
349349

350350
public void testInNestedWithDifferentDataTypesFromLeftValue_SelectClause() {
351-
assertEquals("1:29: expected data type [KEYWORD], value provided is of type [INTEGER]",
351+
assertEquals("1:29: expected data type [keyword], value provided is of type [integer]",
352352
error("SELECT 1 = 1 OR 'foo' IN (2, 3)"));
353353
}
354354

355355
public void testInWithDifferentDataTypes_WhereClause() {
356-
assertEquals("1:49: expected data type [TEXT], value provided is of type [INTEGER]",
356+
assertEquals("1:49: expected data type [text], value provided is of type [integer]",
357357
error("SELECT * FROM test WHERE text IN ('foo', 'bar', 4)"));
358358
}
359359

360360
public void testInNestedWithDifferentDataTypes_WhereClause() {
361-
assertEquals("1:60: expected data type [TEXT], value provided is of type [INTEGER]",
361+
assertEquals("1:60: expected data type [text], value provided is of type [integer]",
362362
error("SELECT * FROM test WHERE int = 1 OR text IN ('foo', 'bar', 2)"));
363363
}
364364

365365
public void testInWithDifferentDataTypesFromLeftValue_WhereClause() {
366-
assertEquals("1:35: expected data type [TEXT], value provided is of type [INTEGER]",
366+
assertEquals("1:35: expected data type [text], value provided is of type [integer]",
367367
error("SELECT * FROM test WHERE text IN (1, 2)"));
368368
}
369369

370370
public void testInNestedWithDifferentDataTypesFromLeftValue_WhereClause() {
371-
assertEquals("1:46: expected data type [TEXT], value provided is of type [INTEGER]",
371+
assertEquals("1:46: expected data type [text], value provided is of type [integer]",
372372
error("SELECT * FROM test WHERE int = 1 OR text IN (1, 2)"));
373373
}
374374

@@ -478,27 +478,27 @@ public void testConditionalWithDifferentDataTypes_SelectClause() {
478478
@SuppressWarnings("unchecked")
479479
String function = randomFrom(IfNull.class, NullIf.class).getSimpleName();
480480
assertEquals("1:" + (22 + function.length()) +
481-
": expected data type [INTEGER], value provided is of type [KEYWORD]",
481+
": expected data type [integer], value provided is of type [keyword]",
482482
error("SELECT 1 = 1 OR " + function + "(3, '4') > 1"));
483483

484484
@SuppressWarnings("unchecked")
485485
String arbirtraryArgsfunction = randomFrom(Coalesce.class, Greatest.class, Least.class).getSimpleName();
486486
assertEquals("1:" + (34 + arbirtraryArgsfunction.length()) +
487-
": expected data type [INTEGER], value provided is of type [KEYWORD]",
487+
": expected data type [integer], value provided is of type [keyword]",
488488
error("SELECT 1 = 1 OR " + arbirtraryArgsfunction + "(null, null, 3, '4') > 1"));
489489
}
490490

491491
public void testConditionalWithDifferentDataTypes_WhereClause() {
492492
@SuppressWarnings("unchecked")
493493
String function = randomFrom(IfNull.class, NullIf.class).getSimpleName();
494494
assertEquals("1:" + (34 + function.length()) +
495-
": expected data type [KEYWORD], value provided is of type [INTEGER]",
495+
": expected data type [keyword], value provided is of type [integer]",
496496
error("SELECT * FROM test WHERE " + function + "('foo', 4) > 1"));
497497

498498
@SuppressWarnings("unchecked")
499499
String arbirtraryArgsfunction = randomFrom(Coalesce.class, Greatest.class, Least.class).getSimpleName();
500500
assertEquals("1:" + (46 + arbirtraryArgsfunction.length()) +
501-
": expected data type [KEYWORD], value provided is of type [INTEGER]",
501+
": expected data type [keyword], value provided is of type [integer]",
502502
error("SELECT * FROM test WHERE " + arbirtraryArgsfunction + "(null, null, 'foo', 4) > 1"));
503503
}
504504

0 commit comments

Comments
 (0)