You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@phoenix.apache.org by "szucsvillo (via GitHub)" <gi...@apache.org> on 2024/10/29 14:28:39 UTC

[PR] PHOENIX-7424 Support toStringBinary/toBytesBinary conversion [phoenix]

szucsvillo opened a new pull request, #2020:
URL: https://github.com/apache/phoenix/pull/2020

   (no 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: issues-unsubscribe@phoenix.apache.org

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


Re: [PR] PHOENIX-7424 Support toStringBinary/toBytesBinary conversion [phoenix]

Posted by "stoty (via GitHub)" <gi...@apache.org>.
stoty commented on code in PR #2020:
URL: https://github.com/apache/phoenix/pull/2020#discussion_r1822865245


##########
phoenix-core-client/src/main/java/org/apache/phoenix/expression/function/EncodeFormat.java:
##########
@@ -22,5 +22,6 @@ public enum EncodeFormat {
 	HEX, //format for encoding HEX value to bytes
 	BASE62, //format for encoding a base 10 long value to base 62 string
 	BASE64, //format for encoding a base 10 long value to base 64 string
-	ASCII // Plain Text
+	ASCII, //Plain Text
+	HBASE //HBase-specific binary encoding format

Review Comment:
   nit: this is more of an escaping format than encoding.



-- 
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-unsubscribe@phoenix.apache.org

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


Re: [PR] PHOENIX-7424 Support toStringBinary/toBytesBinary conversion [phoenix]

Posted by "stoty (via GitHub)" <gi...@apache.org>.
stoty commented on code in PR #2020:
URL: https://github.com/apache/phoenix/pull/2020#discussion_r1842596834


##########
phoenix-core-client/src/main/java/org/apache/phoenix/expression/function/DecodeFunction.java:
##########
@@ -71,19 +71,25 @@ public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
 	        .setMessage("Missing bytes encoding").build().buildException());
 		}
 
-		type = encodingExpression.getDataType();
+		PDataType type = encodingExpression.getDataType();
 		String encoding = ((String) type.toObject(ptr)).toUpperCase();
 
 		byte out[];
 
 		EncodeFormat format = EncodeFormat.valueOf(encoding);
