snuyanzin commented on code in PR #20546:
URL: https://github.com/apache/flink/pull/20546#discussion_r948706751


##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/table/GenerateSeriesFunction.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.flink.table.runtime.functions.table;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.functions.BuiltInFunctionDefinitions;
+import org.apache.flink.table.functions.SpecializedFunction.SpecializedContext;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.table.types.logical.utils.LogicalTypeMerging;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * GenerateSeries implements the table function `generate_series(start, stop)`
+ * `generate_series(start, * stop, step)` which generate a series of values, 
from start to stop with
+ * a step size.
+ */
+@Internal
+public class GenerateSeriesFunction extends BuiltInTableFunction<Object> {
+
+    private static final long serialVersionUID = 1L;
+
+    private final transient DataType outputDataType;
+    private final LogicalType outputLogicalType;
+
+    public GenerateSeriesFunction(SpecializedContext specializedContext) {
+        super(BuiltInFunctionDefinitions.GENERATE_SERIES, specializedContext);
+
+        // The output type in the context is already wrapped, however, the 
result of the
+        // function is not. Therefore, we need a custom output type.
+        final List<LogicalType> actualTypes =
+                
specializedContext.getCallContext().getArgumentDataTypes().stream()
+                        .map(DataType::getLogicalType)
+                        .collect(Collectors.toList());
+        this.outputLogicalType = 
LogicalTypeMerging.findCommonType(actualTypes).get();
+        this.outputDataType = DataTypes.of(outputLogicalType).toInternal();
+    }
+
+    @Override
+    public DataType getOutputDataType() {
+        return outputDataType;
+    }
+
+    public void eval(Number start, Number stop) {
+        eval(start, stop, 1);
+    }
+
+    public void eval(Number start, Number stop, Number step) {
+        if (isZero(step.doubleValue(), 0.000001)) {
+            throw new IllegalArgumentException("step size cannot equal zero");
+        }
+
+        double s = start.doubleValue();

Review Comment:
   Could we expect here `BigDecimal`/`DECIMAL` and if yes how will it wokr?



##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/table/GenerateSeriesFunction.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.flink.table.runtime.functions.table;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.functions.BuiltInFunctionDefinitions;
+import org.apache.flink.table.functions.SpecializedFunction.SpecializedContext;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.table.types.logical.utils.LogicalTypeMerging;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * GenerateSeries implements the table function `generate_series(start, stop)`
+ * `generate_series(start, * stop, step)` which generate a series of values, 
from start to stop with
+ * a step size.
+ */
+@Internal
+public class GenerateSeriesFunction extends BuiltInTableFunction<Object> {
+
+    private static final long serialVersionUID = 1L;
+
+    private final transient DataType outputDataType;
+    private final LogicalType outputLogicalType;
+
+    public GenerateSeriesFunction(SpecializedContext specializedContext) {
+        super(BuiltInFunctionDefinitions.GENERATE_SERIES, specializedContext);
+
+        // The output type in the context is already wrapped, however, the 
result of the
+        // function is not. Therefore, we need a custom output type.
+        final List<LogicalType> actualTypes =
+                
specializedContext.getCallContext().getArgumentDataTypes().stream()
+                        .map(DataType::getLogicalType)
+                        .collect(Collectors.toList());
+        this.outputLogicalType = 
LogicalTypeMerging.findCommonType(actualTypes).get();
+        this.outputDataType = DataTypes.of(outputLogicalType).toInternal();
+    }
+
+    @Override
+    public DataType getOutputDataType() {
+        return outputDataType;
+    }
+
+    public void eval(Number start, Number stop) {
+        eval(start, stop, 1);
+    }
+
+    public void eval(Number start, Number stop, Number step) {
+        if (isZero(step.doubleValue(), 0.000001)) {
+            throw new IllegalArgumentException("step size cannot equal zero");
+        }
+
+        double s = start.doubleValue();

Review Comment:
   Could we expect here `BigDecimal`/`DECIMAL` and if yes how will it work?



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to