phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tdsi...@apache.org
Subject phoenix git commit: Filters on Tables and Views with composite PK of VARCHAR fields with sort direction DESC do not work
Date Thu, 19 Oct 2017 04:01:19 GMT
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-0.98 9c7dbab85 -> ec1160ebb


Filters on Tables and Views with composite PK of VARCHAR fields with sort direction DESC do
not work


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

Branch: refs/heads/4.x-HBase-0.98
Commit: ec1160ebb24d8bf22e698eab82601743c4a1aa8a
Parents: 9c7dbab
Author: Thomas D'Silva <tdsilva@apache.org>
Authored: Wed Oct 18 18:39:18 2017 -0700
Committer: Thomas D'Silva <tdsilva@apache.org>
Committed: Wed Oct 18 20:58:36 2017 -0700

----------------------------------------------------------------------
 .../java/org/apache/phoenix/end2end/ViewIT.java | 74 ++++++++++++++++++++
 .../org/apache/phoenix/schema/ValueSchema.java  |  2 +-
 2 files changed, 75 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/ec1160eb/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java
index 1953f79..66e2430 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java
@@ -790,4 +790,78 @@ public class ViewIT extends BaseViewIT {
         String[] actualPKs = pkCols.toArray(new String[0]);
         assertArrayEquals(expectedPKs, actualPKs);
     }
+
+	@Test
+	public void testCompositeDescPK() throws SQLException {
+		Properties props = new Properties();
+		try (Connection globalConn = DriverManager.getConnection(getUrl(), props)) {
+			String tableName = generateUniqueName();
+			String viewName = generateUniqueName();
+
+			// create global base table
+			globalConn.createStatement().execute("CREATE TABLE " + tableName
+					+ " (TENANT_ID CHAR(15) NOT NULL, KEY_PREFIX CHAR(3) NOT NULL, CREATED_DATE DATE, CREATED_BY
CHAR(15), SYSTEM_MODSTAMP DATE CONSTRAINT PK PRIMARY KEY (TENANT_ID, KEY_PREFIX)) VERSIONS=1,
MULTI_TENANT=true, IMMUTABLE_ROWS=TRUE, REPLICATION_SCOPE=1");
+
+			// create various tenant specific views
+			globalConn.createStatement()
+					.execute("CREATE VIEW " + viewName
+							+ " (pk1 VARCHAR(10) NOT NULL, pk2 VARCHAR(10) NOT NULL, col1 DATE, col3 DECIMAL CONSTRAINT
PK PRIMARY KEY (pk1 DESC, pk2 DESC)) AS SELECT * FROM "
+							+ tableName + " WHERE KEY_PREFIX = 'abc' ");
+
+			String tenantId = "tenantId";
+			Properties tenantProps = new Properties();
+			tenantProps.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId);
+			// create a tenant specific view
+			try (Connection tenantConn = DriverManager.getConnection(getUrl(), tenantProps)) {
+				// upsert rows
+				tenantConn.createStatement().execute("UPSERT INTO " + viewName
+						+ " (pk1, pk2, col1, col3) VALUES ('testa', 'testb', TO_DATE('2017-10-16 22:00:00',
'yyyy-MM-dd HH:mm:ss'), 10)");
+				tenantConn.createStatement().execute("UPSERT INTO " + viewName
+						+ " (pk1, pk2, col1, col3) VALUES ('testa', 'testc', TO_DATE('2017-10-16 22:00:00',
'yyyy-MM-dd HH:mm:ss'), 10)");
+				tenantConn.createStatement().execute("UPSERT INTO " + viewName
+						+ " (pk1, pk2, col1, col3) VALUES ('testa', 'testd', TO_DATE('2017-10-16 22:00:00',
'yyyy-MM-dd HH:mm:ss'), 10)");
+				tenantConn.createStatement().execute("UPSERT INTO " + viewName
+						+ " (pk1, pk2, col1, col3) VALUES ('testa', 'teste', TO_DATE('2017-10-16 22:00:00',
'yyyy-MM-dd HH:mm:ss'), 10)");
+				tenantConn.createStatement().execute("UPSERT INTO " + viewName
+						+ " (pk1, pk2, col1, col3) VALUES ('testb', 'testa', TO_DATE('2017-10-16 22:00:00',
'yyyy-MM-dd HH:mm:ss'), 10)");
+				tenantConn.commit();
+
+				// run queries
+				ResultSet rs = tenantConn.createStatement()
+						.executeQuery("SELECT count(*) FROM " + viewName + " WHERE pk1 = 'testa'");
+				assertTrue(rs.next());
+				assertEquals(4, rs.getLong(1));
+				assertFalse(rs.next());
+
+				rs = tenantConn.createStatement().executeQuery("SELECT count(*) FROM " + viewName);
+				assertTrue(rs.next());
+				assertEquals(5, rs.getLong(1));
+				assertFalse(rs.next());
+
+				rs = tenantConn.createStatement()
+						.executeQuery("SELECT count(*) FROM " + viewName + " WHERE pk1 >= 'testa'");
+				assertTrue(rs.next());
+				assertEquals(5, rs.getLong(1));
+				assertFalse(rs.next());
+
+				rs = tenantConn.createStatement()
+						.executeQuery("SELECT count(*) FROM " + viewName + " WHERE pk1 <= 'testa'");
+				assertTrue(rs.next());
+				assertEquals(4, rs.getLong(1));
+				assertFalse(rs.next());
+
+				rs = tenantConn.createStatement()
+						.executeQuery("SELECT count(*) FROM " + viewName + " WHERE pk1 > 'testa'");
+				assertTrue(rs.next());
+				assertEquals(1, rs.getLong(1));
+				assertFalse(rs.next());
+
+				rs = tenantConn.createStatement()
+						.executeQuery("SELECT count(*) FROM " + viewName + " WHERE pk1 < 'testa'");
+				assertTrue(rs.next());
+				assertEquals(0, rs.getLong(1));
+				assertFalse(rs.next());
+			}
+		}
+	}
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/ec1160eb/phoenix-core/src/main/java/org/apache/phoenix/schema/ValueSchema.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/ValueSchema.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/ValueSchema.java
index b2fa2b1..716be12 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/ValueSchema.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/ValueSchema.java
@@ -217,7 +217,7 @@ public abstract class ValueSchema implements Writable {
             this.type = field.getDataType();
             this.byteSize = field.byteSize;
             this.count = count;
-            this.sortOrder = SortOrder.getDefault();
+            this.sortOrder = field.getSortOrder();
         }
         
         @Override


Mime
View raw message