You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by jf...@apache.org on 2015/10/08 19:09:32 UTC

phoenix git commit: PHOENIX-2310 Fix to address issue in Phoenix / Pig integration that was causing PhoenixConfigurationUtil.getUpsertColumnMetadataList() to return aan invalid SQL statement if View DDL had recently been executed

Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.0 340911841 -> 3b6a11b78


PHOENIX-2310 Fix to address issue in Phoenix / Pig integration that was causing PhoenixConfigurationUtil.getUpsertColumnMetadataList() to return aan invalid SQL statement if View DDL had recently been executed


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

Branch: refs/heads/4.x-HBase-1.0
Commit: 3b6a11b78b0c8db4125280f4d6b15a95ca500bf8
Parents: 3409118
Author: Jan <jf...@salesforce.com>
Authored: Thu Oct 8 10:09:16 2015 -0700
Committer: Jan <jf...@salesforce.com>
Committed: Thu Oct 8 10:09:16 2015 -0700

----------------------------------------------------------------------
 .../apache/phoenix/schema/DelegateColumn.java   |  5 ++
 .../apache/phoenix/schema/DelegateTable.java    |  5 ++
 .../util/PhoenixConfigurationUtilTest.java      | 73 ++++++++++++++++++++
 3 files changed, 83 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/3b6a11b7/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateColumn.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateColumn.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateColumn.java
index 7ff8eb8..20f3070 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateColumn.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateColumn.java
@@ -83,5 +83,10 @@ public class DelegateColumn extends DelegateDatum implements PColumn {
     @Override
     public boolean isRowTimestamp() {
         return getDelegate().isRowTimestamp();
+    }    
+    
+    @Override
+    public String toString() {
+        return getDelegate().toString();
     }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/3b6a11b7/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateTable.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateTable.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateTable.java
index 203c5e6..5a0d63b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateTable.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/DelegateTable.java
@@ -251,4 +251,9 @@ public class DelegateTable implements PTable {
     public int getRowTimestampColPos() {
         return delegate.getRowTimestampColPos();
     }
+    
+    @Override
+    public String toString() {
+        return delegate.toString();
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/3b6a11b7/phoenix-core/src/test/java/org/apache/phoenix/mapreduce/util/PhoenixConfigurationUtilTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/mapreduce/util/PhoenixConfigurationUtilTest.java b/phoenix-core/src/test/java/org/apache/phoenix/mapreduce/util/PhoenixConfigurationUtilTest.java
index 0ba849f..4d325c2 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/mapreduce/util/PhoenixConfigurationUtilTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/mapreduce/util/PhoenixConfigurationUtilTest.java
@@ -40,6 +40,79 @@ import org.junit.Test;
 public class PhoenixConfigurationUtilTest extends BaseConnectionlessQueryTest {
     private static final String ORIGINAL_CLUSTER_QUORUM = "myzookeeperhost";
     private static final String OVERRIDE_CLUSTER_QUORUM = "myoverridezookeeperhost";
+    
+    @Test
+    /**
+     * This test reproduces the bug filed in PHOENIX-2310. 
+     * 
+     * When invoking PhoenixConfigurationUtil.getUpsertStatement(),
+     * if upserting into a Phoenix View and the View DDL had recently been issued such that MetdataClient cache had
+     * been updated as a result of the create table versus from data in SYSTEM.CATALOG, the Upsert statement
+     * would contain the Object.toString() classname + hashcode instead of the correct cf.column_name representation
+     * which would cause the calling Pig script to fail.
+     */
+    public void testUpsertStatementOnNewViewWithReferencedCols() throws Exception {
+        
+        // Arrange
+        Connection conn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES));
+
+        try {
+            final String tableName = "TEST_TABLE_WITH_VIEW";
+            final String viewName = "TEST_VIEW";
+            String ddl = "CREATE TABLE "+ tableName + 
+                    "  (a_string varchar not null, a_binary varbinary not null, col1 integer" +
+                    "  CONSTRAINT pk PRIMARY KEY (a_string, a_binary))\n";
+            conn.createStatement().execute(ddl);
+            String viewDdl = "CREATE VIEW "+ viewName + 
+                    "  AS SELECT * FROM " + tableName + "\n";
+            conn.createStatement().execute(viewDdl);
+            final Configuration configuration = new Configuration ();
+            configuration.set(HConstants.ZOOKEEPER_QUORUM, getUrl());
+            PhoenixConfigurationUtil.setOutputTableName(configuration, viewName);
+            PhoenixConfigurationUtil.setPhysicalTableName(configuration, viewName);
+            PhoenixConfigurationUtil.setUpsertColumnNames(configuration, new String[] {"A_STRING", "A_BINARY", "COL1"});
+            
+            // Act
+            final String upserStatement = PhoenixConfigurationUtil.getUpsertStatement(configuration);
+            
+            // Assert
+            final String expectedUpsertStatement = "UPSERT  INTO " + viewName + " (\"A_STRING\", \"A_BINARY\", \"0\".\"COL1\") VALUES (?, ?, ?)"; 
+            assertEquals(expectedUpsertStatement, upserStatement);
+        } finally {
+            conn.close();
+        }
+     }
+    
+    @Test
+    public void testUpsertStatementOnNewTableWithReferencedCols() throws Exception {
+        
+        // Arrange
+        Connection conn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES));
+
+        try {
+            final String tableName = "TEST_TABLE_WITH_REF_COLS";
+            String ddl = "CREATE TABLE "+ tableName + 
+                    "  (a_string varchar not null, a_binary varbinary not null, col1 integer" +
+                    "  CONSTRAINT pk PRIMARY KEY (a_string, a_binary))\n";
+            conn.createStatement().execute(ddl);
+            final Configuration configuration = new Configuration ();
+            configuration.set(HConstants.ZOOKEEPER_QUORUM, getUrl());
+            PhoenixConfigurationUtil.setOutputTableName(configuration, tableName);
+            PhoenixConfigurationUtil.setPhysicalTableName(configuration, tableName);
+            PhoenixConfigurationUtil.setUpsertColumnNames(configuration, new String[] {"A_STRING", "A_BINARY", "COL1"});
+            
+            // Act
+            final String upserStatement = PhoenixConfigurationUtil.getUpsertStatement(configuration);
+            
+            // Assert
+            final String expectedUpsertStatement = "UPSERT  INTO " + tableName + " (\"A_STRING\", \"A_BINARY\", \"0\".\"COL1\") VALUES (?, ?, ?)"; 
+            assertEquals(expectedUpsertStatement, upserStatement);
+        } finally {
+            conn.close();
+        }
+     }
+
+    
     @Test
     public void testUpsertStatement() throws Exception {
         Connection conn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES));