You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2022/06/14 02:21:44 UTC

[GitHub] [iotdb] Plutooooooo opened a new pull request, #6268: [IOTDB-3299] Migrate udf api to a seperate module

Plutooooooo opened a new pull request, #6268:
URL: https://github.com/apache/iotdb/pull/6268

   ## Description
   
   Following changes are made:
   1. UDF API is a independent module now.
   2. Use Type as a substituion class for TSDataType in APIs. UDFDataTypeTransformer is responsible for managing transformation between Type and TSDataType.
   3. Use udf.api.Binary as a substituion class for tsfile.util.Binary in APUs. UDFBinaryTransformer is responsible for managing transformation between udf.api.Binary and tsfile.util.Binary.
   


-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] ericpai commented on a diff in pull request #6268: [IOTDB-3299] Migrate udf api to a seperate module

Posted by GitBox <gi...@apache.org>.
ericpai commented on code in PR #6268:
URL: https://github.com/apache/iotdb/pull/6268#discussion_r896457010


##########
udf-api/src/main/java/org/apache/iotdb/udf/api/type/Binary.java:
##########
@@ -95,13 +102,16 @@ public int hashCode() {
    */
   public int getLength() {
     if (this.values == null) {
-      return -1;
+      return 0;
     }
     return this.values.length;
   }
 
   public String getStringValue() {
-    return new String(this.values, STRING_CHARSET);
+    if (stringCache == null) {
+      stringCache = new String(this.values, STRING_CHARSET);

Review Comment:
   Maybe we should check whether `this.values  == null`.



##########
udf-api/src/main/java/org/apache/iotdb/udf/api/type/Binary.java:
##########
@@ -85,7 +89,10 @@ public boolean equals(Object other) {
 
   @Override
   public int hashCode() {
-    return Arrays.hashCode(values);
+    if (hash == 0) {
+      hash = Arrays.hashCode(values);

Review Comment:
   there's a corner case... If the result just equals 0, then it will be computed every time... Maybe we should add another boolean value to indicate whether the hashCode has been calculated...



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] Plutooooooo commented on a diff in pull request #6268: [IOTDB-3299] Migrate udf api to a seperate module

Posted by GitBox <gi...@apache.org>.
Plutooooooo commented on code in PR #6268:
URL: https://github.com/apache/iotdb/pull/6268#discussion_r896454501


##########
udf-api/src/main/java/org/apache/iotdb/udf/api/type/Binary.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.iotdb.udf.api.type;
+
+import java.io.Serializable;
+import java.nio.charset.Charset;
+import java.util.Arrays;
+
+/**
+ * Override compareTo() and equals() function to Binary class. This class is used to accept Java
+ * String type
+ */
+public class Binary implements Comparable<Binary>, Serializable {
+
+  private static final long serialVersionUID = 1250049718612917815L;
+  public static final String STRING_ENCODING = "UTF-8";
+  public static final Charset STRING_CHARSET = Charset.forName(STRING_ENCODING);
+
+  private byte[] values;
+
+  /** if the bytes v is modified, the modification is visible to this binary. */
+  public Binary(byte[] v) {
+    this.values = v;
+  }
+
+  public Binary(String s) {
+    this.values = (s == null) ? null : s.getBytes(STRING_CHARSET);
+  }
+
+  public static Binary valueOf(String value) {
+    return new Binary(stringToBytes(value));
+  }
+
+  @Override
+  public int compareTo(Binary other) {
+    if (other == null) {
+      if (this.values == null) {
+        return 0;
+      } else {
+        return 1;
+      }
+    }
+
+    int i = 0;
+    while (i < getLength() && i < other.getLength()) {
+      if (this.values[i] == other.values[i]) {
+        i++;
+        continue;
+      }
+      return this.values[i] - other.values[i];
+    }
+    return getLength() - other.getLength();
+  }
+
+  @Override
+  public boolean equals(Object other) {
+    if (this == other) {
+      return true;
+    }
+    if (other == null) {
+      return false;
+    }
+    if (getClass() != other.getClass()) {
+      return false;
+    }
+
+    return compareTo((Binary) other) == 0;
+  }
+
+  @Override
+  public int hashCode() {
+    return Arrays.hashCode(values);

Review Comment:
   Fixed.



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] Plutooooooo commented on a diff in pull request #6268: [IOTDB-3299] Migrate udf api to a seperate module

Posted by GitBox <gi...@apache.org>.
Plutooooooo commented on code in PR #6268:
URL: https://github.com/apache/iotdb/pull/6268#discussion_r896472417


##########
udf-api/src/main/java/org/apache/iotdb/udf/api/type/Binary.java:
##########
@@ -85,7 +89,10 @@ public boolean equals(Object other) {
 
   @Override
   public int hashCode() {
-    return Arrays.hashCode(values);
+    if (hash == 0) {
+      hash = Arrays.hashCode(values);

Review Comment:
   Right... Using Integer needs Boxing and Unboxing, I added a boolean value.



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] SteveYurongSu merged pull request #6268: [IOTDB-3299] Migrate udf api to a seperate module

Posted by GitBox <gi...@apache.org>.
SteveYurongSu merged PR #6268:
URL: https://github.com/apache/iotdb/pull/6268


-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] ericpai commented on a diff in pull request #6268: [IOTDB-3299] Migrate udf api to a seperate module

Posted by GitBox <gi...@apache.org>.
ericpai commented on code in PR #6268:
URL: https://github.com/apache/iotdb/pull/6268#discussion_r896421710


##########
udf-api/src/main/java/org/apache/iotdb/udf/api/type/Binary.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.iotdb.udf.api.type;
+
+import java.io.Serializable;
+import java.nio.charset.Charset;
+import java.util.Arrays;
+
+/**
+ * Override compareTo() and equals() function to Binary class. This class is used to accept Java
+ * String type
+ */
+public class Binary implements Comparable<Binary>, Serializable {
+
+  private static final long serialVersionUID = 1250049718612917815L;
+  public static final String STRING_ENCODING = "UTF-8";
+  public static final Charset STRING_CHARSET = Charset.forName(STRING_ENCODING);
+
+  private byte[] values;
+
+  /** if the bytes v is modified, the modification is visible to this binary. */
+  public Binary(byte[] v) {
+    this.values = v;
+  }
+
+  public Binary(String s) {
+    this.values = (s == null) ? null : s.getBytes(STRING_CHARSET);
+  }
+
+  public static Binary valueOf(String value) {
+    return new Binary(stringToBytes(value));
+  }
+
+  @Override
+  public int compareTo(Binary other) {
+    if (other == null) {
+      if (this.values == null) {
+        return 0;
+      } else {
+        return 1;
+      }
+    }
+
+    int i = 0;
+    while (i < getLength() && i < other.getLength()) {
+      if (this.values[i] == other.values[i]) {
+        i++;
+        continue;
+      }
+      return this.values[i] - other.values[i];
+    }
+    return getLength() - other.getLength();
+  }
+
+  @Override
+  public boolean equals(Object other) {
+    if (this == other) {
+      return true;
+    }
+    if (other == null) {
+      return false;
+    }
+    if (getClass() != other.getClass()) {
+      return false;
+    }
+
+    return compareTo((Binary) other) == 0;
+  }
+
+  @Override
+  public int hashCode() {
+    return Arrays.hashCode(values);

Review Comment:
   If the `values` is not changed, the `hashCode()` may compute only once. So is there any places to use `setBytes()`? If not, we can let `values` be final and compute the hashCode in a lazy mode.



##########
udf-api/src/main/java/org/apache/iotdb/udf/api/type/Binary.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.iotdb.udf.api.type;
+
+import java.io.Serializable;
+import java.nio.charset.Charset;
+import java.util.Arrays;
+
+/**
+ * Override compareTo() and equals() function to Binary class. This class is used to accept Java
+ * String type
+ */
+public class Binary implements Comparable<Binary>, Serializable {
+
+  private static final long serialVersionUID = 1250049718612917815L;
+  public static final String STRING_ENCODING = "UTF-8";
+  public static final Charset STRING_CHARSET = Charset.forName(STRING_ENCODING);
+
+  private byte[] values;
+
+  /** if the bytes v is modified, the modification is visible to this binary. */
+  public Binary(byte[] v) {
+    this.values = v;
+  }
+
+  public Binary(String s) {
+    this.values = (s == null) ? null : s.getBytes(STRING_CHARSET);
+  }
+
+  public static Binary valueOf(String value) {
+    return new Binary(stringToBytes(value));
+  }
+
+  @Override
+  public int compareTo(Binary other) {
+    if (other == null) {
+      if (this.values == null) {
+        return 0;
+      } else {
+        return 1;
+      }
+    }
+
+    int i = 0;
+    while (i < getLength() && i < other.getLength()) {
+      if (this.values[i] == other.values[i]) {
+        i++;
+        continue;
+      }
+      return this.values[i] - other.values[i];
+    }
+    return getLength() - other.getLength();
+  }
+
+  @Override
+  public boolean equals(Object other) {
+    if (this == other) {
+      return true;
+    }
+    if (other == null) {
+      return false;
+    }
+    if (getClass() != other.getClass()) {
+      return false;
+    }
+
+    return compareTo((Binary) other) == 0;
+  }
+
+  @Override
+  public int hashCode() {
+    return Arrays.hashCode(values);
+  }
+
+  /**
+   * get length.
+   *
+   * @return length
+   */
+  public int getLength() {
+    if (this.values == null) {
+      return -1;

Review Comment:
   IMO no matter whether `values` is null or an empty array, the length should be 0. Or it will be a little strage for caller.



##########
node-commons/src/main/java/org/apache/iotdb/commons/udf/utils/UDFBinaryTransformer.java:
##########
@@ -0,0 +1,34 @@
+/*
+ * 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.iotdb.commons.udf.utils;
+
+/** Transform Binary to Binary / Binary to Binary */

Review Comment:
   A strange comment :D . May refine like this `Transform between {@link org.apache.iotdb.tsfile.utils.Binary} and {@link org.apache.iotdb.tsfile.utils.Binary}`



##########
udf-api/src/main/java/org/apache/iotdb/udf/api/type/Binary.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.iotdb.udf.api.type;
+
+import java.io.Serializable;
+import java.nio.charset.Charset;
+import java.util.Arrays;
+
+/**
+ * Override compareTo() and equals() function to Binary class. This class is used to accept Java
+ * String type
+ */
+public class Binary implements Comparable<Binary>, Serializable {
+
+  private static final long serialVersionUID = 1250049718612917815L;
+  public static final String STRING_ENCODING = "UTF-8";
+  public static final Charset STRING_CHARSET = Charset.forName(STRING_ENCODING);
+
+  private byte[] values;
+
+  /** if the bytes v is modified, the modification is visible to this binary. */
+  public Binary(byte[] v) {
+    this.values = v;
+  }
+
+  public Binary(String s) {
+    this.values = (s == null) ? null : s.getBytes(STRING_CHARSET);
+  }
+
+  public static Binary valueOf(String value) {
+    return new Binary(stringToBytes(value));
+  }
+
+  @Override
+  public int compareTo(Binary other) {
+    if (other == null) {
+      if (this.values == null) {
+        return 0;
+      } else {
+        return 1;
+      }
+    }
+
+    int i = 0;
+    while (i < getLength() && i < other.getLength()) {
+      if (this.values[i] == other.values[i]) {
+        i++;
+        continue;
+      }
+      return this.values[i] - other.values[i];
+    }
+    return getLength() - other.getLength();
+  }
+
+  @Override
+  public boolean equals(Object other) {
+    if (this == other) {
+      return true;
+    }
+    if (other == null) {
+      return false;
+    }
+    if (getClass() != other.getClass()) {
+      return false;
+    }
+
+    return compareTo((Binary) other) == 0;
+  }
+
+  @Override
+  public int hashCode() {
+    return Arrays.hashCode(values);
+  }
+
+  /**
+   * get length.
+   *
+   * @return length
+   */
+  public int getLength() {
+    if (this.values == null) {
+      return -1;
+    }
+    return this.values.length;
+  }
+
+  public String getStringValue() {
+    return new String(this.values, STRING_CHARSET);

Review Comment:
   Like `hashCode()`, if the `values` is immutable, we can `getStringValue()` in a lazy mode.



##########
udf-api/pom.xml:
##########
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>iotdb-parent</artifactId>
+        <groupId>org.apache.iotdb</groupId>
+        <version>0.14.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>udf-api</artifactId>

Review Comment:
   I think this module should be added to `iotdb-distribution` and give out as a maven lib when new version is releasing. So developers can add it as their project's dependency to implement their 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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] Plutooooooo commented on a diff in pull request #6268: [IOTDB-3299] Migrate udf api to a seperate module

Posted by GitBox <gi...@apache.org>.
Plutooooooo commented on code in PR #6268:
URL: https://github.com/apache/iotdb/pull/6268#discussion_r896449358


##########
udf-api/src/main/java/org/apache/iotdb/udf/api/type/Binary.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.iotdb.udf.api.type;
+
+import java.io.Serializable;
+import java.nio.charset.Charset;
+import java.util.Arrays;
+
+/**
+ * Override compareTo() and equals() function to Binary class. This class is used to accept Java
+ * String type
+ */
+public class Binary implements Comparable<Binary>, Serializable {
+
+  private static final long serialVersionUID = 1250049718612917815L;
+  public static final String STRING_ENCODING = "UTF-8";
+  public static final Charset STRING_CHARSET = Charset.forName(STRING_ENCODING);
+
+  private byte[] values;
+
+  /** if the bytes v is modified, the modification is visible to this binary. */
+  public Binary(byte[] v) {
+    this.values = v;
+  }
+
+  public Binary(String s) {
+    this.values = (s == null) ? null : s.getBytes(STRING_CHARSET);
+  }
+
+  public static Binary valueOf(String value) {
+    return new Binary(stringToBytes(value));
+  }
+
+  @Override
+  public int compareTo(Binary other) {
+    if (other == null) {
+      if (this.values == null) {
+        return 0;
+      } else {
+        return 1;
+      }
+    }
+
+    int i = 0;
+    while (i < getLength() && i < other.getLength()) {
+      if (this.values[i] == other.values[i]) {
+        i++;
+        continue;
+      }
+      return this.values[i] - other.values[i];
+    }
+    return getLength() - other.getLength();
+  }
+
+  @Override
+  public boolean equals(Object other) {
+    if (this == other) {
+      return true;
+    }
+    if (other == null) {
+      return false;
+    }
+    if (getClass() != other.getClass()) {
+      return false;
+    }
+
+    return compareTo((Binary) other) == 0;
+  }
+
+  @Override
+  public int hashCode() {
+    return Arrays.hashCode(values);
+  }
+
+  /**
+   * get length.
+   *
+   * @return length
+   */
+  public int getLength() {
+    if (this.values == null) {
+      return -1;

Review Comment:
   In tsfile.util.Binary, this method returns -1 when values is null. But I think it's better to return 0, too.



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] ericpai commented on a diff in pull request #6268: [IOTDB-3299] Migrate udf api to a seperate module

Posted by GitBox <gi...@apache.org>.
ericpai commented on code in PR #6268:
URL: https://github.com/apache/iotdb/pull/6268#discussion_r896452390


##########
udf-api/src/main/java/org/apache/iotdb/udf/api/type/Binary.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.iotdb.udf.api.type;
+
+import java.io.Serializable;
+import java.nio.charset.Charset;
+import java.util.Arrays;
+
+/**
+ * Override compareTo() and equals() function to Binary class. This class is used to accept Java
+ * String type
+ */
+public class Binary implements Comparable<Binary>, Serializable {
+
+  private static final long serialVersionUID = 1250049718612917815L;
+  public static final String STRING_ENCODING = "UTF-8";
+  public static final Charset STRING_CHARSET = Charset.forName(STRING_ENCODING);
+
+  private byte[] values;
+
+  /** if the bytes v is modified, the modification is visible to this binary. */
+  public Binary(byte[] v) {
+    this.values = v;
+  }
+
+  public Binary(String s) {
+    this.values = (s == null) ? null : s.getBytes(STRING_CHARSET);
+  }
+
+  public static Binary valueOf(String value) {
+    return new Binary(stringToBytes(value));
+  }
+
+  @Override
+  public int compareTo(Binary other) {
+    if (other == null) {
+      if (this.values == null) {
+        return 0;
+      } else {
+        return 1;
+      }
+    }
+
+    int i = 0;
+    while (i < getLength() && i < other.getLength()) {
+      if (this.values[i] == other.values[i]) {
+        i++;
+        continue;
+      }
+      return this.values[i] - other.values[i];
+    }
+    return getLength() - other.getLength();
+  }
+
+  @Override
+  public boolean equals(Object other) {
+    if (this == other) {
+      return true;
+    }
+    if (other == null) {
+      return false;
+    }
+    if (getClass() != other.getClass()) {
+      return false;
+    }
+
+    return compareTo((Binary) other) == 0;
+  }
+
+  @Override
+  public int hashCode() {
+    return Arrays.hashCode(values);
+  }
+
+  /**
+   * get length.
+   *
+   * @return length
+   */
+  public int getLength() {
+    if (this.values == null) {
+      return -1;

Review Comment:
   So we should make sure is it necessary to distinguish `empty` and `null` using `getLength()`? Or just adding another `isNull()` may be more clear.



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] Plutooooooo commented on a diff in pull request #6268: [IOTDB-3299] Migrate udf api to a seperate module

Posted by GitBox <gi...@apache.org>.
Plutooooooo commented on code in PR #6268:
URL: https://github.com/apache/iotdb/pull/6268#discussion_r896457590


##########
udf-api/src/main/java/org/apache/iotdb/udf/api/type/Binary.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.iotdb.udf.api.type;
+
+import java.io.Serializable;
+import java.nio.charset.Charset;
+import java.util.Arrays;
+
+/**
+ * Override compareTo() and equals() function to Binary class. This class is used to accept Java
+ * String type
+ */
+public class Binary implements Comparable<Binary>, Serializable {
+
+  private static final long serialVersionUID = 1250049718612917815L;
+  public static final String STRING_ENCODING = "UTF-8";
+  public static final Charset STRING_CHARSET = Charset.forName(STRING_ENCODING);
+
+  private byte[] values;
+
+  /** if the bytes v is modified, the modification is visible to this binary. */
+  public Binary(byte[] v) {
+    this.values = v;
+  }
+
+  public Binary(String s) {
+    this.values = (s == null) ? null : s.getBytes(STRING_CHARSET);
+  }
+
+  public static Binary valueOf(String value) {
+    return new Binary(stringToBytes(value));
+  }
+
+  @Override
+  public int compareTo(Binary other) {
+    if (other == null) {
+      if (this.values == null) {
+        return 0;
+      } else {
+        return 1;
+      }
+    }
+
+    int i = 0;
+    while (i < getLength() && i < other.getLength()) {
+      if (this.values[i] == other.values[i]) {
+        i++;
+        continue;
+      }
+      return this.values[i] - other.values[i];
+    }
+    return getLength() - other.getLength();
+  }
+
+  @Override
+  public boolean equals(Object other) {
+    if (this == other) {
+      return true;
+    }
+    if (other == null) {
+      return false;
+    }
+    if (getClass() != other.getClass()) {
+      return false;
+    }
+
+    return compareTo((Binary) other) == 0;
+  }
+
+  @Override
+  public int hashCode() {
+    return Arrays.hashCode(values);
+  }
+
+  /**
+   * get length.
+   *
+   * @return length
+   */
+  public int getLength() {
+    if (this.values == null) {
+      return -1;

Review Comment:
   Perhaps we can add a isNull() method and let getLength() remain the same?



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] ericpai commented on a diff in pull request #6268: [IOTDB-3299] Migrate udf api to a seperate module

Posted by GitBox <gi...@apache.org>.
ericpai commented on code in PR #6268:
URL: https://github.com/apache/iotdb/pull/6268#discussion_r896459183


##########
udf-api/src/main/java/org/apache/iotdb/udf/api/type/Binary.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.iotdb.udf.api.type;
+
+import java.io.Serializable;
+import java.nio.charset.Charset;
+import java.util.Arrays;
+
+/**
+ * Override compareTo() and equals() function to Binary class. This class is used to accept Java
+ * String type
+ */
+public class Binary implements Comparable<Binary>, Serializable {
+
+  private static final long serialVersionUID = 1250049718612917815L;
+  public static final String STRING_ENCODING = "UTF-8";
+  public static final Charset STRING_CHARSET = Charset.forName(STRING_ENCODING);
+
+  private byte[] values;
+
+  /** if the bytes v is modified, the modification is visible to this binary. */
+  public Binary(byte[] v) {
+    this.values = v;
+  }
+
+  public Binary(String s) {
+    this.values = (s == null) ? null : s.getBytes(STRING_CHARSET);
+  }
+
+  public static Binary valueOf(String value) {
+    return new Binary(stringToBytes(value));
+  }
+
+  @Override
+  public int compareTo(Binary other) {
+    if (other == null) {
+      if (this.values == null) {
+        return 0;
+      } else {
+        return 1;
+      }
+    }
+
+    int i = 0;
+    while (i < getLength() && i < other.getLength()) {
+      if (this.values[i] == other.values[i]) {
+        i++;
+        continue;
+      }
+      return this.values[i] - other.values[i];
+    }
+    return getLength() - other.getLength();
+  }
+
+  @Override
+  public boolean equals(Object other) {
+    if (this == other) {
+      return true;
+    }
+    if (other == null) {
+      return false;
+    }
+    if (getClass() != other.getClass()) {
+      return false;
+    }
+
+    return compareTo((Binary) other) == 0;
+  }
+
+  @Override
+  public int hashCode() {
+    return Arrays.hashCode(values);
+  }
+
+  /**
+   * get length.
+   *
+   * @return length
+   */
+  public int getLength() {
+    if (this.values == null) {
+      return -1;

Review Comment:
   Then we need to explain this in the javadoc comment.



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] ericpai commented on a diff in pull request #6268: [IOTDB-3299] Migrate udf api to a seperate module

Posted by GitBox <gi...@apache.org>.
ericpai commented on code in PR #6268:
URL: https://github.com/apache/iotdb/pull/6268#discussion_r896431124


##########
node-commons/src/main/java/org/apache/iotdb/commons/udf/utils/UDFDataTypeTransformer.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.iotdb.commons.udf.utils;
+
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.udf.api.type.Type;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+/** Transform Type to TsDataType / TsDataType to Type */
+public class UDFDataTypeTransformer {

Review Comment:
   A strange comment :D . May refine like this Transform between {@link org.apache.iotdb.tsfile.file.metadata.enums.TSDataType} and {@link org.apache.iotdb.udf.api.type.Type}



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] ericpai commented on a diff in pull request #6268: [IOTDB-3299] Migrate udf api to a seperate module

Posted by GitBox <gi...@apache.org>.
ericpai commented on code in PR #6268:
URL: https://github.com/apache/iotdb/pull/6268#discussion_r896431734


##########
node-commons/src/main/java/org/apache/iotdb/commons/udf/utils/UDFDataTypeTransformer.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.iotdb.commons.udf.utils;
+
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.udf.api.type.Type;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+/** Transform Type to TsDataType / TsDataType to Type */

Review Comment:
   A strange comment :D . May refine like this Transform between {@link org.apache.iotdb.tsfile.file.metadata.enums.TSDataType} and {@link org.apache.iotdb.udf.api.type.Type}



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] Plutooooooo commented on a diff in pull request #6268: [IOTDB-3299] Migrate udf api to a seperate module

Posted by GitBox <gi...@apache.org>.
Plutooooooo commented on code in PR #6268:
URL: https://github.com/apache/iotdb/pull/6268#discussion_r896454940


##########
udf-api/src/main/java/org/apache/iotdb/udf/api/type/Binary.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.iotdb.udf.api.type;
+
+import java.io.Serializable;
+import java.nio.charset.Charset;
+import java.util.Arrays;
+
+/**
+ * Override compareTo() and equals() function to Binary class. This class is used to accept Java
+ * String type
+ */
+public class Binary implements Comparable<Binary>, Serializable {
+
+  private static final long serialVersionUID = 1250049718612917815L;
+  public static final String STRING_ENCODING = "UTF-8";
+  public static final Charset STRING_CHARSET = Charset.forName(STRING_ENCODING);
+
+  private byte[] values;
+
+  /** if the bytes v is modified, the modification is visible to this binary. */
+  public Binary(byte[] v) {
+    this.values = v;
+  }
+
+  public Binary(String s) {
+    this.values = (s == null) ? null : s.getBytes(STRING_CHARSET);
+  }
+
+  public static Binary valueOf(String value) {
+    return new Binary(stringToBytes(value));
+  }
+
+  @Override
+  public int compareTo(Binary other) {
+    if (other == null) {
+      if (this.values == null) {
+        return 0;
+      } else {
+        return 1;
+      }
+    }
+
+    int i = 0;
+    while (i < getLength() && i < other.getLength()) {
+      if (this.values[i] == other.values[i]) {
+        i++;
+        continue;
+      }
+      return this.values[i] - other.values[i];
+    }
+    return getLength() - other.getLength();
+  }
+
+  @Override
+  public boolean equals(Object other) {
+    if (this == other) {
+      return true;
+    }
+    if (other == null) {
+      return false;
+    }
+    if (getClass() != other.getClass()) {
+      return false;
+    }
+
+    return compareTo((Binary) other) == 0;
+  }
+
+  @Override
+  public int hashCode() {
+    return Arrays.hashCode(values);
+  }
+
+  /**
+   * get length.
+   *
+   * @return length
+   */
+  public int getLength() {
+    if (this.values == null) {
+      return -1;
+    }
+    return this.values.length;
+  }
+
+  public String getStringValue() {
+    return new String(this.values, STRING_CHARSET);

Review Comment:
   Fixed.



##########
node-commons/src/main/java/org/apache/iotdb/commons/udf/utils/UDFBinaryTransformer.java:
##########
@@ -0,0 +1,34 @@
+/*
+ * 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.iotdb.commons.udf.utils;
+
+/** Transform Binary to Binary / Binary to Binary */

Review Comment:
   Fixed.



##########
node-commons/src/main/java/org/apache/iotdb/commons/udf/utils/UDFDataTypeTransformer.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.iotdb.commons.udf.utils;
+
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.udf.api.type.Type;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+/** Transform Type to TsDataType / TsDataType to Type */

Review Comment:
   Fixed.



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] ericpai commented on a diff in pull request #6268: [IOTDB-3299] Migrate udf api to a seperate module

Posted by GitBox <gi...@apache.org>.
ericpai commented on code in PR #6268:
URL: https://github.com/apache/iotdb/pull/6268#discussion_r896472643


##########
udf-api/src/main/java/org/apache/iotdb/udf/api/type/Binary.java:
##########
@@ -90,13 +93,16 @@ public boolean equals(Object other) {
   @Override
   public int hashCode() {
     if (hash == 0) {
-      hash = Arrays.hashCode(values);
+      if (!hasCalculatedHash) {

Review Comment:
   Just check `hasCalculatedHash` is enough. There's no need to check `hash == 0`.



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org