Skip to content

Commit

Permalink
PHOENIX-5210 NullPointerException when alter options of a table that …
Browse files Browse the repository at this point in the history
…is appendOnlySchema

Signed-off-by: Xinyi Yan <yanxinyi@apache.org>
  • Loading branch information
brfrn169 authored and yanxinyi committed Nov 2, 2020
1 parent a8a9699 commit 8aa243d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
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;
Expand Down Expand Up @@ -354,4 +355,27 @@ public void testUpsertRowToDeletedTable() throws Exception {
}
}

@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());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3680,7 +3680,7 @@ public MutationState addColumn(PTable table, List<ColumnDef> origColumnDefs,
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) {
Expand Down

0 comments on commit 8aa243d

Please sign in to comment.