This is an automated email from the ASF dual-hosted git repository.

vjasani pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/master by this push:
     new 35b12bc7f4 PHOENIX-7510 VARBINARY_ENCODED should support using hex 
format in WHERE clause (#2058)
35b12bc7f4 is described below

commit 35b12bc7f4e4eabdee2ee3550d21871f98828e44
Author: Viraj Jasani <[email protected]>
AuthorDate: Fri Jan 17 08:24:11 2025 -0800

    PHOENIX-7510 VARBINARY_ENCODED should support using hex format in WHERE 
clause (#2058)
---
 .../phoenix/expression/CoerceExpression.java       |   6 +-
 .../org/apache/phoenix/schema/types/PBinary.java   |   2 +-
 .../phoenix/end2end/VarBinaryEncoded1IT.java       | 203 ++++++++++++++-------
 .../phoenix/end2end/VarBinaryEncoded2IT.java       | 116 +++++++++---
 .../apache/phoenix/schema/types/PDataTypeTest.java |   2 +-
 5 files changed, 238 insertions(+), 91 deletions(-)

diff --git 
a/phoenix-core-client/src/main/java/org/apache/phoenix/expression/CoerceExpression.java
 
b/phoenix-core-client/src/main/java/org/apache/phoenix/expression/CoerceExpression.java
index 548426cfef..f6d5c21d4d 100644
--- 
a/phoenix-core-client/src/main/java/org/apache/phoenix/expression/CoerceExpression.java
+++ 
b/phoenix-core-client/src/main/java/org/apache/phoenix/expression/CoerceExpression.java
@@ -28,6 +28,7 @@ import org.apache.hadoop.io.WritableUtils;
 import org.apache.phoenix.expression.visitor.ExpressionVisitor;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.tuple.Tuple;
+import org.apache.phoenix.schema.types.PBinary;
 import org.apache.phoenix.schema.types.PDataType;
 
 import org.apache.phoenix.schema.types.PVarbinary;
@@ -153,8 +154,9 @@ public class CoerceExpression extends BaseSingleExpression {
         // encode rhs literal value to VARBINARY_ENCODED type. This makes the 
eventual coerce
         // evaluation successful.
         if (getChild() instanceof LiteralExpression
-            && getChild().getDataType() == PVarbinary.INSTANCE
-            && getDataType() == PVarbinaryEncoded.INSTANCE) {
+                && (getChild().getDataType() == PVarbinary.INSTANCE ||
+                getChild().getDataType() == PBinary.INSTANCE)
+                && getDataType() == PVarbinaryEncoded.INSTANCE) {
             Expression expression;
             try {
                 expression =
diff --git 
a/phoenix-core-client/src/main/java/org/apache/phoenix/schema/types/PBinary.java
 
b/phoenix-core-client/src/main/java/org/apache/phoenix/schema/types/PBinary.java
index d35e8a5bf5..f5e250f057 100644
--- 
a/phoenix-core-client/src/main/java/org/apache/phoenix/schema/types/PBinary.java
+++ 
b/phoenix-core-client/src/main/java/org/apache/phoenix/schema/types/PBinary.java
@@ -141,7 +141,7 @@ public class PBinary extends PBinaryBase {
 
     @Override
     public boolean isCoercibleTo(PDataType targetType) {
-        return equalsAny(targetType, this, PVarbinary.INSTANCE);
+        return equalsAny(targetType, this, PVarbinary.INSTANCE, 
PVarbinaryEncoded.INSTANCE);
     }
 
     @Override
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/VarBinaryEncoded1IT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/VarBinaryEncoded1IT.java
index 70ea99d2a8..28e13ec676 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/VarBinaryEncoded1IT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/VarBinaryEncoded1IT.java
@@ -26,6 +26,7 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.Properties;
 
+import org.apache.phoenix.schema.types.PVarbinary;
 import org.junit.Assert;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
@@ -43,8 +44,10 @@ import static 
org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
 public class VarBinaryEncoded1IT extends ParallelStatsDisabledIT {
 
   private final String tableDDLOptions;
+  private final boolean isBindStatement;
 
-  public VarBinaryEncoded1IT(boolean columnEncoded, String 
transactionProvider, boolean mutable) {
+  public VarBinaryEncoded1IT(boolean columnEncoded, String 
transactionProvider, boolean mutable,
+                             boolean isBindStatement) {
     StringBuilder optionBuilder = new StringBuilder();
     if (!columnEncoded) {
       if (optionBuilder.length() != 0) {
@@ -71,20 +74,29 @@ public class VarBinaryEncoded1IT extends 
ParallelStatsDisabledIT {
           " TRANSACTIONAL=true,TRANSACTION_PROVIDER='" + transactionProvider + 
"'");
     }
     this.tableDDLOptions = optionBuilder.toString();
+    this.isBindStatement = isBindStatement;
   }
 
   @Parameterized.Parameters(name =
-      "VarBinary1IT_columnEncoded={0}, transactionProvider={1}, mutable={2}")
+          "VarBinary1IT_columnEncoded={0}, transactionProvider={1}, 
mutable={2}")
   public static synchronized Collection<Object[]> data() {
-    return Arrays.asList(new Object[][] {
-        {false, null, false},
-        {false, "OMID", false},
-        {false, null, true},
-        {false, "OMID", true},
-        {true, null, false},
-        {true, "OMID", false},
-        {true, null, true},
-        {true, "OMID", true},
+    return Arrays.asList(new Object[][]{
+            {false, null, false, false},
+            {false, "OMID", false, false},
+            {false, null, true, false},
+            {false, "OMID", true, false},
+            {true, null, false, false},
+            {true, "OMID", false, false},
+            {true, null, true, false},
+            {true, "OMID", true, false},
+            {false, null, false, true},
+            {false, "OMID", false, true},
+            {false, null, true, true},
+            {false, "OMID", true, true},
+            {true, null, false, true},
+            {true, "OMID", false, true},
+            {true, null, true, true},
+            {true, "OMID", true, true}
     });
   }
 
@@ -240,11 +252,16 @@ public class VarBinaryEncoded1IT extends 
ParallelStatsDisabledIT {
 
       Assert.assertFalse(resultSet.next());
 
-      PreparedStatement preparedStatement =
-          conn.prepareStatement("SELECT * FROM " + tableName + " WHERE PK1 = 
?");
-
-      preparedStatement.setBytes(1, b11);
-      resultSet = preparedStatement.executeQuery();
+      PreparedStatement preparedStatement;
+      if (isBindStatement) {
+        preparedStatement =
+                conn.prepareStatement("SELECT * FROM " + tableName + " WHERE 
PK1 = ?");
+        preparedStatement.setBytes(1, b11);
+        resultSet = preparedStatement.executeQuery();
+      } else {
+        resultSet = conn.createStatement().executeQuery("SELECT * FROM " + 
tableName
+                + " WHERE PK1 = " + PVarbinary.INSTANCE.toStringLiteral(b11));
+      }
 
       Assert.assertTrue(resultSet.next());
 
@@ -294,11 +311,16 @@ public class VarBinaryEncoded1IT extends 
ParallelStatsDisabledIT {
       Assert.assertFalse(resultSet.next());
 
 
-      preparedStatement = conn.prepareStatement(
-          "SELECT * FROM " + tableName + " WHERE PK1 = ? AND PK2 IS NOT NULL 
");
-
-      preparedStatement.setBytes(1, b11);
-      resultSet = preparedStatement.executeQuery();
+      if (isBindStatement) {
+        preparedStatement = conn.prepareStatement(
+                "SELECT * FROM " + tableName + " WHERE PK1 = ? AND PK2 IS NOT 
NULL ");
+        preparedStatement.setBytes(1, b11);
+        resultSet = preparedStatement.executeQuery();
+      } else {
+        resultSet = conn.createStatement().executeQuery(
+                "SELECT * FROM " + tableName + " WHERE PK1 = " +
+                        PVarbinary.INSTANCE.toStringLiteral(b11) + " AND PK2 
IS NOT NULL");
+      }
 
       Assert.assertTrue(resultSet.next());
 
@@ -338,11 +360,17 @@ public class VarBinaryEncoded1IT extends 
ParallelStatsDisabledIT {
 
       Assert.assertFalse(resultSet.next());
 
-      preparedStatement =
-          conn.prepareStatement("SELECT * FROM " + tableName + " WHERE PK1 = ? 
AND PK2 = ?");
-      preparedStatement.setBytes(1, b11);
-      preparedStatement.setBytes(2, b21);
-      resultSet = preparedStatement.executeQuery();
+      if (isBindStatement) {
+        preparedStatement =
+                conn.prepareStatement("SELECT * FROM " + tableName + " WHERE 
PK1 = ? AND PK2 = ?");
+        preparedStatement.setBytes(1, b11);
+        preparedStatement.setBytes(2, b21);
+        resultSet = preparedStatement.executeQuery();
+      } else {
+        resultSet = conn.createStatement().executeQuery("SELECT * FROM " + 
tableName + " WHERE " +
+                "PK1 = " + PVarbinary.INSTANCE.toStringLiteral(b11) + " AND 
PK2 = " +
+                PVarbinary.INSTANCE.toStringLiteral(b21));
+      }
 
       Assert.assertTrue(resultSet.next());
 
@@ -373,12 +401,21 @@ public class VarBinaryEncoded1IT extends 
ParallelStatsDisabledIT {
 
       Assert.assertFalse(resultSet.next());
 
-      preparedStatement = conn.prepareStatement("SELECT * FROM " + tableName
-          + " WHERE PK1 = ? AND PK2 BETWEEN ? AND ? AND PK3 IS NOT NULL");
-      preparedStatement.setBytes(1, b11);
-      preparedStatement.setBytes(2, new byte[] {57, -83, 0, -2, 0, -7, -12, 
-13, 3, 24, -121});
-      preparedStatement.setBytes(3, new byte[] {57, -83, 0, -2, 0, -7, -12, 
-13, 4});
-      resultSet = preparedStatement.executeQuery();
+      if (isBindStatement) {
+        preparedStatement = conn.prepareStatement("SELECT * FROM " + tableName
+                + " WHERE PK1 = ? AND PK2 BETWEEN ? AND ? AND PK3 IS NOT 
NULL");
+        preparedStatement.setBytes(1, b11);
+        preparedStatement.setBytes(2, new byte[]{57, -83, 0, -2, 0, -7, -12, 
-13, 3, 24, -121});
+        preparedStatement.setBytes(3, new byte[]{57, -83, 0, -2, 0, -7, -12, 
-13, 4});
+        resultSet = preparedStatement.executeQuery();
+      } else {
+        resultSet = conn.createStatement().executeQuery("SELECT * FROM " + 
tableName
+                + " WHERE PK1 = " + PVarbinary.INSTANCE.toStringLiteral(b11) + 
" AND PK2 BETWEEN "
+                + PVarbinary.INSTANCE.toStringLiteral(
+                new byte[]{57, -83, 0, -2, 0, -7, -12, -13, 3, 24, -121}) + " 
AND " +
+                PVarbinary.INSTANCE.toStringLiteral(
+                        new byte[]{57, -83, 0, -2, 0, -7, -12, -13, 4}) + " 
AND PK3 IS NOT NULL");
+      }
 
       Assert.assertTrue(resultSet.next());
 
@@ -400,13 +437,21 @@ public class VarBinaryEncoded1IT extends 
ParallelStatsDisabledIT {
 
       Assert.assertFalse(resultSet.next());
 
-      preparedStatement = conn.prepareStatement("SELECT * FROM " + tableName
-          + " WHERE PK1 = ? AND PK2 IN (?, ?, ?)");
-      preparedStatement.setBytes(1, b11);
-      preparedStatement.setBytes(2, b21);
-      preparedStatement.setBytes(3, b23);
-      preparedStatement.setBytes(4, b22);
-      resultSet = preparedStatement.executeQuery();
+      if (isBindStatement) {
+        preparedStatement = conn.prepareStatement("SELECT * FROM " + tableName
+                + " WHERE PK1 = ? AND PK2 IN (?, ?, ?)");
+        preparedStatement.setBytes(1, b11);
+        preparedStatement.setBytes(2, b21);
+        preparedStatement.setBytes(3, b23);
+        preparedStatement.setBytes(4, b22);
+        resultSet = preparedStatement.executeQuery();
+      } else {
+        resultSet = conn.createStatement().executeQuery("SELECT * FROM " + 
tableName
+                + " WHERE PK1 = " + PVarbinary.INSTANCE.toStringLiteral(b11) + 
" AND PK2 IN (" +
+                PVarbinary.INSTANCE.toStringLiteral(b21) + ", " +
+                PVarbinary.INSTANCE.toStringLiteral(b23) + ", " +
+                PVarbinary.INSTANCE.toStringLiteral(b22) + ")");
+      }
 
       Assert.assertTrue(resultSet.next());
 
@@ -446,12 +491,20 @@ public class VarBinaryEncoded1IT extends 
ParallelStatsDisabledIT {
 
       Assert.assertFalse(resultSet.next());
 
-      preparedStatement = conn.prepareStatement(
-          "SELECT * FROM " + tableName + " WHERE PK1 = ? AND PK2 = ? AND PK3 = 
?");
-      preparedStatement.setBytes(1, b11);
-      preparedStatement.setBytes(2, b21);
-      preparedStatement.setBytes(3, b31);
-      resultSet = preparedStatement.executeQuery();
+      if (isBindStatement) {
+        preparedStatement = conn.prepareStatement(
+                "SELECT * FROM " + tableName + " WHERE PK1 = ? AND PK2 = ? AND 
PK3 = ?");
+        preparedStatement.setBytes(1, b11);
+        preparedStatement.setBytes(2, b21);
+        preparedStatement.setBytes(3, b31);
+        resultSet = preparedStatement.executeQuery();
+      } else {
+        resultSet = conn.createStatement().executeQuery(
+                "SELECT * FROM " + tableName + " WHERE PK1 = " +
+                        PVarbinary.INSTANCE.toStringLiteral(b11) + " AND PK2 = 
" +
+                        PVarbinary.INSTANCE.toStringLiteral(b21) + " AND PK3 = 
" +
+                        PVarbinary.INSTANCE.toStringLiteral(b31));
+      }
 
       Assert.assertTrue(resultSet.next());
 
@@ -464,11 +517,18 @@ public class VarBinaryEncoded1IT extends 
ParallelStatsDisabledIT {
 
       Assert.assertFalse(resultSet.next());
 
-      preparedStatement = conn.prepareStatement(
-          "SELECT * FROM " + tableName + " WHERE PK1 = ? AND PK2 = ? AND PK3 
IS NULL");
-      preparedStatement.setBytes(1, b11);
-      preparedStatement.setBytes(2, b21);
-      resultSet = preparedStatement.executeQuery();
+      if (isBindStatement) {
+        preparedStatement = conn.prepareStatement(
+                "SELECT * FROM " + tableName + " WHERE PK1 = ? AND PK2 = ? AND 
PK3 IS NULL");
+        preparedStatement.setBytes(1, b11);
+        preparedStatement.setBytes(2, b21);
+        resultSet = preparedStatement.executeQuery();
+      } else {
+        resultSet = conn.createStatement().executeQuery(
+                "SELECT * FROM " + tableName + " WHERE PK1 = " +
+                        PVarbinary.INSTANCE.toStringLiteral(b11) + " AND PK2 = 
" +
+                        PVarbinary.INSTANCE.toStringLiteral(b21) + " AND PK3 
IS NULL");
+      }
 
       Assert.assertTrue(resultSet.next());
 
@@ -2066,12 +2126,21 @@ public class VarBinaryEncoded1IT extends 
ParallelStatsDisabledIT {
 
       Assert.assertFalse(resultSet.next());
 
-      preparedStatement = conn.prepareStatement("SELECT * FROM " + tableName
-          + " WHERE PK1 = ? AND PK2 BETWEEN ? AND ? AND PK3 IS NOT NULL");
-      preparedStatement.setDouble(1, b11);
-      preparedStatement.setBytes(2, new byte[] {57, -83, 0, -2, 0, -7, -12, 
-13, 3, 24, -121});
-      preparedStatement.setBytes(3, new byte[] {57, -83, 0, -2, 0, -7, -12, 
-13, 4});
-      resultSet = preparedStatement.executeQuery();
+      if (isBindStatement) {
+        preparedStatement = conn.prepareStatement("SELECT * FROM " + tableName
+                + " WHERE PK1 = ? AND PK2 BETWEEN ? AND ? AND PK3 IS NOT 
NULL");
+        preparedStatement.setDouble(1, b11);
+        preparedStatement.setBytes(2, new byte[]{57, -83, 0, -2, 0, -7, -12, 
-13, 3, 24, -121});
+        preparedStatement.setBytes(3, new byte[]{57, -83, 0, -2, 0, -7, -12, 
-13, 4});
+        resultSet = preparedStatement.executeQuery();
+      } else {
+        resultSet = conn.createStatement().executeQuery("SELECT * FROM " + 
tableName
+                + " WHERE PK1 = " + b11 +
+                " AND PK2 BETWEEN " + PVarbinary.INSTANCE.toStringLiteral(
+                new byte[]{57, -83, 0, -2, 0, -7, -12, -13, 3, 24, -121}) +
+                " AND " + PVarbinary.INSTANCE.toStringLiteral(
+                new byte[]{57, -83, 0, -2, 0, -7, -12, -13, 4}) + " AND PK3 IS 
NOT NULL");
+      }
 
       Assert.assertTrue(resultSet.next());
 
@@ -2093,13 +2162,21 @@ public class VarBinaryEncoded1IT extends 
ParallelStatsDisabledIT {
 
       Assert.assertFalse(resultSet.next());
 
-      preparedStatement = conn.prepareStatement("SELECT * FROM " + tableName
-          + " WHERE PK1 = ? AND PK2 IN (?, ?, ?)");
-      preparedStatement.setDouble(1, b11);
-      preparedStatement.setBytes(2, b21);
-      preparedStatement.setBytes(3, b23);
-      preparedStatement.setBytes(4, b22);
-      resultSet = preparedStatement.executeQuery();
+      if (isBindStatement) {
+        preparedStatement = conn.prepareStatement("SELECT * FROM " + tableName
+                + " WHERE PK1 = ? AND PK2 IN (?, ?, ?)");
+        preparedStatement.setDouble(1, b11);
+        preparedStatement.setBytes(2, b21);
+        preparedStatement.setBytes(3, b23);
+        preparedStatement.setBytes(4, b22);
+        resultSet = preparedStatement.executeQuery();
+      } else {
+        resultSet = conn.createStatement().executeQuery("SELECT * FROM " + 
tableName
+                + " WHERE PK1 = " + b11
+                + " AND PK2 IN (" + PVarbinary.INSTANCE.toStringLiteral(b21) + 
","
+                + PVarbinary.INSTANCE.toStringLiteral(b22) + ", "
+                + PVarbinary.INSTANCE.toStringLiteral(b23) + ")");
+      }
 
       Assert.assertTrue(resultSet.next());
 
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/VarBinaryEncoded2IT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/VarBinaryEncoded2IT.java
index d2441a12ca..bfe97bd9f0 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/VarBinaryEncoded2IT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/VarBinaryEncoded2IT.java
@@ -26,6 +26,7 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.Properties;
 
+import org.apache.phoenix.schema.types.PVarbinary;
 import org.junit.Assert;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
@@ -46,22 +47,28 @@ public class VarBinaryEncoded2IT extends 
ParallelStatsDisabledIT {
 
   private final boolean columnEncoded;
   private final boolean coveredIndex;
+  private final boolean isBindStatement;
 
-  public VarBinaryEncoded2IT(boolean columnEncoded, boolean coveredIndex) {
+  public VarBinaryEncoded2IT(boolean columnEncoded, boolean coveredIndex, 
boolean isBindStatement) {
     this.columnEncoded = columnEncoded;
     this.coveredIndex = coveredIndex;
+    this.isBindStatement = isBindStatement;
   }
 
   @Parameterized.Parameters(name =
       "VarBinary2IT_columnEncoded={0}, coveredIndex={1}")
   public static synchronized Collection<Object[]> data() {
     return Arrays.asList(
-        new Object[][] {
-            {false, false},
-            {false, true},
-            {true, false},
-            {true, true}
-        });
+            new Object[][]{
+                    {false, false, false},
+                    {false, true, false},
+                    {true, false, false},
+                    {true, true, false},
+                    {false, false, true},
+                    {false, true, true},
+                    {true, false, true},
+                    {true, true, true}
+            });
   }
 
   @Test
@@ -147,11 +154,11 @@ public class VarBinaryEncoded2IT extends 
ParallelStatsDisabledIT {
             Bytes.toBytes("col21048rnbfpe3-"), 
Bytes.toBytes("col319efnrugifj"));
         upsertRow(preparedStatement, b10, b20, b30, b40, b50, b60);
         upsertRow(preparedStatement, b1, b2, b3, b4, b5, b6);
-        upsertRow(preparedStatement, b11, b21, b31, b41, b51, b61);
+        upsertRow(conn, tableName, b11, b21, b31, b41, b51, b61);
         upsertRow(preparedStatement, b12, b22, b32, b42, b52, b62);
-        upsertRow(preparedStatement, b13, b23, b33, b43, b53, b63);
+        upsertRow(conn, tableName, b13, b23, b33, b43, b53, b63);
         upsertRow(preparedStatement, b14, b24, b34, b44, b54, b64);
-        upsertRow(preparedStatement, b15, b25, b35, b45, b55, b65);
+        upsertRow(conn, tableName, b15, b25, b35, b45, b55, b65);
         upsertRow(preparedStatement, b16, b26, b36, b46, b56, b66);
       }
       conn.commit();
@@ -271,11 +278,19 @@ public class VarBinaryEncoded2IT extends 
ParallelStatsDisabledIT {
 
       Assert.assertFalse(resultSet.next());
 
-      preparedStatement = conn.prepareStatement("SELECT * FROM " + tableName
-          + " WHERE COL1 = ? AND COL2 BETWEEN ? AND ?");
-      preparedStatement.setString(1, b4);
-      preparedStatement.setBytes(2, b51);
-      preparedStatement.setBytes(3, b5);
+      if (isBindStatement) {
+        preparedStatement = conn.prepareStatement("SELECT * FROM " + tableName
+                + " WHERE COL1 = ? AND COL2 BETWEEN ? AND ?");
+        preparedStatement.setString(1, b4);
+        preparedStatement.setBytes(2, b51);
+        preparedStatement.setBytes(3, b5);
+      } else {
+        preparedStatement = conn.prepareStatement("SELECT * FROM " + tableName
+                + " WHERE COL1 = ? AND COL2 BETWEEN "
+                + PVarbinary.INSTANCE.toStringLiteral(b51) + " AND "
+                + PVarbinary.INSTANCE.toStringLiteral(b5));
+        preparedStatement.setString(1, b4);
+      }
 
       assertIndexUsed(preparedStatement, indexName, "RANGE SCAN ");
 
@@ -429,16 +444,16 @@ public class VarBinaryEncoded2IT extends 
ParallelStatsDisabledIT {
 
       try (PreparedStatement preparedStatement = conn.prepareStatement("UPSERT 
INTO " + tableName
           + "(PK1, PK2, PK3, COL1, COL2, COL3) VALUES (?, ?, ?, ?, ?, ?)")) {
-        upsertRow(preparedStatement, Bytes.toBytes("pk1-ehgir4jf"), 
Bytes.toBytes("pk22p0jfdkhrgi"),
+        upsertRow(conn, tableName, Bytes.toBytes("pk1-ehgir4jf"), 
Bytes.toBytes("pk22p0jfdkhrgi"),
             Bytes.toBytes("pk33ogjirhhf"), Bytes.toBytes("col19fnbb0hf0t"),
             Bytes.toBytes("col21048rnbfpe3-"), 
Bytes.toBytes("col319efnrugifj"));
         upsertRow(preparedStatement, b10, b20, b30, b40, b50, b60);
-        upsertRow(preparedStatement, b1, b2, b3, b4, b5, b6);
+        upsertRow(conn, tableName, b1, b2, b3, b4, b5, b6);
         upsertRow(preparedStatement, b11, b21, b31, b41, b51, b61);
         upsertRow(preparedStatement, b12, b22, b32, b42, b52, b62);
-        upsertRow(preparedStatement, b13, b23, b33, b43, b53, b63);
+        upsertRow(conn, tableName, b13, b23, b33, b43, b53, b63);
         upsertRow(preparedStatement, b14, b24, b34, b44, b54, b64);
-        upsertRow(preparedStatement, b15, b25, b35, b45, b55, b65);
+        upsertRow(conn, tableName, b15, b25, b35, b45, b55, b65);
         upsertRow(preparedStatement, b16, b26, b36, b46, b56, b66);
       }
       conn.commit();
@@ -597,11 +612,18 @@ public class VarBinaryEncoded2IT extends 
ParallelStatsDisabledIT {
 
       Assert.assertFalse(resultSet.next());
 
-      preparedStatement = conn.prepareStatement("SELECT * FROM " + tableName
-          + " WHERE COL1 = ? AND COL2 IN (?, ?)");
-      preparedStatement.setBytes(1, b4);
-      preparedStatement.setBytes(2, b51);
-      preparedStatement.setBytes(3, b5);
+      if (isBindStatement) {
+        preparedStatement = conn.prepareStatement("SELECT * FROM " + tableName
+                + " WHERE COL1 = ? AND COL2 IN (?, ?)");
+        preparedStatement.setBytes(1, b4);
+        preparedStatement.setBytes(2, b51);
+        preparedStatement.setBytes(3, b5);
+      } else {
+        preparedStatement = conn.prepareStatement("SELECT * FROM " + tableName
+                + " WHERE COL1 = " + PVarbinary.INSTANCE.toStringLiteral(b4)
+                + " AND COL2 IN (" + PVarbinary.INSTANCE.toStringLiteral(b51) 
+ ", "
+                + PVarbinary.INSTANCE.toStringLiteral(b5) + ")");
+      }
 
       assertIndexUsed(preparedStatement, indexName, "SKIP SCAN ON 2 KEYS ");
 
@@ -1230,6 +1252,29 @@ public class VarBinaryEncoded2IT extends 
ParallelStatsDisabledIT {
     preparedStatement.executeUpdate();
   }
 
+  private static void upsertRow(Connection conn, String tableName, byte[] b10, 
byte[] b20,
+                                byte[] b30, byte[] b40, byte[] b50, byte[] b60)
+          throws SQLException {
+    if (b30 != null) {
+      conn.createStatement().executeUpdate("UPSERT INTO " + tableName
+              + "(PK1, PK2, PK3, COL1, COL2, COL3) VALUES ("
+              + PVarbinary.INSTANCE.toStringLiteral(b10) + ", "
+              + PVarbinary.INSTANCE.toStringLiteral(b20) + ", "
+              + PVarbinary.INSTANCE.toStringLiteral(b30) + ", "
+              + PVarbinary.INSTANCE.toStringLiteral(b40) + ", "
+              + PVarbinary.INSTANCE.toStringLiteral(b50) + ", "
+              + PVarbinary.INSTANCE.toStringLiteral(b60) + ")");
+    } else {
+      conn.createStatement().executeUpdate("UPSERT INTO " + tableName
+              + "(PK1, PK2, COL1, COL2, COL3) VALUES ("
+              + PVarbinary.INSTANCE.toStringLiteral(b10) + ", "
+              + PVarbinary.INSTANCE.toStringLiteral(b20) + ", "
+              + PVarbinary.INSTANCE.toStringLiteral(b40) + ", "
+              + PVarbinary.INSTANCE.toStringLiteral(b50) + ", "
+              + PVarbinary.INSTANCE.toStringLiteral(b60) + ")");
+    }
+  }
+
   private static void upsertRow(PreparedStatement preparedStatement, byte[] 
b10, byte[] b20,
       byte[] b30, String b40, byte[] b50, byte[] b60) throws SQLException {
     preparedStatement.setBytes(1, b10);
@@ -1263,4 +1308,27 @@ public class VarBinaryEncoded2IT extends 
ParallelStatsDisabledIT {
     preparedStatement.executeUpdate();
   }
 
+  private static void upsertRow(Connection conn, String tableName, byte[] b13, 
byte[] b23,
+                                byte[] b33, String b43, byte[] b53, byte[] b63)
+          throws SQLException {
+    if (b33 != null) {
+      conn.createStatement().executeUpdate("UPSERT INTO " + tableName
+              + "(PK1, PK2, PK3, COL1, COL2, COL3) VALUES ("
+              + PVarbinary.INSTANCE.toStringLiteral(b13) + ", "
+              + PVarbinary.INSTANCE.toStringLiteral(b23) + ", "
+              + PVarbinary.INSTANCE.toStringLiteral(b33) + ", '"
+              + b43 + "', "
+              + PVarbinary.INSTANCE.toStringLiteral(b53) + ", "
+              + PVarbinary.INSTANCE.toStringLiteral(b63) + ")");
+    } else {
+      conn.createStatement().executeUpdate("UPSERT INTO " + tableName
+              + "(PK1, PK2, COL1, COL2, COL3) VALUES ("
+              + PVarbinary.INSTANCE.toStringLiteral(b13) + ", "
+              + PVarbinary.INSTANCE.toStringLiteral(b23) + ", '"
+              + b43 + "', "
+              + PVarbinary.INSTANCE.toStringLiteral(b53) + ", "
+              + PVarbinary.INSTANCE.toStringLiteral(b63) + ")");
+    }
+  }
+
 }
diff --git 
a/phoenix-core/src/test/java/org/apache/phoenix/schema/types/PDataTypeTest.java 
b/phoenix-core/src/test/java/org/apache/phoenix/schema/types/PDataTypeTest.java
index 1cdb183b81..31b9505d7e 100644
--- 
a/phoenix-core/src/test/java/org/apache/phoenix/schema/types/PDataTypeTest.java
+++ 
b/phoenix-core/src/test/java/org/apache/phoenix/schema/types/PDataTypeTest.java
@@ -1743,7 +1743,7 @@ public class PDataTypeTest {
         assertEquals(
               "{BIGINT=[BIGINT, BINARY, DECIMAL, DOUBLE, VARBINARY], "
              + "BIGINT ARRAY=[BIGINT ARRAY, BINARY ARRAY, DECIMAL ARRAY, 
DOUBLE ARRAY, VARBINARY ARRAY], "
-             + "BINARY=[BINARY, VARBINARY], "
+             + "BINARY=[BINARY, VARBINARY, VARBINARY_ENCODED], "
              + "BINARY ARRAY=[BINARY ARRAY, VARBINARY ARRAY], "
              + "BOOLEAN=[BINARY, BOOLEAN, VARBINARY, VARBINARY_ENCODED], "
              + "BOOLEAN ARRAY=[BINARY ARRAY, BOOLEAN ARRAY, VARBINARY ARRAY], "

Reply via email to