Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request]: UDF supports lambda & RecordType parameter #27465

Closed
1 of 15 tasks
gabrywu opened this issue Jul 12, 2023 · 2 comments
Closed
1 of 15 tasks

[Feature Request]: UDF supports lambda & RecordType parameter #27465

gabrywu opened this issue Jul 12, 2023 · 2 comments

Comments

@gabrywu
Copy link
Member

gabrywu commented Jul 12, 2023

What would you like to happen?

I want to create a new UDF which supports a lambda parameter and a Row parameter, for example

static class LambdaUDFA implements BeamSqlUdf {
        public static List<Row> eval(@Parameter(name = "rows") List<Row> rows,
                                     @Parameter(name = "filter") Predicate1<Row> filter) {
            return rows.stream().filter(filter::apply).collect(Collectors.toList());
        }
    }

But beam SQL throws an exception like this
sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to java.lang.Class

Issue Priority

Priority: 2 (default / most feature requests should be filed as P2)

Issue Components

  • Component: Python SDK
  • Component: Java SDK
  • Component: Go SDK
  • Component: Typescript SDK
  • Component: IO connector
  • Component: Beam examples
  • Component: Beam playground
  • Component: Beam katas
  • Component: Website
  • Component: Spark Runner
  • Component: Flink Runner
  • Component: Samza Runner
  • Component: Twister2 Runner
  • Component: Hazelcast Jet Runner
  • Component: Google Cloud Dataflow Runner
@gabrywu gabrywu changed the title [Feature Request]: UDF supports lambda parameter [Feature Request]: UDF supports lambda & row parameter Jul 12, 2023
@gabrywu gabrywu changed the title [Feature Request]: UDF supports lambda & row parameter [Feature Request]: UDF supports lambda & RecordType parameter Jul 12, 2023
@Amar3tto
Copy link
Contributor

There are some difficulties in supporting UDFs with @Parameter(...) Row and @Parameter(...) Predicate1:

  1. Each parameter type should be translatable to Calcite RelDataType.
  2. If we want to translate Row type to Calcite RelRecordType, then we need to have an ability to somehow pass a Schema of that Row. This is currently not implemented in registering UDFs.
  3. There is no an appropriate Calcite RelDataType for lambda types.
  4. At the moment when UDF is applied, we have all Rows in form of Object[]. And Object[] cannot be automatically cast to Row.

@Amar3tto
Copy link
Contributor

@gabrywu FYI

@gabrywu gabrywu closed this as completed Jul 11, 2024
@github-actions github-actions bot added this to the 2.59.0 Release milestone Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants