phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maryann...@apache.org
Subject phoenix git commit: PHOENIX-3498 Query with index failed when query back to data table with desc PK column
Date Fri, 18 Nov 2016 18:59:57 GMT
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.1 fe78460cd -> 79c139eef


PHOENIX-3498 Query with index failed when query back to data table with desc PK column


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

Branch: refs/heads/4.x-HBase-1.1
Commit: 79c139eef595244b0f6c08a2c05295469144d110
Parents: fe78460
Author: William Yang <yhxx511@163.com>
Authored: Fri Nov 18 10:59:43 2016 -0800
Committer: maryannxue <maryann.xue@gmail.com>
Committed: Fri Nov 18 10:59:43 2016 -0800

----------------------------------------------------------------------
 .../apache/phoenix/end2end/index/IndexIT.java   | 45 ++++++++++++++++++++
 .../apache/phoenix/join/HashCacheClient.java    |  4 +-
 2 files changed, 47 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/79c139ee/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java
index 8ab563c..48fe3e6 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java
@@ -1093,4 +1093,49 @@ public class IndexIT extends ParallelStatsDisabledIT {
         }
     }
 
+    @Test
+    public void testQueryBackToDataTableWithDescPKColumn() throws SQLException {
+        doTestQueryBackToDataTableWithDescPKColumn(true);
+        doTestQueryBackToDataTableWithDescPKColumn(false);
+    }
+
+    private void doTestQueryBackToDataTableWithDescPKColumn(boolean isSecondPKDesc) throws
SQLException {
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        String tableName = "TBL_" + generateUniqueName();
+        String indexName = "IND_" + generateUniqueName();
+        String fullTableName = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, tableName);
+        String fullIndexName = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, indexName);
+
+        try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+            // create data table and index table
+            conn.setAutoCommit(true);
+            Statement stmt = conn.createStatement();
+            String ddl = "CREATE TABLE " + fullTableName + "(p1 integer not null, p2 integer
not null, " +
+                    " a integer, b integer CONSTRAINT PK PRIMARY KEY ";
+            if (isSecondPKDesc) {
+                ddl += "(p1, p2 desc))";
+            } else {
+                ddl += "(p1 desc, p2))";
+            }
+            stmt.executeUpdate(ddl);
+            ddl = "CREATE "+ (localIndex ? "LOCAL " : "") + " INDEX " + fullIndexName + "
on " + fullTableName + "(a)";
+            stmt.executeUpdate(ddl);
+
+            // upsert a single row
+            String upsert = "UPSERT INTO " + fullTableName + " VALUES(1,2,3,4)";
+            stmt.executeUpdate(upsert);
+
+            // try select with index
+            // a = 3, should hit index table, but we select column B, so it will query back
to data table
+            String query = "SELECT /*+index(" + fullTableName + " " + fullIndexName + "*/
b from " + fullTableName +
+                    " WHERE a = 3";
+            ResultSet rs = stmt.executeQuery(query);
+            assertTrue(rs.next());
+            assertEquals(4, rs.getInt(1));
+            assertFalse(rs.next());
+            rs.close();
+            stmt.close();
+        }
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/79c139ee/phoenix-core/src/main/java/org/apache/phoenix/join/HashCacheClient.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/join/HashCacheClient.java b/phoenix-core/src/main/java/org/apache/phoenix/join/HashCacheClient.java
index e8b3389..32d0469 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/join/HashCacheClient.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/join/HashCacheClient.java
@@ -158,7 +158,7 @@ public class HashCacheClient  {
             PDataType type = keyExpression.getDataType();
             keyExpression.reset();
             if (keyExpression.evaluate(tuple, ptr)) {
-                return LiteralExpression.newConstant(type.toObject(ptr), type);
+                return LiteralExpression.newConstant(type.toObject(ptr, keyExpression.getSortOrder()),
type);
             }
             
             return LiteralExpression.newConstant(null, type);
@@ -170,7 +170,7 @@ public class HashCacheClient  {
             PDataType type = child.getDataType();
             child.reset();
             if (child.evaluate(tuple, ptr)) {
-                values.add(LiteralExpression.newConstant(type.toObject(ptr), type));
+                values.add(LiteralExpression.newConstant(type.toObject(ptr, child.getSortOrder()),
type));
             } else {
                 values.add(LiteralExpression.newConstant(null, type));
             }


Mime
View raw message