dylanhz commented on code in PR #25053:
URL: https://github.com/apache/flink/pull/25053#discussion_r1700049564


##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/MathFunctionsITCase.java:
##########


Review Comment:
   Considering the problem about return type, maybe we need some corner cases 
for different input type, such as:
   - shiftleft(1, 31)
   - shiftleft(1, 32)
   - shiftleft((byte)1, 10)
   - shiftleft((short)1, 20)
   - ...



##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/functions/BuiltInFunctionDefinitions.java:
##########
@@ -1830,6 +1830,32 @@ ANY, and(logical(LogicalTypeRoot.BOOLEAN), LITERAL)
                     
.outputTypeStrategy(nullableIfArgs(SpecificTypeStrategies.ROUND))
                     .build();
 
+    public static final BuiltInFunctionDefinition SHIFTLEFT =
+            BuiltInFunctionDefinition.newBuilder()
+                    .name("shiftleft")
+                    .kind(SCALAR)
+                    .inputTypeStrategy(
+                            sequence(
+                                    logical(LogicalTypeFamily.INTEGER_NUMERIC, 
true),
+                                    logical(LogicalTypeFamily.INTEGER_NUMERIC, 
true)))
+                    
.outputTypeStrategy(nullableIfArgs(explicit(DataTypes.BIGINT())))

Review Comment:
   I'm not sure about the return type. In Spark and Hive, `tinyint/smallint/int 
-> int` and `bigint -> bigint`. Considering this is a very basic function, 
maybe we need a more general design to align with other products.
   
   



##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/functions/BuiltInFunctionDefinitions.java:
##########
@@ -1830,6 +1830,32 @@ ANY, and(logical(LogicalTypeRoot.BOOLEAN), LITERAL)
                     
.outputTypeStrategy(nullableIfArgs(SpecificTypeStrategies.ROUND))
                     .build();
 
+    public static final BuiltInFunctionDefinition SHIFTLEFT =
+            BuiltInFunctionDefinition.newBuilder()
+                    .name("shiftleft")
+                    .kind(SCALAR)
+                    .inputTypeStrategy(
+                            sequence(
+                                    logical(LogicalTypeFamily.INTEGER_NUMERIC, 
true),
+                                    logical(LogicalTypeFamily.INTEGER_NUMERIC, 
true)))

Review Comment:
   Can you explain why using `true` here? I think this param takes effect only 
when it's `false`.



##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/functions/BuiltInFunctionDefinitions.java:
##########
@@ -1830,6 +1830,32 @@ ANY, and(logical(LogicalTypeRoot.BOOLEAN), LITERAL)
                     
.outputTypeStrategy(nullableIfArgs(SpecificTypeStrategies.ROUND))
                     .build();
 
+    public static final BuiltInFunctionDefinition SHIFTLEFT =
+            BuiltInFunctionDefinition.newBuilder()
+                    .name("shiftleft")

Review Comment:
   Function name in new stack should be upper case with underline like 
SHIFTLEFT.
   See https://issues.apache.org/jira/browse/FLINK-23384.



##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/functions/BuiltInFunctionDefinitions.java:
##########
@@ -1830,6 +1830,32 @@ ANY, and(logical(LogicalTypeRoot.BOOLEAN), LITERAL)
                     
.outputTypeStrategy(nullableIfArgs(SpecificTypeStrategies.ROUND))
                     .build();
 
+    public static final BuiltInFunctionDefinition SHIFTLEFT =
+            BuiltInFunctionDefinition.newBuilder()
+                    .name("shiftleft")
+                    .kind(SCALAR)
+                    .inputTypeStrategy(
+                            sequence(

Review Comment:
   I think we should use the sequence method with param names to make error 
info more clear.
   Take function IFNULL as a reference.



##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/scalar/BitLeftShiftFunction.java:
##########
@@ -0,0 +1,46 @@
+/*
+ * 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.scalar;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.table.functions.BuiltInFunctionDefinitions;
+import org.apache.flink.table.functions.SpecializedFunction;
+
+import javax.annotation.Nullable;
+
+/** Implementation of {@link BuiltInFunctionDefinitions#SHIFTLEFT}. */
+@Internal
+public class BitLeftShiftFunction extends BuiltInScalarFunction {
+
+    public BitLeftShiftFunction(SpecializedFunction.SpecializedContext 
context) {
+        super(BuiltInFunctionDefinitions.SHIFTLEFT, context);
+    }
+
+    public @Nullable Long eval(Object operand, Object shiftBits) {
+        if (operand == null || shiftBits == null) {
+            return null;
+        }
+        Number operandNumber = (Number) operand;
+        Number shiftBitsNumber = (Number) shiftBits;

Review Comment:
   Can we just use `Number` as param type? Since we only have to support 
`Byte/Short/Integer/Long`.



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