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 18:13:29 UTC
phoenix git commit: PHOENIX-2310 Fix to address issue Phoenix / Pig
integration that was causing
PhoenixConfigurationUtil.getUpsertColumnMetadataList() to return an invalid
SQL statement if View DDL had recently been executed
Repository: phoenix
Updated Branches:
refs/heads/4.5-HBase-0.98 298069b2e -> 2212fc8b8
PHOENIX-2310 Fix to address issue Phoenix / Pig integration that was causing PhoenixConfigurationUtil.getUpsertColumnMetadataList() to return an 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/2212fc8b
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/2212fc8b
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/2212fc8b
Branch: refs/heads/4.5-HBase-0.98
Commit: 2212fc8b8905b4b008ea1978752b3320e57b4ae3
Parents: 298069b
Author: Jan <jf...@salesforce.com>
Authored: Thu Oct 8 09:13:01 2015 -0700
Committer: Jan <jf...@salesforce.com>
Committed: Thu Oct 8 09:13:01 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/2212fc8b/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 b4671db..fa51c74 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
@@ -75,4 +75,9 @@ public class DelegateColumn extends DelegateDatum implements PColumn {
public String getExpressionStr() {
return getDelegate().getExpressionStr();
}
+
+ @Override
+ public String toString() {
+ return getDelegate().toString();
+ }
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/2212fc8b/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 0251da1..b99a533 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
@@ -246,4 +246,9 @@ public class DelegateTable implements PTable {
public boolean rowKeyOrderOptimizable() {
return delegate.rowKeyOrderOptimizable();
}
+
+ @Override
+ public String toString() {
+ return delegate.toString();
+ }
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/2212fc8b/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));