This is an automated email from the ASF dual-hosted git repository.

yanxinyi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/master by this push:
     new d8a0a8a  PHOENIX-5210 NullPointerException when alter options of a 
table that is appendOnlySchema
d8a0a8a is described below

commit d8a0a8a540d71889d487e9ba31a8c2115d8a6aba
Author: Toshihiro Suzuki <[email protected]>
AuthorDate: Thu Aug 15 13:50:32 2019 +0900

    PHOENIX-5210 NullPointerException when alter options of a table that is 
appendOnlySchema
    
    Signed-off-by: Xinyi Yan <[email protected]>
---
 .../apache/phoenix/end2end/AppendOnlySchemaIT.java | 24 ++++++++++++++++++++++
 .../org/apache/phoenix/schema/MetaDataClient.java  |  2 +-
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AppendOnlySchemaIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AppendOnlySchemaIT.java
index dc06f62..2cf32c8 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AppendOnlySchemaIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AppendOnlySchemaIT.java
@@ -39,6 +39,7 @@ import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.sql.Statement;
 import java.util.Collections;
 import java.util.List;
 import java.util.Properties;
@@ -354,4 +355,27 @@ public class AppendOnlySchemaIT extends 
ParallelStatsDisabledIT {
         }
     }
 
+    @Test
+    public void testAlterTableOptions() throws Exception {
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        try (Connection conn = DriverManager.getConnection(getUrl(), props);
+             Statement stmt = conn.createStatement()) {
+            String tableName = generateUniqueName();
+            // create a table
+            stmt.execute("CREATE TABLE " + tableName +
+              " (ID INTEGER PRIMARY KEY, COL INTEGER) APPEND_ONLY_SCHEMA = 
true,"
+              + " UPDATE_CACHE_FREQUENCY = 1");
+
+            // alter the table to set table options
+            stmt.execute("ALTER TABLE " + tableName + " SET STORE_NULLS = 
true");
+
+            try (ResultSet rs = stmt.executeQuery("SELECT STORE_NULLS FROM 
\"SYSTEM\".\"CATALOG\""
+              + " WHERE TABLE_NAME = '" + tableName + "' AND STORE_NULLS IS 
NOT NULL"
+              + " AND TENANT_ID IS NULL AND TABLE_SCHEM IS NULL")) {
+                assertTrue(rs.next());
+                assertTrue(rs.getBoolean(1));
+                assertFalse(rs.next());
+            }
+        }
+    }
 }
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java 
b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
index 56104f9..cbc600c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
@@ -3683,7 +3683,7 @@ public class MetaDataClient {
             connection.setAutoCommit(false);
 
             List<ColumnDef> columnDefs;
-            if (table.isAppendOnlySchema() || ifNotExists) {
+            if ((table.isAppendOnlySchema() || ifNotExists) && origColumnDefs 
!= null) {
                 // only make the rpc if we are adding new columns
                 columnDefs = Lists.newArrayList();
                 for (ColumnDef columnDef : origColumnDefs) {

Reply via email to