RussellSpitzer commented on code in PR #5824:
URL: https://github.com/apache/iceberg/pull/5824#discussion_r1021622062


##########
spark/v3.3/spark/src/main/java/org/apache/iceberg/spark/actions/SparkHilbertUDF.java:
##########
@@ -0,0 +1,243 @@
+/*
+ * 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.iceberg.spark.actions;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.Serializable;
+import java.math.BigDecimal;
+import org.apache.iceberg.util.BinaryUtil;
+import org.apache.spark.sql.Column;
+import org.apache.spark.sql.expressions.UserDefinedFunction;
+import org.apache.spark.sql.functions;
+import org.apache.spark.sql.types.BinaryType;
+import org.apache.spark.sql.types.BooleanType;
+import org.apache.spark.sql.types.ByteType;
+import org.apache.spark.sql.types.DataType;
+import org.apache.spark.sql.types.DataTypes;
+import org.apache.spark.sql.types.DateType;
+import org.apache.spark.sql.types.DecimalType;
+import org.apache.spark.sql.types.DoubleType;
+import org.apache.spark.sql.types.FloatType;
+import org.apache.spark.sql.types.IntegerType;
+import org.apache.spark.sql.types.LongType;
+import org.apache.spark.sql.types.ShortType;
+import org.apache.spark.sql.types.StringType;
+import org.apache.spark.sql.types.TimestampType;
+import org.davidmoten.hilbert.HilbertCurve;
+import scala.collection.JavaConverters;
+import scala.collection.Seq;
+
+class SparkHilbertUDF implements SparkSpaceCurveUDF, Serializable {
+  private static final long PRIMITIVE_EMPTY = Long.MAX_VALUE;
+
+  private static final int BITS_NUM = 63;
+
+  SparkHilbertUDF() {}
+
+  private void readObject(ObjectInputStream in) throws IOException, 
ClassNotFoundException {
+    in.defaultReadObject();
+  }
+
+  byte[] hilbertCurvePosBytes(Seq<Long> points) {
+    java.util.List<Long> longs = JavaConverters.seqAsJavaList(points);
+    long[] longs1 = new long[longs.size()];
+    for (int i = 0; i < longs.size(); i++) {
+      longs1[i] = longs.get(i);
+    }
+    HilbertCurve hilbertCurve = 
HilbertCurve.bits(BITS_NUM).dimensions(points.size());
+    return HilbertCurveUtils.indexBytes(hilbertCurve, longs1, BITS_NUM);
+  }
+
+  private UserDefinedFunction tinyToOrderedLongUDF() {
+    UserDefinedFunction udf =
+        functions
+            .udf(
+                (Byte value) -> {
+                  if (value == null) {
+                    return PRIMITIVE_EMPTY;
+                  }
+                  return BinaryUtil.convertBytesToLong(new byte[] {value});
+                },
+                DataTypes.LongType)
+            .withName("TINY_ORDERED_BYTES");
+
+    return udf;
+  }
+
+  private UserDefinedFunction shortToOrderedLongUDF() {
+    UserDefinedFunction udf =
+        functions
+            .udf(
+                (Short value) -> {
+                  if (value == null) {
+                    return PRIMITIVE_EMPTY;
+                  }
+                  return (long) value;
+                },
+                DataTypes.LongType)
+            .withName("SHORT_ORDERED_BYTES");
+
+    return udf;
+  }
+
+  private UserDefinedFunction intToOrderedLongUDF() {
+    UserDefinedFunction udf =
+        functions
+            .udf(
+                (Integer value) -> {
+                  if (value == null) {
+                    return PRIMITIVE_EMPTY;
+                  }
+                  return (long) value;
+                },
+                DataTypes.LongType)
+            .withName("INT_ORDERED_BYTES");
+
+    return udf;
+  }
+
+  private UserDefinedFunction longToOrderedLongUDF() {

Review Comment:
   These are all the same as the Zorder functions correct? Can we unify the 
byte transformation udfs?



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to