Skip to content

Commit

Permalink
Add a test for adding a new column
Browse files Browse the repository at this point in the history
  • Loading branch information
mayankgarg1990 authored and rschlussel committed Oct 15, 2020
1 parent 84ade36 commit 029ae8d
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3665,6 +3665,45 @@ protected String partitionTargetPath(SchemaTableName schemaTableName, String par
}
}

@Test
public void testAddColumn()
throws Exception
{
SchemaTableName tableName = temporaryTable("test_add_column");
try {
doCreateEmptyTable(tableName, ORC, CREATE_TABLE_COLUMNS);
ExtendedHiveMetastore metastoreClient = getMetastoreClient();
metastoreClient.addColumn(tableName.getSchemaName(), tableName.getTableName(), "new_col", HIVE_LONG, null);
Optional<Table> table = metastoreClient.getTable(tableName.getSchemaName(), tableName.getTableName());
assertTrue(table.isPresent());
List<Column> columns = table.get().getDataColumns();
assertEquals(columns.get(columns.size() - 1).getName(), "new_col");
}
finally {
dropTable(tableName);
}
}

@Test
public void testDropColumn()
throws Exception
{
SchemaTableName tableName = temporaryTable("test_drop_column");
try {
doCreateEmptyTable(tableName, ORC, CREATE_TABLE_COLUMNS);
ExtendedHiveMetastore metastoreClient = getMetastoreClient();
metastoreClient.dropColumn(tableName.getSchemaName(), tableName.getTableName(), CREATE_TABLE_COLUMNS.get(0).getName());
Optional<Table> table = metastoreClient.getTable(tableName.getSchemaName(), tableName.getTableName());
assertTrue(table.isPresent());
List<Column> columns = table.get().getDataColumns();
assertEquals(columns.get(0).getName(), CREATE_TABLE_COLUMNS.get(1).getName());
assertFalse(columns.stream().map(Column::getName).anyMatch(colName -> colName.equals(CREATE_TABLE_COLUMNS.get(0).getName())));
}
finally {
dropTable(tableName);
}
}

/**
* This test creates 2 identical partitions and verifies that the statistics projected based on
* a single partition sample are equal to the statistics computed in a fair way
Expand Down

0 comments on commit 029ae8d

Please sign in to comment.