[ 
https://issues.apache.org/jira/browse/BEAM-12473?focusedWorklogId=609653&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-609653
 ]

ASF GitHub Bot logged work on BEAM-12473:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 10/Jun/21 11:23
            Start Date: 10/Jun/21 11:23
    Worklog Time Spent: 10m 
      Work Description: je-ik commented on pull request #14986:
URL: https://github.com/apache/beam/pull/14986#issuecomment-858538776


   I'm not 100% sure this is the best solution. We should definitely not throw 
ClassCastException in the described case. My first iteration was to simply 
throw an exception explaining why this doesn't work, but then I realized, that 
by wrapping into anonymous subclass the problem can be solved. Not sure if the 
anonymous subclass should be created as well, but looks reusable and actually 
helps a lot (at least with JDK11+, where it is possible to create anonymous 
subclasses with diamond operator, so the user does not actually know that the 
accumulator of Max is `Combine.Holder<T>`, which is nice).


-- 
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: 609653)
    Time Spent: 20m  (was: 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: 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)

Reply via email to