ibzib commented on a change in pull request #12461:
URL: https://github.com/apache/beam/pull/12461#discussion_r465289699
##########
File path:
sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/BeamSqlDslUdfUdafTest.java
##########
@@ -101,6 +103,21 @@ public void testJodaTimeUdfUdaf() throws Exception {
pipeline.run().waitUntilFinish();
}
+ @Test
+ public void testListUdf() throws Exception {
+ Schema resultType = Schema.builder().addArrayField("array_field",
FieldType.INT64).build();
+
+ Row row1 = Row.withSchema(resultType).addValue(Arrays.asList(1L)).build();
Review comment:
Nit: why are row1, sql1, etc. variable names numbered when there's only
one of each?
##########
File path:
sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/utils/CalciteUtils.java
##########
@@ -285,16 +286,23 @@ private static RelDataType toRelDataType(
* SQL-Java type mapping, with specified Beam rules: <br>
* 1. redirect {@link AbstractInstant} to {@link Date} so Calcite can
recognize it.
*
- * @param rawType
+ * @param type
* @return
*/
- public static RelDataType sqlTypeWithAutoCast(RelDataTypeFactory
typeFactory, Type rawType) {
+ public static RelDataType sqlTypeWithAutoCast(RelDataTypeFactory
typeFactory, Type type) {
// For Joda time types, return SQL type for java.util.Date.
- if (rawType instanceof Class &&
AbstractInstant.class.isAssignableFrom((Class<?>) rawType)) {
+ if (type instanceof Class &&
AbstractInstant.class.isAssignableFrom((Class<?>) type)) {
return typeFactory.createJavaType(Date.class);
- } else if (rawType instanceof Class &&
ByteString.class.isAssignableFrom((Class<?>) rawType)) {
+ } else if (type instanceof Class &&
ByteString.class.isAssignableFrom((Class<?>) type)) {
return typeFactory.createJavaType(byte[].class);
+ } else if (type instanceof ParameterizedType
+ && java.util.List.class.isAssignableFrom(
+ (Class<?>) ((ParameterizedType) type).getRawType())) {
+ ParameterizedType parameterizedType = (ParameterizedType) type;
+ Class<?> genericType = (Class<?>)
parameterizedType.getActualTypeArguments()[0];
+ RelDataType collectionElementType =
typeFactory.createJavaType(genericType);
+ return typeFactory.createArrayType(collectionElementType, -1L);
Review comment:
```suggestion
return typeFactory.createArrayType(collectionElementType,
UNLIMITED_ARRAY_SIZE);
```
##########
File path:
sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/utils/CalciteUtils.java
##########
@@ -285,16 +286,23 @@ private static RelDataType toRelDataType(
* SQL-Java type mapping, with specified Beam rules: <br>
* 1. redirect {@link AbstractInstant} to {@link Date} so Calcite can
recognize it.
Review comment:
We should probably update this comment to explain how/why ByteString and
List are special cases.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]