viirya commented on a change in pull request #32407:
URL: https://github.com/apache/spark/pull/32407#discussion_r627864707



##########
File path: 
sql/core/src/test/java/test/org/apache/spark/sql/connector/catalog/functions/JavaLongAdd.java
##########
@@ -0,0 +1,130 @@
+/*
+ * 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 test.org.apache.spark.sql.connector.catalog.functions;
+
+import org.apache.spark.sql.catalyst.InternalRow;
+import org.apache.spark.sql.connector.catalog.functions.BoundFunction;
+import org.apache.spark.sql.connector.catalog.functions.ScalarFunction;
+import org.apache.spark.sql.connector.catalog.functions.UnboundFunction;
+import org.apache.spark.sql.types.DataType;
+import org.apache.spark.sql.types.DataTypes;
+import org.apache.spark.sql.types.LongType;
+import org.apache.spark.sql.types.StructField;
+import org.apache.spark.sql.types.StructType;
+
+public class JavaLongAdd implements UnboundFunction {
+  private final ScalarFunction<Long> impl;
+
+  public JavaLongAdd(ScalarFunction<Long> impl) {
+    this.impl = impl;
+  }
+
+  @Override
+  public String name() {
+    return "long_add";
+  }
+
+  @Override
+  public BoundFunction bind(StructType inputType) {
+    if (inputType.fields().length != 2) {
+      throw new UnsupportedOperationException("Expect two arguments");
+    }
+    StructField[] fields = inputType.fields();
+    if (!(fields[0].dataType() instanceof LongType)) {
+      throw new UnsupportedOperationException("Expect first argument to be 
LongType");
+    }
+    if (!(fields[1].dataType() instanceof LongType)) {
+      throw new UnsupportedOperationException("Expect second argument to be 
LongType");
+    }
+    return impl;
+  }
+
+  @Override
+  public String description() {
+    return "long_add";
+  }
+
+  private abstract static class JavaLongAddBase implements 
ScalarFunction<Long> {
+    private final boolean isResultNullable;
+
+    JavaLongAddBase(boolean isResultNullable) {
+      this.isResultNullable = isResultNullable;
+    }
+
+    @Override
+    public DataType[] inputTypes() {
+      return new DataType[] { DataTypes.LongType, DataTypes.LongType };
+    }
+
+    @Override
+    public DataType resultType() {
+      return DataTypes.LongType;
+    }
+
+    @Override
+    public boolean isResultNullable() {
+      return isResultNullable;
+    }
+  }
+
+  public static class JavaLongAddDefault extends JavaLongAddBase {
+    public JavaLongAddDefault(boolean isResultNullable) {
+      super(isResultNullable);
+    }
+
+    @Override
+    public String name() {
+      return "long_add_default";
+    }
+
+    @Override
+    public Long produceResult(InternalRow input) {
+      return input.getLong(0) + input.getLong(1);
+    }
+  }
+
+  public static class JavaLongAddMagic extends JavaLongAddBase {
+    public JavaLongAddMagic(boolean isResultNullable) {
+      super(isResultNullable);
+    }
+
+    @Override
+    public String name() {
+      return "add_long_magic";

Review comment:
       long_add_magic? To be consistent with other naming.




-- 
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:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to