You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "Zhipeng Zhang (Jira)" <ji...@apache.org> on 2022/06/08 07:41:00 UTC

[jira] [Created] (FLINK-27952) Table UDF fails when using Double.POSITIVE_INFINITY as parameters

Zhipeng Zhang created FLINK-27952:
-------------------------------------

             Summary: Table UDF fails when using Double.POSITIVE_INFINITY as parameters
                 Key: FLINK-27952
                 URL: https://issues.apache.org/jira/browse/FLINK-27952
             Project: Flink
          Issue Type: New Feature
          Components: Table SQL / Planner
            Reporter: Zhipeng Zhang


The following code fails and throws NumberFormatException when casting Double.POSITIVE_INFINITY to BigDecimal.

 

@Test
public void testTableUdf() {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        DataStream <Row> data = env.fromElements(Row.of(1.), Row.of(2.));
        StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);
        Table table = tEnv.fromDataStream(data).as("f0");
        Double[][] d = new Double[][]\{new Double[]{1.0, Double.POSITIVE_INFINITY}};
        Expression[] expressions = new Expression[2];
        expressions[0] = org.apache.flink.table.api.Expressions.call(MyUDF.class, $("f0"), d);
        expressions[1] = org.apache.flink.table.api.Expressions.call(MyUDF.class, $("f0"), d);
        table.addColumns(expressions)
            .as("f0", "output", "output2")
            .execute().print();
    }

public static class MyUDF extends ScalarFunction {
        public Integer eval(Integer num, Double[][] add) {
            return (int)(num + add[0][0]);
        }
    }



--
This message was sent by Atlassian Jira
(v8.20.7#820007)