MasseGuillaume commented on code in PR #3231:
URL: https://github.com/apache/calcite/pull/3231#discussion_r1210997503
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -7909,6 +7909,45 @@ private static void
checkArrayConcatAggFuncFails(SqlOperatorFixture t) {
"17357000", "BIGINT NOT NULL");
}
+ @Test void testNamedStruct() {
+ final SqlOperatorFixture f = fixture().withLibrary(SqlLibrary.SPARK);
+ f.setFor(SqlLibraryOperators.NAMED_STRUCT, VmName.EXPAND);
+
+ f.checkFails(
+ "^named_struct()^",
+ "named_struct requires at least 2 arguments",
+ false);
+
+ f.checkFails(
+ "^named_struct('k1', 1, 'k2')^",
+ "named_struct requires an even number for arguments",
+ false);
+
+ f.checkType(
+ "named_struct('k', 1)",
+ "RecordType(INTEGER NOT NULL k) NOT NULL");
+
+ f.checkType(
+ "named_struct('k1', 1, 'k2', 2)",
+ "RecordType(INTEGER NOT NULL k1, INTEGER NOT NULL k2) NOT NULL");
+
+ f.checkFails(
+ "^named_struct('k1', 1, 2, 3)^",
+ "named_struct key is not a string literal, found type 'BigDecimal'",
+ false);
+
+ // named_struct keys can be expression that can constant fold to a string
+ // in Apache Spark, we do not support it for simplicity
+ // scala> spark.sql("select named_struct('k' || '1', 1) as s").printSchema
+ // root
+ // |-- s: struct (nullable = false)
+ // | |-- k1: integer (nullable = false)
+ f.checkFails(
+ "^named_struct('k1', 1, 'k' || '1', 2)^",
+ "named_struct key is not a string literal, got an expression",
+ false);
+ }
Review Comment:
Is there a way to get the position of the parameters via
`SqlOperatorBinding`?
For example, I was trying to get more precision positions on the test
failures:
```
f.checkFails(
"named_struct('k1', 1, ^2^, 3)",
"named_struct key is not a string literal, found type 'BigDecimal'",
false);
f.checkFails(
"named_struct('k1', 1, ^'k' || '1'^, 2)",
"named_struct key is not a string literal, got an expression",
false);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]