[
https://issues.apache.org/jira/browse/BEAM-12473?focusedWorklogId=610938&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-610938
]
ASF GitHub Bot logged work on BEAM-12473:
-----------------------------------------
Author: ASF GitHub Bot
Created on: 14/Jun/21 21:17
Start Date: 14/Jun/21 21:17
Worklog Time Spent: 10m
Work Description: ibzib commented on a change in pull request #14986:
URL: https://github.com/apache/beam/pull/14986#discussion_r651280045
##########
File path:
sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/UdfTypeUtils.java
##########
@@ -0,0 +1,144 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.extensions.sql;
+
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
+import java.util.Optional;
+import javax.annotation.Nullable;
+import org.apache.beam.sdk.coders.CannotProvideCoderException;
+import org.apache.beam.sdk.coders.Coder;
+import org.apache.beam.sdk.coders.CoderRegistry;
+import org.apache.beam.sdk.transforms.Combine;
+import org.apache.beam.sdk.transforms.display.DisplayData;
+import org.apache.beam.sdk.values.TypeDescriptor;
+
+public class UdfTypeUtils {
Review comment:
`org.apache.beam.sdk.extensions.sql.udf` is set aside for a newer
version of the UDF API (it uses
[AggregateFn](https://github.com/apache/beam/blob/master/sdks/java/extensions/sql/udf/src/main/java/org/apache/beam/sdk/extensions/sql/udf/AggregateFn.java)
instead of CombineFn for aggregates).
Since there is nothing SQL-specific about this solution, we might consider
moving the class into the core Java SDK (`org.apache.beam.sdk.util`).
--
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]
Issue Time Tracking
-------------------
Worklog Id: (was: 610938)
Time Spent: 1h 20m (was: 1h 10m)
> ClassCastException when using registerUdaf in Calcite SQL
> ---------------------------------------------------------
>
> Key: BEAM-12473
> URL: https://issues.apache.org/jira/browse/BEAM-12473
> Project: Beam
> Issue Type: Bug
> Components: dsl-sql
> Affects Versions: 2.31.0
> Reporter: Jan Lukavský
> Assignee: Jan Lukavský
> Priority: P2
> Time Spent: 1h 20m
> Remaining Estimate: 0h
>
> When using {{registerUdaf}} as follows:
> {code:java}
> .registerUdaf(
> "LONGEST_WORD",
> Max.of(
> (Comparator<String> & Serializable)
> (String a, String b) ->
> Integer.compare(a.length(), b.length()))))
> {code}
> results in following exception:
> {noformat}
> Caused by: java.lang.ClassCastException: class
> sun.reflect.generics.reflectiveObjects.TypeVariableImpl cannot be cast to
> class java.lang.Class
> (sun.reflect.generics.reflectiveObjects.TypeVariableImpl and java.lang.Class
> are in module java.base of loader 'bootstrap')
> at
> org.apache.beam.sdk.extensions.sql.impl.utils.CalciteUtils.sqlTypeWithAutoCast(CalciteUtils.java:327)
> at
> org.apache.beam.sdk.extensions.sql.impl.UdafImpl$1.getType(UdafImpl.java:73)
> at
> org.apache.beam.vendor.calcite.v1_20_0.org.apache.calcite.prepare.CalciteCatalogReader.toOp(CalciteCatalogReader.java:315)
> at
> org.apache.beam.vendor.calcite.v1_20_0.org.apache.calcite.prepare.CalciteCatalogReader.toOp(CalciteCatalogReader.java:302)
> at
> org.apache.beam.vendor.calcite.v1_20_0.org.apache.calcite.prepare.CalciteCatalogReader.lambda$lookupOperatorOverloads$3(CalciteCatalogReader.java:271)
> at
> java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
> at
> java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
> {noformat}
> If this way of registering UDAF is not supported, it should throw a more
> user-friendly exception.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)