-		switch (format) {
-			case HEX:
-				out = decodeHex(stringToDecode);
-				break;
-			default:
-				throw new IllegalDataException("Unsupported encoding \"" + encoding + "\"");
-		}
+        switch (format) {
+            case HEX:
+                out = decodeHex(stringToDecode);
+                break;
+            case BASE64:
+				out = Base64.getDecoder().decode(stringToDecode);

Review Comment:
   whitespaces



-- 
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-unsubscribe@phoenix.apache.org

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


Re: [PR] PHOENIX-7424 Support toStringBinary/toBytesBinary conversion [phoenix]

Posted by "stoty (via GitHub)" <gi...@apache.org>.
stoty merged PR #2020:
URL: https://github.com/apache/phoenix/pull/2020


-- 
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-unsubscribe@phoenix.apache.org

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


Re: [PR] PHOENIX-7424 Support toStringBinary/toBytesBinary conversion [phoenix]

Posted by "stoty (via GitHub)" <gi...@apache.org>.
stoty commented on code in PR #2020:
URL: https://github.com/apache/phoenix/pull/2020#discussion_r1822873848


##########
phoenix-core-client/src/main/java/org/apache/phoenix/expression/function/DecodeBinaryFunction.java:
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.phoenix.expression.function;
+
+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;
+
+/**
+ * Decodes binary data in various formats (Hex, Base64, HBase) by extending the DecodeFunction.
+ * <p>
+ * Usage:
+ * DECODE_BINARY(<input_string>, <format>)
+ *
+ * @param input_string The string to be decoded.
+ * @param format       The encoding format (HEX, BASE64, HBASE).
+ */
+@FunctionParseNode.BuiltInFunction(name = DecodeBinaryFunction.NAME, args = {
+        @FunctionParseNode.Argument(allowedTypes = {PVarchar.class}),
+        @FunctionParseNode.Argument(enumeration = "EncodeFormat")})
+public class DecodeBinaryFunction extends DecodeFunction {

Review Comment:
   Technically, we do not even need the new DECODE_BINARY function, we are only adding it so that the encoding/decoding functions have intuitive names.



-- 
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-unsubscribe@phoenix.apache.org

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


Re: [PR] PHOENIX-7424 Support toStringBinary/toBytesBinary conversion [phoenix]

Posted by "stoty (via GitHub)" <gi...@apache.org>.
stoty commented on code in PR #2020:
URL: https://github.com/apache/phoenix/pull/2020#discussion_r1848292680


##########
phoenix-core/src/it/java/org/apache/phoenix/end2end/DecodeBinaryFunctionIT.java:
##########
@@ -0,0 +1,202 @@
+/*
+ * 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.phoenix.end2end;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Arrays;
+
+import org.apache.phoenix.exception.SQLExceptionCode;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(ParallelStatsDisabledTest.class)
+public class DecodeBinaryFunctionIT extends ParallelStatsDisabledIT {
+
+    @Test
+    public void testDecodeHBaseFromEscapedHex() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+
+        String testTable = generateUniqueName();
+        String ddl = "CREATE TABLE " + testTable + " (id INTEGER PRIMARY KEY, data VARCHAR)";
+
+        conn.createStatement().execute(ddl);
+
+        PreparedStatement ps = conn.prepareStatement("UPSERT INTO " + testTable + " (id, data) VALUES (1, 'data')");
+        ps.execute();
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery(
+                "SELECT DECODE_BINARY('\\\\x48\\\\x65\\\\x6C\\\\x6C\\\\x6F\\\\x50" +

Review Comment:
   I still don't get why this works.
   I would expect this to result in \H\e\l\l\o\P\h\o\e\n\i\x
   
   Why does the DECODE_BINARY swallow the extra backslashes ?



-- 
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-unsubscribe@phoenix.apache.org

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


Re: [PR] PHOENIX-7424 Support toStringBinary/toBytesBinary conversion [phoenix]

Posted by "stoty (via GitHub)" <gi...@apache.org>.
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-unsubscribe@phoenix.apache.org

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


Re: [PR] PHOENIX-7424 Support toStringBinary/toBytesBinary conversion [phoenix]

Posted by "stoty (via GitHub)" <gi...@apache.org>.
stoty commented on code in PR #2020:
URL: https://github.com/apache/phoenix/pull/2020#discussion_r1842614456


##########
phoenix-core/src/it/java/org/apache/phoenix/end2end/DecodeBinaryFunctionIT.java:
##########
@@ -0,0 +1,202 @@
+/*
+ * 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.phoenix.end2end;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Arrays;
+
+import org.apache.phoenix.exception.SQLExceptionCode;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(ParallelStatsDisabledTest.class)
+public class DecodeBinaryFunctionIT extends ParallelStatsDisabledIT {
+
+    @Test
+    public void testDecodeHBaseFromEscapedHex() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+
+        String testTable = generateUniqueName();
+        String ddl = "CREATE TABLE " + testTable + " (id INTEGER PRIMARY KEY, data VARCHAR)";
+
+        conn.createStatement().execute(ddl);
+
+        PreparedStatement ps = conn.prepareStatement("UPSERT INTO " + testTable + " (id, data) VALUES (1, 'data')");
+        ps.execute();
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery(
+                "SELECT DECODE_BINARY('\\\\x48\\\\x65\\\\x6C\\\\x6C\\\\x6F\\\\x50" +
+                        "\\\\x68\\\\x6F\\\\x65\\\\x6E\\\\x69\\\\x78', " + "'HBASE') FROM " + testTable);
+        assertTrue(rs.next());
+        byte[] actualBytes = rs.getBytes(1);
+        assertTrue(Arrays.equals("HelloPhoenix".getBytes(), actualBytes));
+    }
+
+    @Test
+    public void testDecodeHBaseFromHexLiteral() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+
+        String testTable = generateUniqueName();
+        String ddl = "CREATE TABLE " + testTable + " (id INTEGER PRIMARY KEY, data VARCHAR)";
+
+        conn.createStatement().execute(ddl);
+
+        PreparedStatement ps = conn.prepareStatement("UPSERT INTO " + testTable + " (id, data) VALUES (1, 'data')");
+        ps.execute();
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery(
+                "SELECT DECODE_BINARY('\\x48\\x65\\x6C\\x6C\\x6F\\x50\\x68\\x6F\\x65\\x6E\\x69\\x78', " +
+                        "'HBASE') FROM " + testTable);
+        assertTrue(rs.next());
+        byte[] actualBytes = rs.getBytes(1);
+        assertTrue(Arrays.equals("HelloPhoenix".getBytes(), actualBytes));
+    }
+
+    @Test
+    public void testInvalidDecodingFormat() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        String testTable = generateUniqueName();
+        String ddl = "CREATE TABLE " + testTable + " (id INTEGER PRIMARY KEY, data VARCHAR)";
+
+        conn.createStatement().execute(ddl);
+
+        try {
+            conn.createStatement().executeQuery("SELECT DECODE_BINARY(data, 'INVALIDFORMAT') FROM " + testTable);
+            fail("Expected an exception for invalid encoding format");
+        } catch (SQLException e) {
+            assertEquals(SQLExceptionCode.TYPE_MISMATCH.getErrorCode(), e.getErrorCode());
+        }
+    }
+
+    @Test
+    public void testNullAndEmptyStringDecoding() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        String testTable = generateUniqueName();
+        String ddl = "CREATE TABLE " + testTable + " (id INTEGER PRIMARY KEY, data VARCHAR)";
+
+        conn.createStatement().execute(ddl);
+
+        ResultSet rs = conn.createStatement().executeQuery("SELECT DECODE_BINARY(data, 'HBASE') FROM " + testTable);
+        assertFalse(rs.next());
+
+        ResultSet rs2 = conn.createStatement().executeQuery("SELECT DECODE_BINARY(NULL, 'HEX') FROM " + testTable);
+        assertFalse(rs2.next());
+    }
+
+    @Test
+    public void testLongBase64Decoding() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+
+        String testTable = generateUniqueName();
+        String ddl = "CREATE TABLE " + testTable + " (id INTEGER PRIMARY KEY, data VARCHAR)";
+        conn.createStatement().execute(ddl);
+
+        String base64Chunk = "SGVsbG9QaG9lbml4";
+        StringBuilder base64String = new StringBuilder();
+        for (int i = 0; i < 20; i++) {
+            base64String.append(base64Chunk);
+        }
+
+        PreparedStatement ps = conn.prepareStatement("UPSERT INTO " + testTable + " (id, data) VALUES (1, ?)");
+        ps.setString(1, base64String.toString());
+        ps.execute();
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery("SELECT DECODE_BINARY(data, 'BASE64') FROM " + testTable);
+        assertTrue(rs.next());
+
+        StringBuilder expectedString = new StringBuilder();
+        for (int i = 0; i < 20; i++) {
+            expectedString.append("HelloPhoenix");
+        }
+
+        byte[] actualBytes = rs.getBytes(1);
+        assertTrue(Arrays.equals(expectedString.toString().getBytes(), actualBytes));
+        assertFalse(rs.next());
+    }
+
+    @Test
+    public void testDecodeEncodeRoundHex() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        String testTable = generateUniqueName();
+        String ddl = "CREATE TABLE " + testTable + " (id INTEGER PRIMARY KEY, data VARCHAR)";
+        conn.createStatement().execute(ddl);
+
+        PreparedStatement ps =
+                conn.prepareStatement("UPSERT INTO " + testTable + " (id, data) VALUES (1, '48656C6C6F')");
+        ps.execute();
+        conn.commit();
+
+        ResultSet rs = conn.createStatement()
+                .executeQuery("SELECT ENCODE_BINARY(DECODE_BINARY(data, 'HEX'), 'HEX') FROM " + testTable);
+        assertTrue(rs.next());
+        String actualString = rs.getString(1);
+        assertEquals("48656c6c6f", actualString);

Review Comment:
   nit:Could use a constant on both ends.



-- 
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-unsubscribe@phoenix.apache.org

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


Re: [PR] PHOENIX-7424 Support toStringBinary/toBytesBinary conversion [phoenix]

Posted by "stoty (via GitHub)" <gi...@apache.org>.
stoty commented on code in PR #2020:
URL: https://github.com/apache/phoenix/pull/2020#discussion_r1842607582


##########
phoenix-core/src/it/java/org/apache/phoenix/end2end/DecodeBinaryFunctionIT.java:
##########
@@ -0,0 +1,202 @@
+/*
+ * 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.phoenix.end2end;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Arrays;
+
+import org.apache.phoenix.exception.SQLExceptionCode;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(ParallelStatsDisabledTest.class)
+public class DecodeBinaryFunctionIT extends ParallelStatsDisabledIT {
+
+    @Test
+    public void testDecodeHBaseFromEscapedHex() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+
+        String testTable = generateUniqueName();
+        String ddl = "CREATE TABLE " + testTable + " (id INTEGER PRIMARY KEY, data VARCHAR)";

Review Comment:
   creating a separate table for each test will slow the tests down.
   Consider creating a single table in @BeforeClass and re-using it.



-- 
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-unsubscribe@phoenix.apache.org

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


Re: [PR] PHOENIX-7424 Support toStringBinary/toBytesBinary conversion [phoenix]

Posted by "szucsvillo (via GitHub)" <gi...@apache.org>.
szucsvillo commented on code in PR #2020:
URL: https://github.com/apache/phoenix/pull/2020#discussion_r1848317016


##########
phoenix-core-client/src/main/java/org/apache/phoenix/expression/function/DecodeFunction.java:
##########
@@ -59,7 +59,7 @@ public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
 			return true; // expression was evaluated, but evaluated to null
 		}
 
-		String stringToDecode = (String) PVarchar.INSTANCE.toObject(ptr);
+        String stringToDecode = (String) PVarchar.INSTANCE.toObject(ptr);

Review Comment:
   I tried to follow that approach, however, the static code analyzer flagged some formatting issues, which I addressed to avoid any errors in the process.



-- 
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-unsubscribe@phoenix.apache.org

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


Re: [PR] PHOENIX-7424 Support toStringBinary/toBytesBinary conversion [phoenix]

Posted by "stoty (via GitHub)" <gi...@apache.org>.
stoty commented on code in PR #2020:
URL: https://github.com/apache/phoenix/pull/2020#discussion_r1842617434


##########
phoenix-core/src/it/java/org/apache/phoenix/end2end/EncodeBinaryFunctionIT.java:
##########
@@ -0,0 +1,256 @@
+/*
+ * 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.phoenix.end2end;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Arrays;
+
+import org.apache.phoenix.exception.SQLExceptionCode;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+
+@Category(ParallelStatsDisabledTest.class)
+public class EncodeBinaryFunctionIT extends ParallelStatsDisabledIT {
+
+    @Test
+    public void testEncodeHex() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+
+        String testTable = generateUniqueName();
+        String ddl = "CREATE TABLE " + testTable + " (id INTEGER PRIMARY KEY, data VARBINARY)";
+
+        conn.createStatement().execute(ddl);
+
+        PreparedStatement ps = conn.prepareStatement(
+                "UPSERT INTO " + testTable + " (id, data) VALUES (1, X'48656c6c6f50686f656e6978')");
+        ps.execute();
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery("SELECT ENCODE_BINARY(data, 'HEX') FROM " + testTable);
+        assertTrue(rs.next());
+        String actualString = rs.getString(1);
+        assertEquals("48656c6c6f50686f656e6978", actualString);

Review Comment:
   nit: use a java constant for these kinds of tests, with toLower() toUpper() if needed



-- 
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-unsubscribe@phoenix.apache.org

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


Re: [PR] PHOENIX-7424 Support toStringBinary/toBytesBinary conversion [phoenix]

Posted by "stoty (via GitHub)" <gi...@apache.org>.
stoty commented on code in PR #2020:
URL: https://github.com/apache/phoenix/pull/2020#discussion_r1842597645


##########
phoenix-core-client/src/main/java/org/apache/phoenix/expression/function/EncodeBinaryFunction.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.phoenix.expression.function;
+
+import static org.apache.hadoop.hbase.util.Bytes.toHex;
+
+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.types.PVarchar;
+import org.apache.phoenix.schema.types.PVarbinary;
+import org.apache.phoenix.schema.tuple.Tuple;
+
+/**
+ * Encodes binary data into a string from various formats such as Hex, Base64, or HBase binary.

Review Comment:
   to, instead of from



-- 
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-unsubscribe@phoenix.apache.org

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


Re: [PR] PHOENIX-7424 Support toStringBinary/toBytesBinary conversion [phoenix]

Posted by "szucsvillo (via GitHub)" <gi...@apache.org>.
szucsvillo commented on code in PR #2020:
URL: https://github.com/apache/phoenix/pull/2020#discussion_r1848123981


##########
phoenix-core-client/src/main/java/org/apache/phoenix/expression/function/EncodeBinaryFunction.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.phoenix.expression.function;
+
+import static org.apache.hadoop.hbase.util.Bytes.toHex;
+
+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.types.PVarchar;
+import org.apache.phoenix.schema.types.PVarbinary;
+import org.apache.phoenix.schema.tuple.Tuple;
+
+/**
+ * Encodes binary data into a string from various formats such as Hex, Base64, or HBase binary.
+ */
+@FunctionParseNode.BuiltInFunction(name = EncodeBinaryFunction.NAME, args = {
+    @FunctionParseNode.Argument(allowedTypes = {PVarbinary.class}),
+    @FunctionParseNode.Argument(enumeration = "EncodeFormat")})
+public class EncodeBinaryFunction extends ScalarFunction {
+
+    public static final String NAME = "ENCODE_BINARY";
+
+    public EncodeBinaryFunction() {
+    }
+
+    public EncodeBinaryFunction(List<Expression> children) throws SQLException {
+        super(children);
+    }
+
+    @Override
+    public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
+        Expression expression = getExpression();
+        if (!expression.evaluate(tuple, ptr)) {
+            return false;
+        }
+        if (ptr.getLength() == 0) {
+            return true;
+        }
+
+        byte[] bytesToEncode = ptr.copyBytes();
+        Expression encodingExpression = getEncodingExpression();
+
+        if (!encodingExpression.evaluate(tuple, ptr)) {
+            return false;
+        }
+
+        if (ptr.getLength() == 0) {
+            throw new IllegalDataException(getMissingEncodeFormatMsg());
+        }
+
+        PDataType type = encodingExpression.getDataType();
+        String encodingFormat = ((String) type.toObject(ptr)).toUpperCase();
+        EncodeFormat format = EncodeFormat.valueOf(encodingFormat);
+        String encodedString;
+
+        switch (format) {
+            case HEX:
+                encodedString = toHex(bytesToEncode);
+                break;
+            case BASE64:
+                encodedString = Base64.getEncoder().encodeToString(bytesToEncode);

Review Comment:
   It is a standard Base64 encoder which is not particularly heavy as the encoding logic itself is relatively lightweight. Since the encoder is stateless, it does not gain much from being reused. I think the performance gains from this optimization would be minimal in most cases.



-- 
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-unsubscribe@phoenix.apache.org

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


Re: [PR] PHOENIX-7424 Support toStringBinary/toBytesBinary conversion [phoenix]

Posted by "stoty (via GitHub)" <gi...@apache.org>.
stoty commented on code in PR #2020:
URL: https://github.com/apache/phoenix/pull/2020#discussion_r1848299497


##########
phoenix-core-client/src/main/java/org/apache/phoenix/expression/function/DecodeFunction.java:
##########
@@ -59,7 +59,7 @@ public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
 			return true; // expression was evaluated, but evaluated to null
 		}
 
-		String stringToDecode = (String) PVarchar.INSTANCE.toObject(ptr);
+        String stringToDecode = (String) PVarchar.INSTANCE.toObject(ptr);

Review Comment:
   The indentation seems to be off.
   
   Make sure to configure your IDE with the Phoenix standard code formatting setting
   (then again, maybe this file is just misformatted.
   
   In any case, try to minimize the whitespace changes, we're going to reformat the whole code base soon.



-- 
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-unsubscribe@phoenix.apache.org

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


Re: [PR] PHOENIX-7424 Support toStringBinary/toBytesBinary conversion [phoenix]

Posted by "stoty (via GitHub)" <gi...@apache.org>.
stoty commented on code in PR #2020:
URL: https://github.com/apache/phoenix/pull/2020#discussion_r1848280562


##########
phoenix-core-client/src/main/java/org/apache/phoenix/expression/function/EncodeBinaryFunction.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.phoenix.expression.function;
+
+import static org.apache.hadoop.hbase.util.Bytes.toHex;
+
+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.types.PVarchar;
+import org.apache.phoenix.schema.types.PVarbinary;
+import org.apache.phoenix.schema.tuple.Tuple;
+
+/**
+ * Encodes binary data into a string from various formats such as Hex, Base64, or HBase binary.
+ */
+@FunctionParseNode.BuiltInFunction(name = EncodeBinaryFunction.NAME, args = {
+    @FunctionParseNode.Argument(allowedTypes = {PVarbinary.class}),
+    @FunctionParseNode.Argument(enumeration = "EncodeFormat")})
+public class EncodeBinaryFunction extends ScalarFunction {
+
+    public static final String NAME = "ENCODE_BINARY";
+
+    public EncodeBinaryFunction() {
+    }
+
+    public EncodeBinaryFunction(List<Expression> children) throws SQLException {
+        super(children);
+    }
+
+    @Override
+    public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
+        Expression expression = getExpression();
+        if (!expression.evaluate(tuple, ptr)) {
+            return false;
+        }
+        if (ptr.getLength() == 0) {
+            return true;
+        }
+
+        byte[] bytesToEncode = ptr.copyBytes();
+        Expression encodingExpression = getEncodingExpression();
+
+        if (!encodingExpression.evaluate(tuple, ptr)) {
+            return false;
+        }
+
+        if (ptr.getLength() == 0) {
+            throw new IllegalDataException(getMissingEncodeFormatMsg());
+        }
+
+        PDataType type = encodingExpression.getDataType();
+        String encodingFormat = ((String) type.toObject(ptr)).toUpperCase();
+        EncodeFormat format = EncodeFormat.valueOf(encodingFormat);
+        String encodedString;
+
+        switch (format) {
+            case HEX:
+                encodedString = toHex(bytesToEncode);
+                break;
+            case BASE64:
+                encodedString = Base64.getEncoder().encodeToString(bytesToEncode);

Review Comment:
   Yes, it looks like a simple getter for a class member.



-- 
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-unsubscribe@phoenix.apache.org

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


Re: [PR] PHOENIX-7424 Support toStringBinary/toBytesBinary conversion [phoenix]

Posted by "stoty (via GitHub)" <gi...@apache.org>.
stoty commented on code in PR #2020:
URL: https://github.com/apache/phoenix/pull/2020#discussion_r1848281076


##########
phoenix-core-client/src/main/java/org/apache/phoenix/expression/function/EncodeBinaryFunction.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.phoenix.expression.function;
+
+import static org.apache.hadoop.hbase.util.Bytes.toHex;
+
+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.types.PVarchar;
+import org.apache.phoenix.schema.types.PVarbinary;
+import org.apache.phoenix.schema.tuple.Tuple;
+
+/**
+ * Encodes binary data into a string from various formats such as Hex, Base64, or HBase binary.
+ */
+@FunctionParseNode.BuiltInFunction(name = EncodeBinaryFunction.NAME, args = {
+    @FunctionParseNode.Argument(allowedTypes = {PVarbinary.class}),
+    @FunctionParseNode.Argument(enumeration = "EncodeFormat")})
+public class EncodeBinaryFunction extends ScalarFunction {
+
+    public static final String NAME = "ENCODE_BINARY";
+
+    public EncodeBinaryFunction() {
+    }
+
+    public EncodeBinaryFunction(List<Expression> children) throws SQLException {
+        super(children);
+    }
+
+    @Override
+    public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
+        Expression expression = getExpression();
+        if (!expression.evaluate(tuple, ptr)) {
+            return false;
+        }
+        if (ptr.getLength() == 0) {
+            return true;
+        }
+
+        byte[] bytesToEncode = ptr.copyBytes();
+        Expression encodingExpression = getEncodingExpression();
+
+        if (!encodingExpression.evaluate(tuple, ptr)) {
+            return false;
+        }
+
+        if (ptr.getLength() == 0) {
+            throw new IllegalDataException(getMissingEncodeFormatMsg());
+        }
+
+        PDataType type = encodingExpression.getDataType();
+        String encodingFormat = ((String) type.toObject(ptr)).toUpperCase();
+        EncodeFormat format = EncodeFormat.valueOf(encodingFormat);
+        String encodedString;
+
+        switch (format) {
+            case HEX:
+                encodedString = toHex(bytesToEncode);
+                break;
+            case BASE64:
+                encodedString = Base64.getEncoder().encodeToString(bytesToEncode);

Review Comment:
   It's probably inlined anyway



-- 
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-unsubscribe@phoenix.apache.org

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


Re: [PR] PHOENIX-7424 Support toStringBinary/toBytesBinary conversion [phoenix]

Posted by "stoty (via GitHub)" <gi...@apache.org>.
stoty commented on code in PR #2020:
URL: https://github.com/apache/phoenix/pull/2020#discussion_r1842613261


##########
phoenix-core/src/it/java/org/apache/phoenix/end2end/DecodeBinaryFunctionIT.java:
##########
@@ -0,0 +1,202 @@
+/*
+ * 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.phoenix.end2end;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Arrays;
+
+import org.apache.phoenix.exception.SQLExceptionCode;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(ParallelStatsDisabledTest.class)
+public class DecodeBinaryFunctionIT extends ParallelStatsDisabledIT {
+
+    @Test
+    public void testDecodeHBaseFromEscapedHex() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+
+        String testTable = generateUniqueName();
+        String ddl = "CREATE TABLE " + testTable + " (id INTEGER PRIMARY KEY, data VARCHAR)";
+
+        conn.createStatement().execute(ddl);
+
+        PreparedStatement ps = conn.prepareStatement("UPSERT INTO " + testTable + " (id, data) VALUES (1, 'data')");
+        ps.execute();
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery(
+                "SELECT DECODE_BINARY('\\\\x48\\\\x65\\\\x6C\\\\x6C\\\\x6F\\\\x50" +
+                        "\\\\x68\\\\x6F\\\\x65\\\\x6E\\\\x69\\\\x78', " + "'HBASE') FROM " + testTable);
+        assertTrue(rs.next());
+        byte[] actualBytes = rs.getBytes(1);
+        assertTrue(Arrays.equals("HelloPhoenix".getBytes(), actualBytes));
+    }
+
+    @Test
+    public void testDecodeHBaseFromHexLiteral() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+
+        String testTable = generateUniqueName();
+        String ddl = "CREATE TABLE " + testTable + " (id INTEGER PRIMARY KEY, data VARCHAR)";
+
+        conn.createStatement().execute(ddl);
+
+        PreparedStatement ps = conn.prepareStatement("UPSERT INTO " + testTable + " (id, data) VALUES (1, 'data')");
+        ps.execute();
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery(
+                "SELECT DECODE_BINARY('\\x48\\x65\\x6C\\x6C\\x6F\\x50\\x68\\x6F\\x65\\x6E\\x69\\x78', " +
+                        "'HBASE') FROM " + testTable);
+        assertTrue(rs.next());
+        byte[] actualBytes = rs.getBytes(1);
+        assertTrue(Arrays.equals("HelloPhoenix".getBytes(), actualBytes));
+    }
+
+    @Test
+    public void testInvalidDecodingFormat() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        String testTable = generateUniqueName();
+        String ddl = "CREATE TABLE " + testTable + " (id INTEGER PRIMARY KEY, data VARCHAR)";
+
+        conn.createStatement().execute(ddl);
+
+        try {
+            conn.createStatement().executeQuery("SELECT DECODE_BINARY(data, 'INVALIDFORMAT') FROM " + testTable);
+            fail("Expected an exception for invalid encoding format");
+        } catch (SQLException e) {
+            assertEquals(SQLExceptionCode.TYPE_MISMATCH.getErrorCode(), e.getErrorCode());
+        }
+    }
+
+    @Test
+    public void testNullAndEmptyStringDecoding() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        String testTable = generateUniqueName();
+        String ddl = "CREATE TABLE " + testTable + " (id INTEGER PRIMARY KEY, data VARCHAR)";
+
+        conn.createStatement().execute(ddl);
+
+        ResultSet rs = conn.createStatement().executeQuery("SELECT DECODE_BINARY(data, 'HBASE') FROM " + testTable);
+        assertFalse(rs.next());
+
+        ResultSet rs2 = conn.createStatement().executeQuery("SELECT DECODE_BINARY(NULL, 'HEX') FROM " + testTable);
+        assertFalse(rs2.next());
+    }
+
+    @Test
+    public void testLongBase64Decoding() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+
+        String testTable = generateUniqueName();
+        String ddl = "CREATE TABLE " + testTable + " (id INTEGER PRIMARY KEY, data VARCHAR)";
+        conn.createStatement().execute(ddl);
+
+        String base64Chunk = "SGVsbG9QaG9lbml4";

Review Comment:
   This works because we do not disable padding.



-- 
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-unsubscribe@phoenix.apache.org

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


Re: [PR] PHOENIX-7424 Support toStringBinary/toBytesBinary conversion [phoenix]

Posted by "szucsvillo (via GitHub)" <gi...@apache.org>.
szucsvillo commented on code in PR #2020:
URL: https://github.com/apache/phoenix/pull/2020#discussion_r1848126033


##########
phoenix-core/src/it/java/org/apache/phoenix/end2end/DecodeBinaryFunctionIT.java:
##########
@@ -0,0 +1,202 @@
+/*
+ * 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.phoenix.end2end;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Arrays;
+
+import org.apache.phoenix.exception.SQLExceptionCode;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(ParallelStatsDisabledTest.class)
+public class DecodeBinaryFunctionIT extends ParallelStatsDisabledIT {
+
+    @Test
+    public void testDecodeHBaseFromEscapedHex() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+
+        String testTable = generateUniqueName();
+        String ddl = "CREATE TABLE " + testTable + " (id INTEGER PRIMARY KEY, data VARCHAR)";
+
+        conn.createStatement().execute(ddl);
+
+        PreparedStatement ps = conn.prepareStatement("UPSERT INTO " + testTable + " (id, data) VALUES (1, 'data')");
+        ps.execute();
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery(
+                "SELECT DECODE_BINARY('\\\\x48\\\\x65\\\\x6C\\\\x6C\\\\x6F\\\\x50" +
+                        "\\\\x68\\\\x6F\\\\x65\\\\x6E\\\\x69\\\\x78', " + "'HBASE') FROM " + testTable);
+        assertTrue(rs.next());
+        byte[] actualBytes = rs.getBytes(1);
+        assertTrue(Arrays.equals("HelloPhoenix".getBytes(), actualBytes));
+    }
+
+    @Test
+    public void testDecodeHBaseFromHexLiteral() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+
+        String testTable = generateUniqueName();
+        String ddl = "CREATE TABLE " + testTable + " (id INTEGER PRIMARY KEY, data VARCHAR)";
+
+        conn.createStatement().execute(ddl);
+
+        PreparedStatement ps = conn.prepareStatement("UPSERT INTO " + testTable + " (id, data) VALUES (1, 'data')");
+        ps.execute();
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery(
+                "SELECT DECODE_BINARY('\\x48\\x65\\x6C\\x6C\\x6F\\x50\\x68\\x6F\\x65\\x6E\\x69\\x78', " +
+                        "'HBASE') FROM " + testTable);
+        assertTrue(rs.next());
+        byte[] actualBytes = rs.getBytes(1);
+        assertTrue(Arrays.equals("HelloPhoenix".getBytes(), actualBytes));
+    }
+
+    @Test
+    public void testInvalidDecodingFormat() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        String testTable = generateUniqueName();
+        String ddl = "CREATE TABLE " + testTable + " (id INTEGER PRIMARY KEY, data VARCHAR)";
+
+        conn.createStatement().execute(ddl);
+
+        try {
+            conn.createStatement().executeQuery("SELECT DECODE_BINARY(data, 'INVALIDFORMAT') FROM " + testTable);
+            fail("Expected an exception for invalid encoding format");
+        } catch (SQLException e) {
+            assertEquals(SQLExceptionCode.TYPE_MISMATCH.getErrorCode(), e.getErrorCode());
+        }
+    }
+
+    @Test
+    public void testNullAndEmptyStringDecoding() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        String testTable = generateUniqueName();
+        String ddl = "CREATE TABLE " + testTable + " (id INTEGER PRIMARY KEY, data VARCHAR)";
+
+        conn.createStatement().execute(ddl);
+
+        ResultSet rs = conn.createStatement().executeQuery("SELECT DECODE_BINARY(data, 'HBASE') FROM " + testTable);
+        assertFalse(rs.next());
+
+        ResultSet rs2 = conn.createStatement().executeQuery("SELECT DECODE_BINARY(NULL, 'HEX') FROM " + testTable);
+        assertFalse(rs2.next());
+    }
+
+    @Test
+    public void testLongBase64Decoding() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+
+        String testTable = generateUniqueName();
+        String ddl = "CREATE TABLE " + testTable + " (id INTEGER PRIMARY KEY, data VARCHAR)";
+        conn.createStatement().execute(ddl);
+
+        String base64Chunk = "SGVsbG9QaG9lbml4";

Review Comment:
   You're right. I will also add a separate test case to verify Base64 decoding with padding.



-- 
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-unsubscribe@phoenix.apache.org

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


Re: [PR] PHOENIX-7424 Support toStringBinary/toBytesBinary conversion [phoenix]

Posted by "stoty (via GitHub)" <gi...@apache.org>.
stoty commented on code in PR #2020:
URL: https://github.com/apache/phoenix/pull/2020#discussion_r1848292680


##########
phoenix-core/src/it/java/org/apache/phoenix/end2end/DecodeBinaryFunctionIT.java:
##########
@@ -0,0 +1,202 @@
+/*
+ * 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.phoenix.end2end;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Arrays;
+
+import org.apache.phoenix.exception.SQLExceptionCode;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(ParallelStatsDisabledTest.class)
+public class DecodeBinaryFunctionIT extends ParallelStatsDisabledIT {
+
+    @Test
+    public void testDecodeHBaseFromEscapedHex() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+
+        String testTable = generateUniqueName();
+        String ddl = "CREATE TABLE " + testTable + " (id INTEGER PRIMARY KEY, data VARCHAR)";
+
+        conn.createStatement().execute(ddl);
+
+        PreparedStatement ps = conn.prepareStatement("UPSERT INTO " + testTable + " (id, data) VALUES (1, 'data')");
+        ps.execute();
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery(
+                "SELECT DECODE_BINARY('\\\\x48\\\\x65\\\\x6C\\\\x6C\\\\x6F\\\\x50" +

Review Comment:
   I still don't get why this works.
   I would expect this to result in \H\e\l\l\o\P\h\o\e\n\i\x
   
   Why does the DECODE_BINARY swallow the extra backslashes ?



-- 
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-unsubscribe@phoenix.apache.org

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


Re: [PR] PHOENIX-7424 Support toStringBinary/toBytesBinary conversion [phoenix]

Posted by "stoty (via GitHub)" <gi...@apache.org>.
stoty commented on code in PR #2020:
URL: https://github.com/apache/phoenix/pull/2020#discussion_r1822870069


##########
phoenix-core-client/src/main/java/org/apache/phoenix/expression/function/DecodeBinaryFunction.java:
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.phoenix.expression.function;
+
+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;
+
+/**
+ * Decodes binary data in various formats (Hex, Base64, HBase) by extending the DecodeFunction.
+ * <p>
+ * Usage:
+ * DECODE_BINARY(<input_string>, <format>)
+ *
+ * @param input_string The string to be decoded.
+ * @param format       The encoding format (HEX, BASE64, HBASE).
+ */
+@FunctionParseNode.BuiltInFunction(name = DecodeBinaryFunction.NAME, args = {
+        @FunctionParseNode.Argument(allowedTypes = {PVarchar.class}),
+        @FunctionParseNode.Argument(enumeration = "EncodeFormat")})
+public class DecodeBinaryFunction extends DecodeFunction {

Review Comment:
   This leaves us with a less capable DECODE() function, and the more capable DECODE_BINARY() function.
   
   Since we are only extending the functionality, we could use the exact same implementation, adding more features to DECODE() is not a problem.
   
   The only reason we are adding new functions at all is the "interesting" existing ENCODE() function.



-- 
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-unsubscribe@phoenix.apache.org

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


Re: [PR] PHOENIX-7424 Support toStringBinary/toBytesBinary conversion [phoenix]

Posted by "stoty (via GitHub)" <gi...@apache.org>.
stoty commented on code in PR #2020:
URL: https://github.com/apache/phoenix/pull/2020#discussion_r1842605816


##########
phoenix-core-client/src/main/java/org/apache/phoenix/expression/function/EncodeBinaryFunction.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.phoenix.expression.function;
+
+import static org.apache.hadoop.hbase.util.Bytes.toHex;
+
+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.types.PVarchar;
+import org.apache.phoenix.schema.types.PVarbinary;
+import org.apache.phoenix.schema.tuple.Tuple;
+
+/**
+ * Encodes binary data into a string from various formats such as Hex, Base64, or HBase binary.
+ */
+@FunctionParseNode.BuiltInFunction(name = EncodeBinaryFunction.NAME, args = {
+    @FunctionParseNode.Argument(allowedTypes = {PVarbinary.class}),
+    @FunctionParseNode.Argument(enumeration = "EncodeFormat")})
+public class EncodeBinaryFunction extends ScalarFunction {
+
+    public static final String NAME = "ENCODE_BINARY";
+
+    public EncodeBinaryFunction() {
+    }
+
+    public EncodeBinaryFunction(List<Expression> children) throws SQLException {
+        super(children);
+    }
+
+    @Override
+    public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
+        Expression expression = getExpression();
+        if (!expression.evaluate(tuple, ptr)) {
+            return false;
+        }
+        if (ptr.getLength() == 0) {
+            return true;
+        }
+
+        byte[] bytesToEncode = ptr.copyBytes();
+        Expression encodingExpression = getEncodingExpression();
+
+        if (!encodingExpression.evaluate(tuple, ptr)) {
+            return false;
+        }
+
+        if (ptr.getLength() == 0) {
+            throw new IllegalDataException(getMissingEncodeFormatMsg());
+        }
+
+        PDataType type = encodingExpression.getDataType();
+        String encodingFormat = ((String) type.toObject(ptr)).toUpperCase();
+        EncodeFormat format = EncodeFormat.valueOf(encodingFormat);
+        String encodedString;
+
+        switch (format) {
+            case HEX:
+                encodedString = toHex(bytesToEncode);
+                break;
+            case BASE64:
+                encodedString = Base64.getEncoder().encodeToString(bytesToEncode);

Review Comment:
   How heavy is Base64.getEncoder() ?
   Would storing a static instance be a reasonable optimization ?



-- 
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-unsubscribe@phoenix.apache.org

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


Re: [PR] PHOENIX-7424 Support toStringBinary/toBytesBinary conversion [phoenix]

Posted by "stoty (via GitHub)" <gi...@apache.org>.
stoty commented on code in PR #2020:
URL: https://github.com/apache/phoenix/pull/2020#discussion_r1842603891


##########
phoenix-core-client/src/main/java/org/apache/phoenix/expression/function/EncodeBinaryFunction.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.phoenix.expression.function;
+
+import static org.apache.hadoop.hbase.util.Bytes.toHex;
+
+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.types.PVarchar;
+import org.apache.phoenix.schema.types.PVarbinary;
+import org.apache.phoenix.schema.tuple.Tuple;
+
+/**
+ * Encodes binary data into a string from various formats such as Hex, Base64, or HBase binary.
+ */
+@FunctionParseNode.BuiltInFunction(name = EncodeBinaryFunction.NAME, args = {
+    @FunctionParseNode.Argument(allowedTypes = {PVarbinary.class}),
+    @FunctionParseNode.Argument(enumeration = "EncodeFormat")})
+public class EncodeBinaryFunction extends ScalarFunction {
+
+    public static final String NAME = "ENCODE_BINARY";
+
+    public EncodeBinaryFunction() {
+    }
+
+    public EncodeBinaryFunction(List<Expression> children) throws SQLException {
+        super(children);
+    }
+
+    @Override
+    public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
+        Expression expression = getExpression();
+        if (!expression.evaluate(tuple, ptr)) {
+            return false;
+        }
+        if (ptr.getLength() == 0) {
+            return true;
+        }
+
+        byte[] bytesToEncode = ptr.copyBytes();
+        Expression encodingExpression = getEncodingExpression();
+
+        if (!encodingExpression.evaluate(tuple, ptr)) {
+            return false;
+        }
+
+        if (ptr.getLength() == 0) {
+            throw new IllegalDataException(getMissingEncodeFormatMsg());
+        }
+
+        PDataType type = encodingExpression.getDataType();
+        String encodingFormat = ((String) type.toObject(ptr)).toUpperCase();
+        EncodeFormat format = EncodeFormat.valueOf(encodingFormat);
+        String encodedString;
+
+        switch (format) {
+            case HEX:
+                encodedString = toHex(bytesToEncode);
+                break;
+            case BASE64:
+                encodedString = Base64.getEncoder().encodeToString(bytesToEncode);

Review Comment:
   
   This uses Basic, which should be fine.



-- 
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-unsubscribe@phoenix.apache.org

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


Re: [PR] PHOENIX-7424 Support toStringBinary/toBytesBinary conversion [phoenix]

Posted by "stoty (via GitHub)" <gi...@apache.org>.
stoty commented on code in PR #2020:
URL: https://github.com/apache/phoenix/pull/2020#discussion_r1842610701


##########
phoenix-core/src/it/java/org/apache/phoenix/end2end/DecodeBinaryFunctionIT.java:
##########
@@ -0,0 +1,202 @@
+/*
+ * 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.phoenix.end2end;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Arrays;
+
+import org.apache.phoenix.exception.SQLExceptionCode;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(ParallelStatsDisabledTest.class)
+public class DecodeBinaryFunctionIT extends ParallelStatsDisabledIT {
+
+    @Test
+    public void testDecodeHBaseFromEscapedHex() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+
+        String testTable = generateUniqueName();
+        String ddl = "CREATE TABLE " + testTable + " (id INTEGER PRIMARY KEY, data VARCHAR)";
+
+        conn.createStatement().execute(ddl);
+
+        PreparedStatement ps = conn.prepareStatement("UPSERT INTO " + testTable + " (id, data) VALUES (1, 'data')");
+        ps.execute();
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery(
+                "SELECT DECODE_BINARY('\\\\x48\\\\x65\\\\x6C\\\\x6C\\\\x6F\\\\x50" +

Review Comment:
   Having four blackslashes doesn not seem right.
   The other examples have only two.
   Java String requires doubling them, by why do we need to double them again ?



-- 
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-unsubscribe@phoenix.apache.org

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


Re: [PR] PHOENIX-7424 Support toStringBinary/toBytesBinary conversion [phoenix]

Posted by "szucsvillo (via GitHub)" <gi...@apache.org>.
szucsvillo commented on code in PR #2020:
URL: https://github.com/apache/phoenix/pull/2020#discussion_r1848125253


##########
phoenix-core/src/it/java/org/apache/phoenix/end2end/DecodeBinaryFunctionIT.java:
##########
@@ -0,0 +1,202 @@
+/*
+ * 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.phoenix.end2end;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Arrays;
+
+import org.apache.phoenix.exception.SQLExceptionCode;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(ParallelStatsDisabledTest.class)
+public class DecodeBinaryFunctionIT extends ParallelStatsDisabledIT {
+
+    @Test
+    public void testDecodeHBaseFromEscapedHex() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+
+        String testTable = generateUniqueName();
+        String ddl = "CREATE TABLE " + testTable + " (id INTEGER PRIMARY KEY, data VARCHAR)";
+
+        conn.createStatement().execute(ddl);
+
+        PreparedStatement ps = conn.prepareStatement("UPSERT INTO " + testTable + " (id, data) VALUES (1, 'data')");
+        ps.execute();
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery(
+                "SELECT DECODE_BINARY('\\\\x48\\\\x65\\\\x6C\\\\x6C\\\\x6F\\\\x50" +

Review Comment:
   I wasn't entirely sure whether we needed both tests for fully escaped strings and hex literals. They both cover similar cases of encoding, so I've removed the duplicate test.



-- 
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-unsubscribe@phoenix.apache.org

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


Re: [PR] PHOENIX-7424 Support toStringBinary/toBytesBinary conversion [phoenix]

Posted by "stoty (via GitHub)" <gi...@apache.org>.
stoty commented on code in PR #2020:
URL: https://github.com/apache/phoenix/pull/2020#discussion_r1842596235


##########
phoenix-core-client/src/main/java/org/apache/phoenix/expression/function/DecodeFunction.java:
##########
@@ -1,11 +1,10 @@
 /*
- * 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
+ * Licensed to the Apache Software Foundation (ASF) under one or more

Review Comment:
   Is this the canonical header ?
   I guess the tests will complain if not.



-- 
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-unsubscribe@phoenix.apache.org

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