phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tdsi...@apache.org
Subject [2/2] phoenix git commit: PHOENIX-4843 InListExpression toString() converts the values in the list to ASC sort order always
Date Mon, 13 Aug 2018 17:42:03 GMT
PHOENIX-4843 InListExpression toString() converts the values in the list to ASC sort order
always


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/a2a30443
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/a2a30443
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/a2a30443

Branch: refs/heads/4.x-HBase-1.3
Commit: a2a30443b72a0078e9b31bc9a36aee0be72d6578
Parents: 59f8d0f
Author: Thomas D'Silva <tdsilva@apache.org>
Authored: Thu Aug 9 17:33:09 2018 -0700
Committer: Thomas D'Silva <tdsilva@apache.org>
Committed: Mon Aug 13 10:41:21 2018 -0700

----------------------------------------------------------------------
 .../org/apache/phoenix/end2end/InListIT.java    | 55 ++++++++++++++++++++
 .../phoenix/expression/InListExpression.java    |  5 +-
 2 files changed, 58 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/a2a30443/phoenix-core/src/it/java/org/apache/phoenix/end2end/InListIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/InListIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/InListIT.java
index fe88dc8..871f326 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/InListIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/InListIT.java
@@ -18,6 +18,7 @@
 package org.apache.phoenix.end2end;
 
 import static java.util.Collections.singletonList;
+import static org.apache.phoenix.util.PhoenixRuntime.TENANT_ID_ATTRIB;
 import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -27,6 +28,7 @@ import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.sql.Statement;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
@@ -46,6 +48,8 @@ import com.google.common.collect.Lists;
 
 
 public class InListIT extends ParallelStatsDisabledIT {
+    
+    private final String TENANT_SPECIFIC_URL1 = getUrl() + ';' + TENANT_ID_ATTRIB + "=tenant1";
 
     @Test
     public void testLeadingPKWithTrailingRVC() throws Exception {
@@ -481,5 +485,56 @@ public class InListIT extends ParallelStatsDisabledIT {
         
         conn.close();
     }
+    
+    @Test
+    public void testInListExpressionWithDesc() throws Exception {
+        String fullTableName = generateUniqueName();
+        String fullViewName = generateUniqueName();
+        String tenantView = generateUniqueName();
+        // create base table and global view using global connection
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            Statement stmt = conn.createStatement();
+            stmt.execute("CREATE TABLE " + fullTableName + "(\n" + 
+                    "    TENANT_ID CHAR(15) NOT NULL,\n" + 
+                    "    KEY_PREFIX CHAR(3) NOT NULL,\n" + 
+                    "    CREATED_DATE DATE,\n" + 
+                    "    CREATED_BY CHAR(15),\n" + 
+                    "    SYSTEM_MODSTAMP DATE\n" + 
+                    "    CONSTRAINT PK PRIMARY KEY (\n" + 
+                    "       TENANT_ID," + 
+                    "       KEY_PREFIX" + 
+                    ")) MULTI_TENANT=TRUE");
+            
+            stmt.execute("CREATE VIEW " + fullViewName + "(\n" + 
+                    "    MODEL VARCHAR NOT NULL,\n" + 
+                    "    MILEAGE  BIGINT NOT NULL,\n" +  
+                    "    MILES_DRIVEN BIGINT NOT NULL,\n" + 
+                    "    MAKE VARCHAR,\n" + 
+                    "    CONSTRAINT PKVIEW PRIMARY KEY\n" + 
+                    "    (\n" + 
+                    "    MODEL, MILEAGE DESC, MILES_DRIVEN\n" + 
+                    ")) AS SELECT * FROM " + fullTableName + " WHERE KEY_PREFIX = '0CY'");
+            
+        }
+        
+        // create and use a tenant specific view to write data
+        try (Connection viewConn = DriverManager.getConnection(TENANT_SPECIFIC_URL1) ) {

+            Statement stmt = viewConn.createStatement();
+            stmt.execute("CREATE VIEW IF NOT EXISTS " + tenantView + " AS SELECT * FROM "
+ fullViewName );
+            viewConn.createStatement().execute("UPSERT INTO " + tenantView + "(CREATED_BY,
CREATED_DATE, SYSTEM_MODSTAMP, MODEL, MILEAGE, MILES_DRIVEN, MAKE) VALUES ('005xx000001Sv6o',
1532458254819, 1532458254819, 'a5', 23, 10000, 'AUDI')");
+            viewConn.createStatement().execute("UPSERT INTO " + tenantView + "(CREATED_BY,
CREATED_DATE, SYSTEM_MODSTAMP, MODEL, MILEAGE, MILES_DRIVEN, MAKE) VALUES ('005xx000001Sv6o',
1532458254819, 1532458254819, 'a4', 27, 30000, 'AUDI')");
+            viewConn.createStatement().execute("UPSERT INTO " + tenantView + "(CREATED_BY,
CREATED_DATE, SYSTEM_MODSTAMP, MODEL, MILEAGE, MILES_DRIVEN, MAKE) VALUES ('005xx000001Sv6o',
1532458254819, 1532458254819, '328i', 32, 40000, 'BMW')");
+            viewConn.commit();
+            
+            ResultSet rs = stmt.executeQuery("SELECT Make, Model FROM " + tenantView + "
WHERE MILEAGE IN (32, 27)");
+            assertTrue(rs.next());
+            assertEquals("BMW", rs.getString(1));
+            assertEquals("328i", rs.getString(2));
+            assertTrue(rs.next());
+            assertEquals("AUDI", rs.getString(1));
+            assertEquals("a4", rs.getString(2));
+            assertFalse(rs.next());
+        }
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/a2a30443/phoenix-core/src/main/java/org/apache/phoenix/expression/InListExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/InListExpression.java
b/phoenix-core/src/main/java/org/apache/phoenix/expression/InListExpression.java
index a977f1f..a0a2ccc 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/InListExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/InListExpression.java
@@ -273,10 +273,11 @@ public class InListExpression extends BaseSingleExpression {
         PDataType type = firstChild.getDataType();
         StringBuilder buf = new StringBuilder(firstChild + " IN (");
         for (ImmutableBytesPtr value : values) {
+            ImmutableBytesPtr valueCopy = new ImmutableBytesPtr(value.copyBytes());
             if (firstChild.getSortOrder() != null) {
-                type.coerceBytes(value, type, firstChild.getSortOrder(), SortOrder.getDefault());
+                type.coerceBytes(valueCopy, type, firstChild.getSortOrder(), SortOrder.getDefault());
             }
-            buf.append(type.toStringLiteral(value, null));
+            buf.append(type.toStringLiteral(valueCopy, null));
             buf.append(',');
             if (buf.length() >= maxToStringLen) {
                 buf.append("... ");


Mime
View raw message