phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pbo...@apache.org
Subject [23/32] phoenix git commit: PHOENIX-4843 InListExpression toString() converts the values in the list to ASC sort order always
Date Wed, 17 Oct 2018 19:46:08 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/f45fd6c5
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/f45fd6c5
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/f45fd6c5

Branch: refs/heads/4.14-cdh5.14
Commit: f45fd6c52b3ec228388363c8f29e60f5affe0488
Parents: 1e32e89
Author: Thomas D'Silva <tdsilva@apache.org>
Authored: Fri Aug 10 01:33:09 2018 +0100
Committer: Pedro Boado <pboado@apache.org>
Committed: Wed Oct 17 20:44:35 2018 +0100

----------------------------------------------------------------------
 .../org/apache/phoenix/end2end/InListIT.java    | 72 ++++++++++++++++++++
 .../phoenix/expression/InListExpression.java    | 11 ++-
 2 files changed, 80 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/f45fd6c5/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..2820fdd 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,73 @@ 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());
+            
+            rs = stmt.executeQuery("SELECT Make, Model FROM " + tenantView + " WHERE MILES_DRIVEN
IN (30000, 40000)");
+            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());
+            
+            viewConn.createStatement().execute("DELETE FROM  " + tenantView + " WHERE MILEAGE
IN (27, 32)");
+            viewConn.commit();
+            rs = stmt.executeQuery("SELECT Make, Model FROM " + tenantView);
+            assertTrue(rs.next());
+            assertEquals("AUDI", rs.getString(1));
+            assertEquals("a5", rs.getString(2));
+            assertFalse(rs.next());
+        }
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/f45fd6c5/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..61fa05c 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,15 @@ public class InListExpression extends BaseSingleExpression {
         PDataType type = firstChild.getDataType();
         StringBuilder buf = new StringBuilder(firstChild + " IN (");
         for (ImmutableBytesPtr value : values) {
-            if (firstChild.getSortOrder() != null) {
-                type.coerceBytes(value, type, firstChild.getSortOrder(), SortOrder.getDefault());
+            ImmutableBytesWritable currValue = value;
+            if (firstChild.getSortOrder() != null && !firstChild.getSortOrder().equals(SortOrder.getDefault()))
{
+                // if we have to invert the bytes create a new ImmutableBytesWritable so
that the
+                // original value is not changed
+                currValue = new ImmutableBytesWritable(value);
+                type.coerceBytes(currValue, type, firstChild.getSortOrder(),
+                    SortOrder.getDefault());
             }
-            buf.append(type.toStringLiteral(value, null));
+            buf.append(type.toStringLiteral(currValue, null));
             buf.append(',');
             if (buf.length() >= maxToStringLen) {
                 buf.append("... ");


Mime
View raw message