stoty commented on code in PR #2020:
URL: https://github.com/apache/phoenix/pull/2020#discussion_r1821942275


##########
phoenix-core-client/src/main/java/org/apache/phoenix/expression/function/EncodeBinaryFunction.java:
##########
@@ -0,0 +1,124 @@
+package org.apache.phoenix.expression.function;
+
+import java.nio.charset.StandardCharsets;
+import java.sql.SQLException;
+import java.util.Base64;
+import java.util.List;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.expression.Expression;
+import org.apache.phoenix.parse.FunctionParseNode;
+import org.apache.phoenix.schema.IllegalDataException;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.tuple.Tuple;
+import org.apache.phoenix.schema.types.PVarchar;
+
+/**
+ * Encodes a string into various formats such as Hex, Base64, or HBase binary.
+ * The input string is converted based on the selected encoding format.
+ * <p>
+ * Usage:
+ * ENCODE_BINARY(<input_string>, <format>)
+ *
+ * @param input_string The string to be encoded.
+ * @param format       The encoding format (HEX, BASE64, HBASE).
+ */
+@FunctionParseNode.BuiltInFunction(name = EncodeBinaryFunction.NAME, args = {
+        @FunctionParseNode.Argument(allowedTypes = {PVarchar.class}),
+        @FunctionParseNode.Argument(enumeration = "EncodeFormat")})
+public class EncodeBinaryFunction extends ScalarFunction {

Review Comment:
   This is derived from and backward compatible with DecodeFunction.
   
   (After fixing the names) instead of duplicating the code, they should share 
the same code via inheritance.
   Adding the new functionality to the existing DECODE function does not break 
functionality, so DECODE and DECODE_BINARY should be basically aliases to each 
other.
   
   (Unless the annotations somehow prevent inheritance from working properly)



##########
phoenix-core-client/src/main/java/org/apache/phoenix/expression/function/DecodeBinaryFunction.java:
##########
@@ -0,0 +1,138 @@
+package org.apache.phoenix.expression.function;
+
+import java.nio.charset.StandardCharsets;
+import java.sql.SQLException;
+import java.util.Base64;
+import java.util.List;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.exception.SQLExceptionCode;
+import org.apache.phoenix.exception.SQLExceptionInfo;
+import org.apache.phoenix.expression.Expression;
+import org.apache.phoenix.parse.FunctionParseNode;
+import org.apache.phoenix.schema.IllegalDataException;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarchar;
+import org.apache.phoenix.schema.types.PVarbinary;
+import org.apache.phoenix.schema.tuple.Tuple;
+
+/**

Review Comment:
   You have the names mixed up.
   
   Encoding is BINARY -> STRING
   
   Decoding is STRING -> BINARY
   
   See the semantics in DecodeFunction.



-- 
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: issues-unsubscr...@phoenix.apache.org

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

Reply via email to