phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From an...@apache.org
Subject phoenix git commit: PHOENIX-2169 Illegal data error on UPSERT SELECT and JOIN with salted tables(Ankit Singhal)
Date Thu, 04 Feb 2016 09:59:51 GMT
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.0 35944997a -> 0e8f4b23c


PHOENIX-2169 Illegal data error on UPSERT SELECT and JOIN with salted tables(Ankit Singhal)


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

Branch: refs/heads/4.x-HBase-1.0
Commit: 0e8f4b23cfe44488e14f77b37b9426dd5707f6c9
Parents: 3594499
Author: Ankit Singhal <ankitsinghal59@gmail.com>
Authored: Thu Feb 4 15:29:44 2016 +0530
Committer: Ankit Singhal <ankitsinghal59@gmail.com>
Committed: Thu Feb 4 15:29:44 2016 +0530

----------------------------------------------------------------------
 .../salted/SaltedTableUpsertSelectIT.java       | 57 ++++++++++++++++++++
 .../expression/ProjectedColumnExpression.java   | 11 +++-
 .../visitor/CloneExpressionVisitor.java         |  2 +-
 3 files changed, 68 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/0e8f4b23/phoenix-core/src/it/java/org/apache/phoenix/end2end/salted/SaltedTableUpsertSelectIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/salted/SaltedTableUpsertSelectIT.java
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/salted/SaltedTableUpsertSelectIT.java
index 0a11ec7..65eeb20 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/salted/SaltedTableUpsertSelectIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/salted/SaltedTableUpsertSelectIT.java
@@ -225,4 +225,61 @@ public class SaltedTableUpsertSelectIT extends BaseHBaseManagedTimeIT
{
             conn.close();
         }
     }
+
+    @Test
+    public void testUpsertSelectWithJoinOnSaltedTables() throws Exception {
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        Connection conn = DriverManager.getConnection(getUrl(), props);
+        conn.setAutoCommit(false);
+        try {
+            String ddl = "CREATE TABLE IF NOT EXISTS source1" +
+                    " (pk1 varchar NULL, pk2 varchar NULL, pk3 integer NOT NULL, col1 INTEGER"
+
+                    " CONSTRAINT pk PRIMARY KEY (pk1, pk2, pk3)) SALT_BUCKETS=4";
+            createTestTable(getUrl(), ddl);
+
+            for (int i = 0; i < 1000; i++) {
+                String upsert = "UPSERT INTO source1(pk1, pk2, pk3, col1) VALUES (?,?,?,?)";
+                PreparedStatement stmt = conn.prepareStatement(upsert);
+                stmt.setString(1, Integer.toString(i));
+                stmt.setString(2, Integer.toString(i));
+                stmt.setInt(3, i);
+                stmt.setInt(4, i);
+                stmt.execute();
+            }
+            conn.commit();
+
+            String ddl2 = "CREATE TABLE IF NOT EXISTS source2" +
+                    " (pk1 varchar NULL, pk2 varchar NULL, pk3 integer NOT NULL, col1 INTEGER"
+
+                    " CONSTRAINT pk PRIMARY KEY (pk1, pk2, pk3)) SALT_BUCKETS=4";
+            createTestTable(getUrl(), ddl2);
+
+            for (int i = 0; i < 1000; i++) {
+                String upsert = "UPSERT INTO source2(pk1, pk2, pk3, col1) VALUES (?,?,?,?)";
+                PreparedStatement stmt = conn.prepareStatement(upsert);
+                stmt.setString(1, Integer.toString(i));
+                stmt.setString(2, Integer.toString(i));
+                stmt.setInt(3, i);
+                stmt.setInt(4, i);
+                stmt.execute();
+            }
+            conn.commit();
+
+            String ddl3 = "CREATE TABLE IF NOT EXISTS dest" +
+                    " (pk1 varchar NULL, pk2 varchar NULL, pk3 integer NOT NULL, col1 INTEGER"
+
+                    " CONSTRAINT pk PRIMARY KEY (pk1, pk2, pk3)) SALT_BUCKETS=4";
+            createTestTable(getUrl(), ddl3);
+
+            String query = "UPSERT INTO dest(pk1, pk2, pk3, col1) SELECT S1.pk1, S1.pk2,
S2.pk3, S2.col1 FROM source1 AS S1 JOIN source2 AS S2 ON S1.pk1 = S2.pk1 AND S1.pk2 = S2.pk2
AND S1.pk3 = S2.pk3";
+            conn.createStatement().execute(query);
+            conn.commit();
+
+            query = "SELECT COUNT(*) FROM dest";
+            PreparedStatement stmt = conn.prepareStatement(query);
+            ResultSet rs = stmt.executeQuery();
+            assertTrue(rs.next());
+            assertEquals(1000, rs.getInt(1));
+        } finally {
+            conn.close();
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/0e8f4b23/phoenix-core/src/main/java/org/apache/phoenix/expression/ProjectedColumnExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/ProjectedColumnExpression.java
b/phoenix-core/src/main/java/org/apache/phoenix/expression/ProjectedColumnExpression.java
index 89619bf..3a38dee 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/ProjectedColumnExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/ProjectedColumnExpression.java
@@ -36,7 +36,7 @@ import org.apache.phoenix.util.SchemaUtil;
 
 public class ProjectedColumnExpression extends ColumnExpression {
 	private KeyValueSchema schema;
-	ValueBitSet bitSet;
+	private ValueBitSet bitSet;
 	private int position;
 	private String displayName;
 	private final Collection<PColumn> columns;
@@ -148,4 +148,13 @@ public class ProjectedColumnExpression extends ColumnExpression {
     public PColumn getColumn() {
         return column;
     }
+
+    @Override
+    public Determinism getDeterminism() {
+        return Determinism.PER_INVOCATION;
+    }
+
+    public ProjectedColumnExpression clone() {
+        return new ProjectedColumnExpression(this.column, this.columns, this.position, this.displayName);
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/0e8f4b23/phoenix-core/src/main/java/org/apache/phoenix/expression/visitor/CloneExpressionVisitor.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/visitor/CloneExpressionVisitor.java
b/phoenix-core/src/main/java/org/apache/phoenix/expression/visitor/CloneExpressionVisitor.java
index 8d14545..00ece40 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/visitor/CloneExpressionVisitor.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/visitor/CloneExpressionVisitor.java
@@ -83,7 +83,7 @@ public abstract class CloneExpressionVisitor extends TraverseAllExpressionVisito
 
     @Override
     public Expression visit(ProjectedColumnExpression node) {
-        return node;
+        return node.clone();
     }
 
     @Override


Mime
View raw message