Github user jihoonson commented on a diff in the pull request:
https://github.com/apache/tajo/pull/653#discussion_r37736825
--- Diff:
tajo-core-tests/src/test/java/org/apache/tajo/master/TestNonForwardQueryResultSystemScanner.java
---
@@ -38,4 +51,89 @@ public void testGetNextRowsForTable() throws Exception {
public void testGetClusterDetails() throws Exception {
assertQueryStr("SELECT TYPE FROM INFORMATION_SCHEMA.CLUSTER");
}
+
+ @Test
+ public final void testGetInformationSchema() throws Exception {
+ executeDDL("create_partitioned_table.sql", null);
+
+ String simpleTableName = "information_schema_test_table";
+ String tableName = CatalogUtil.buildFQName(getCurrentDatabase(),
simpleTableName);
+ assertTrue(catalog.existsTable(tableName));
+
+ TableDesc retrieved = catalog.getTableDesc(tableName);
+
+ executeDDL("alter_table_add_partition1.sql", null);
+ executeDDL("alter_table_add_partition2.sql", null);
+
+ List<CatalogProtos.DatabaseProto> allDatabases =
catalog.getAllDatabases();
+ int dbId = -1;
+ for (CatalogProtos.DatabaseProto database : allDatabases) {
+ if (database.getName().equals(getCurrentDatabase())) {
+ dbId = database.getId();
+ }
+ }
+ assertNotEquals(dbId, -1);
+
+ int tableId = -1;
+ List<CatalogProtos.TableDescriptorProto> allTables =
catalog.getAllTables();
+ for(CatalogProtos.TableDescriptorProto table : allTables) {
+ if (table.getDbId() == dbId &&
table.getName().equals(simpleTableName)) {
+ tableId = table.getTid();
+ }
+ }
+ assertNotEquals(tableId, -1);
+
+ List<CatalogProtos.PartitionDescProto> allPartitions =
catalog.getAllPartitions();
+ List<CatalogProtos.PartitionDescProto> resultPartitions =
TUtil.newList();
+
+ int partitionId = 0;
+ for (CatalogProtos.PartitionDescProto partition : allPartitions) {
+ if (partition.getTid() == tableId
+ && partition.getPartitionName().equals("col3=1/col4=2")
+ && partition.getPath().equals(retrieved.getUri().toString() +
"/col3=1/col4=2")
+ ){
+ resultPartitions.add(partition);
+ partitionId = partition.getPartitionId();
+ }
+ }
+ assertEquals(resultPartitions.size(), 1);
+ assertEquals(resultPartitions.get(0).getPartitionName(),
"col3=1/col4=2");
+
+ List<CatalogProtos.PartitionKeyProto> tablePartitionKeys =
catalog.getAllPartitionKeys();
+ List<CatalogProtos.PartitionKeyProto> resultPartitionKeys =
TUtil.newList();
+
+ for (CatalogProtos.PartitionKeyProto partitionKey: tablePartitionKeys)
{
+ if (partitionKey.getPartitionId() == partitionId
+ && (partitionKey.getColumnName().equals("col3") &&
partitionKey.getPartitionValue().equals("1")
+ || partitionKey.getColumnName().equals("col4") &&
partitionKey.getPartitionValue().equals("2"))) {
+ resultPartitionKeys.add(partitionKey);
+ }
+ }
+ assertEquals(resultPartitionKeys.size(), 2);
+ assertEquals(resultPartitionKeys.get(0).getColumnName(), "col3");
+ assertEquals(resultPartitionKeys.get(0).getPartitionValue(), "1");
+ assertEquals(resultPartitionKeys.get(1).getColumnName(), "col4");
+ assertEquals(resultPartitionKeys.get(1).getPartitionValue(), "2");
--- End diff --
Above tests looks duplicate with below tests. Only difference is that above
tests use catalog client APIs while below tests use tajo client APIs. For
consistency, I prefer to use tajo client APIs in this test class.
In addition, I think that we need to test the case when information of a
lot of partitions and partition keys is stored in catalog. So, it would be
great if more partitions are added when initializing.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---