[ 
https://issues.apache.org/jira/browse/PHOENIX-6764?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17601492#comment-17601492
 ] 

ASF GitHub Bot commented on PHOENIX-6764:
-----------------------------------------

gjacoby126 commented on code in PR #1490:
URL: https://github.com/apache/phoenix/pull/1490#discussion_r965208141


##########
phoenix-core/src/test/java/org/apache/phoenix/parse/QueryParserTest.java:
##########
@@ -925,6 +925,31 @@ public void testShowCreateTable() throws Exception {
         // Expected failures.
         parseQueryThatShouldFail("SHOW CREATE VIEW foo");
         parseQueryThatShouldFail("SHOW CREATE TABLE 'foo'");
+    }
+
+    @Test
+    public void testBinaryLiteral() throws Exception {
+        // Happy paths
+        parseQuery("SELECT b, x from x WHERE x = x'00'");
+        parseQuery("SELECT b, x from x WHERE x = "
+                + "x  '0 12 ' --comment \n /* comment */ '34 567' \n \n 'aA'");
+        parseQuery("SELECT b, x from x WHERE x = "
+                + "b  '0 10 ' --comment \n /* comment */ '10 101' \n \n 
'00000000'");
 
+        // Expected failures.

Review Comment:
   Some comments here would be welcome. In particular I'm having trouble seeing 
why 934 should pass and 940 should fail. (I also find it surprising that 934 
and 936 should pass given the use of whitespace in the WHERE clause.) 



##########
phoenix-core/src/it/java/org/apache/phoenix/end2end/BinaryStringLiteralIT.java:
##########
@@ -0,0 +1,143 @@
+/*
+ * 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 java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+/**
+ * End to end tests for Hexadecimal and Binary literals
+ */
+@Category(ParallelStatsDisabledTest.class)
+public class BinaryStringLiteralIT extends ParallelStatsDisabledIT {
+
+    private static String EMPTY = "";
+    private static String THREE_HEX = "0001AA";
+    private static String NINE_HEX = "0102030405607080F0";
+
+    private static String THREE_BIN = "00000000" + "00000001" + "10101010";
+    private static String NINE_BIN =
+            "00000001" + "00000010" + "00000011" + "00000100" + "00000101" + 
"01100000" + "01110000"
+                    + "10000000" + "11110000";
+
+    private String PARSER_STRESS = "x '0 12 ' --comment \n /* comment */ '34 
567' \n \n 'aA'";
+
+    private String toHex(String s) {
+        return "X'" + s + "'";
+    }
+
+    private String toBin(String s) {
+        return "B'" + s + "'";
+    }
+
+    private void insertRow(Statement stmt, String tableName, int id, String s) 
throws SQLException {
+        stmt.executeUpdate("UPSERT INTO " + tableName + " VALUES (" + id + "," 
+ s + "," + s + ")");
+    }
+
+    @Test
+    public void testBinary() throws Exception {
+        String tableName = generateUniqueName();
+
+        try (Connection conn = DriverManager.getConnection(getUrl());
+                Statement stmt = conn.createStatement();) {
+            String ddl =
+                    "CREATE TABLE " + tableName
+                            + " (id INTEGER NOT NULL PRIMARY KEY, b 
BINARY(10), vb VARBINARY)";
+            stmt.execute(ddl);
+            conn.commit();
+
+            insertRow(stmt, tableName, 1, toHex(EMPTY));
+            insertRow(stmt, tableName, 3, toHex(THREE_HEX));
+            insertRow(stmt, tableName, 9, toHex(NINE_HEX));
+            insertRow(stmt, tableName, 10, PARSER_STRESS);
+
+            insertRow(stmt, tableName, 101, toBin(EMPTY));
+            insertRow(stmt, tableName, 103, toBin(THREE_BIN));
+            insertRow(stmt, tableName, 109, toBin(NINE_BIN));
+
+            conn.commit();
+            ResultSet rs = stmt.executeQuery("SELECT * FROM " + tableName + " 
ORDER BY ID ASC");
+            assertTrue(rs.next());
+            assertEquals(1, rs.getInt(1));
+            assertEquals(null, rs.getString(2));
+            assertEquals(null, rs.getString(3));
+
+            assertTrue(rs.next());
+            assertEquals(3, rs.getInt(1));
+            assertEquals("0001aa00000000000000", rs.getString(2));
+            assertEquals("0001aa", rs.getString(3));
+
+            assertTrue(rs.next());
+            assertEquals(9, rs.getInt(1));
+            assertEquals("0102030405607080f000", rs.getString(2));
+            assertEquals("0102030405607080f0", rs.getString(3));
+
+            assertTrue(rs.next());
+            assertEquals(10, rs.getInt(1));
+            assertEquals("01234567aa0000000000", rs.getString(2));
+            assertEquals("01234567aa", rs.getString(3));
+
+            assertTrue(rs.next());
+            assertEquals(101, rs.getInt(1));
+            assertEquals(null, rs.getString(2));
+            assertEquals(null, rs.getString(3));
+
+            assertTrue(rs.next());
+            assertEquals(103, rs.getInt(1));
+            assertEquals("0001aa00000000000000", rs.getString(2));
+            assertEquals("0001aa", rs.getString(3));
+
+            assertTrue(rs.next());
+            assertEquals(109, rs.getInt(1));
+            assertEquals("0102030405607080f000", rs.getString(2));
+            assertEquals("0102030405607080f0", rs.getString(3));
+
+            assertFalse(rs.next());
+        }
+    }
+
+    @Test
+    public void testBinaryArray() throws Exception {
+        String tableName = generateUniqueName();
+
+        try (Connection conn = DriverManager.getConnection(getUrl());
+                Statement stmt = conn.createStatement();) {
+            String ddl =
+                    "CREATE TABLE " + tableName
+                            + " (id INTEGER NOT NULL PRIMARY KEY, b 
BINARY(10), a BINARY(10)[])";
+            stmt.execute(ddl);
+            conn.commit();
+
+            //FIXME why does not this work ?

Review Comment:
   nit: comment can be removed if this has been fixed





> Implement Binary and Hexadecimal literals
> -----------------------------------------
>
>                 Key: PHOENIX-6764
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-6764
>             Project: Phoenix
>          Issue Type: Bug
>          Components: core
>            Reporter: Istvan Toth
>            Assignee: Istvan Toth
>            Priority: Major
>
> Currently there is no sane way to specify arbitrary binary and varbinary 
> values in the query string.
> They can be set as variables for preparedstatements, and if the length 
> corresponds to an existing type, then some casting gymnastics can be used to 
> work around the problem, but I have not found a way to write a query that 
> upserts an arbitrary three byte value into a binary/varbinary.
> The SQL standard defines Binary and Hex literals in the form of 
> B'01010101001...' and X'0102AAF5...'
> Implement this in the parser.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to