You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by bl...@apache.org on 2019/05/02 05:35:19 UTC
[flink] branch master updated: [hotfix] [table] Refactor
GenericInMemoryCatalogTest to prepare for moving common tests to
CatalogTestBase (#8325)
This is an automated email from the ASF dual-hosted git repository.
bli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
The following commit(s) were added to refs/heads/master by this push:
new 02bd5e1 [hotfix] [table] Refactor GenericInMemoryCatalogTest to prepare for moving common tests to CatalogTestBase (#8325)
02bd5e1 is described below
commit 02bd5e1a9658f03d852ff158306b301bdd6d8868
Author: Bowen L <bo...@gmail.com>
AuthorDate: Wed May 1 22:35:01 2019 -0700
[hotfix] [table] Refactor GenericInMemoryCatalogTest to prepare for moving common tests to CatalogTestBase (#8325)
* [hotfix] [table] Refactor GenericInMemoryCatalogTest to prepare for moving common tests to CatalogTestBase
---
.../hive/GenericHiveMetastoreCatalogTest.java | 6 ++
.../table/catalog/GenericInMemoryCatalogTest.java | 98 ++++++++++++----------
.../flink/table/catalog/CatalogTestBase.java | 7 ++
.../flink/table/catalog/CatalogTestUtil.java | 44 +---------
4 files changed, 68 insertions(+), 87 deletions(-)
diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/catalog/hive/GenericHiveMetastoreCatalogTest.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/catalog/hive/GenericHiveMetastoreCatalogTest.java
index 642c1c2..315d657 100644
--- a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/catalog/hive/GenericHiveMetastoreCatalogTest.java
+++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/catalog/hive/GenericHiveMetastoreCatalogTest.java
@@ -80,4 +80,10 @@ public class GenericHiveMetastoreCatalogTest extends CatalogTestBase {
// TODO: implement this once GenericHiveMetastoreCatalog support table operations
return null;
}
+
+ @Override
+ public CatalogTable createAnotherTable() {
+ // TODO: implement this once GenericHiveMetastoreCatalog support table operations
+ return null;
+ }
}
diff --git a/flink-table/flink-table-api-java/src/test/java/org/apache/flink/table/catalog/GenericInMemoryCatalogTest.java b/flink-table/flink-table-api-java/src/test/java/org/apache/flink/table/catalog/GenericInMemoryCatalogTest.java
index 50d203a..8bb7c66 100644
--- a/flink-table/flink-table-api-java/src/test/java/org/apache/flink/table/catalog/GenericInMemoryCatalogTest.java
+++ b/flink-table/flink-table-api-java/src/test/java/org/apache/flink/table/catalog/GenericInMemoryCatalogTest.java
@@ -31,6 +31,7 @@ import org.apache.flink.table.catalog.exceptions.TableAlreadyExistException;
import org.apache.flink.table.catalog.exceptions.TableNotExistException;
import org.apache.flink.table.catalog.exceptions.TableNotPartitionedException;
import org.apache.flink.table.functions.ScalarFunction;
+import org.apache.flink.table.plan.stats.TableStats;
import org.junit.After;
import org.junit.BeforeClass;
@@ -80,25 +81,23 @@ public class GenericInMemoryCatalogTest extends CatalogTestBase {
@Test
public void testCreateTable_Streaming() throws Exception {
catalog.createDatabase(db1, createDb(), false);
- GenericCatalogTable table = createStreamingTable();
+ CatalogTable table = createStreamingTable();
catalog.createTable(path1, table, false);
- CatalogTestUtil.checkEquals(table, (GenericCatalogTable) catalog.getTable(path1));
+ CatalogTestUtil.checkEquals(table, (CatalogTable) catalog.getTable(path1));
}
@Test
public void testCreateTable_Batch() throws Exception {
catalog.createDatabase(db1, createDb(), false);
- CatalogDatabase database = catalog.getDatabase(db1);
- assertTrue(TEST_COMMENT.equals(database.getDescription().get()));
// Non-partitioned table
- GenericCatalogTable table = createTable();
+ CatalogTable table = createTable();
catalog.createTable(path1, table, false);
CatalogBaseTable tableCreated = catalog.getTable(path1);
- CatalogTestUtil.checkEquals(table, (GenericCatalogTable) tableCreated);
+ CatalogTestUtil.checkEquals(table, (CatalogTable) tableCreated);
assertEquals(TABLE_COMMENT, tableCreated.getDescription().get());
List<String> tables = catalog.listTables(db1);
@@ -112,7 +111,7 @@ public class GenericInMemoryCatalogTest extends CatalogTestBase {
table = createPartitionedTable();
catalog.createTable(path1, table, false);
- CatalogTestUtil.checkEquals(table, (GenericCatalogTable) catalog.getTable(path1));
+ CatalogTestUtil.checkEquals(table, (CatalogTable) catalog.getTable(path1));
tables = catalog.listTables(db1);
@@ -132,7 +131,7 @@ public class GenericInMemoryCatalogTest extends CatalogTestBase {
@Test
public void testCreateTable_TableAlreadyExistException() throws Exception {
catalog.createDatabase(db1, createDb(), false);
- catalog.createTable(path1, CatalogTestUtil.createTable(TABLE_COMMENT), false);
+ catalog.createTable(path1, createTable(), false);
exception.expect(TableAlreadyExistException.class);
exception.expectMessage("Table (or view) db1.t1 already exists in Catalog");
@@ -143,14 +142,14 @@ public class GenericInMemoryCatalogTest extends CatalogTestBase {
public void testCreateTable_TableAlreadyExist_ignored() throws Exception {
catalog.createDatabase(db1, createDb(), false);
- GenericCatalogTable table = CatalogTestUtil.createTable(TABLE_COMMENT);
+ CatalogTable table = createTable();
catalog.createTable(path1, table, false);
- CatalogTestUtil.checkEquals(table, (GenericCatalogTable) catalog.getTable(path1));
+ CatalogTestUtil.checkEquals(table, (CatalogTable) catalog.getTable(path1));
catalog.createTable(path1, createAnotherTable(), true);
- CatalogTestUtil.checkEquals(table, (GenericCatalogTable) catalog.getTable(path1));
+ CatalogTestUtil.checkEquals(table, (CatalogTable) catalog.getTable(path1));
}
@Test
@@ -170,10 +169,8 @@ public class GenericInMemoryCatalogTest extends CatalogTestBase {
}
@Test
- public void testDropTable() throws Exception {
+ public void testDropTable_nonPartitionedTable() throws Exception {
catalog.createDatabase(db1, createDb(), false);
-
- // Non-partitioned table
catalog.createTable(path1, createTable(), false);
assertTrue(catalog.tableExists(path1));
@@ -181,8 +178,11 @@ public class GenericInMemoryCatalogTest extends CatalogTestBase {
catalog.dropTable(path1, false);
assertFalse(catalog.tableExists(path1));
+ }
- // Partitioned table
+ @Test
+ public void testDropTable_partitionedTable() throws Exception {
+ catalog.createDatabase(db1, createDb(), false);
catalog.createTable(path1, createPartitionedTable(), false);
CatalogPartition catalogPartition = createPartition();
CatalogPartitionSpec catalogPartitionSpec = createPartitionSpec();
@@ -231,16 +231,16 @@ public class GenericInMemoryCatalogTest extends CatalogTestBase {
catalog.createDatabase(db1, createDb(), false);
// Non-partitioned table
- GenericCatalogTable table = CatalogTestUtil.createTable(TABLE_COMMENT);
+ CatalogTable table = createTable();
catalog.createTable(path1, table, false);
- CatalogTestUtil.checkEquals(table, (GenericCatalogTable) catalog.getTable(path1));
+ CatalogTestUtil.checkEquals(table, (CatalogTable) catalog.getTable(path1));
- GenericCatalogTable newTable = createAnotherTable();
+ CatalogTable newTable = createAnotherTable();
catalog.alterTable(path1, newTable, false);
assertNotEquals(table, catalog.getTable(path1));
- CatalogTestUtil.checkEquals(newTable, (GenericCatalogTable) catalog.getTable(path1));
+ CatalogTestUtil.checkEquals(newTable, (CatalogTable) catalog.getTable(path1));
catalog.dropTable(path1, false);
@@ -248,12 +248,12 @@ public class GenericInMemoryCatalogTest extends CatalogTestBase {
table = createPartitionedTable();
catalog.createTable(path1, table, false);
- CatalogTestUtil.checkEquals(table, (GenericCatalogTable) catalog.getTable(path1));
+ CatalogTestUtil.checkEquals(table, (CatalogTable) catalog.getTable(path1));
newTable = createAnotherPartitionedTable();
catalog.alterTable(path1, newTable, false);
- CatalogTestUtil.checkEquals(newTable, (GenericCatalogTable) catalog.getTable(path1));
+ CatalogTestUtil.checkEquals(newTable, (CatalogTable) catalog.getTable(path1));
}
@Test
@@ -272,35 +272,34 @@ public class GenericInMemoryCatalogTest extends CatalogTestBase {
}
@Test
- public void testRenameTable() throws Exception {
+ public void testRenameTable_nonPartitionedTable() throws Exception {
catalog.createDatabase(db1, createDb(), false);
-
- // Non-partitioned table
- GenericCatalogTable table = createTable();
+ CatalogTable table = createTable();
catalog.createTable(path1, table, false);
- CatalogTestUtil.checkEquals(table, (GenericCatalogTable) catalog.getTable(path1));
+ CatalogTestUtil.checkEquals(table, (CatalogTable) catalog.getTable(path1));
catalog.renameTable(path1, t2, false);
- CatalogTestUtil.checkEquals(table, (GenericCatalogTable) catalog.getTable(path3));
+ CatalogTestUtil.checkEquals(table, (CatalogTable) catalog.getTable(path3));
assertFalse(catalog.tableExists(path1));
+ }
- catalog.dropTable(path3, false);
-
- // Partitioned table
- table = createPartitionedTable();
+ @Test
+ public void testRenameTable_partitionedTable() throws Exception {
+ catalog.createDatabase(db1, createDb(), false);
+ CatalogTable table = createPartitionedTable();
catalog.createTable(path1, table, false);
CatalogPartition catalogPartition = createPartition();
CatalogPartitionSpec catalogPartitionSpec = createPartitionSpec();
catalog.createPartition(path1, catalogPartitionSpec, catalogPartition, false);
- CatalogTestUtil.checkEquals(table, (GenericCatalogTable) catalog.getTable(path1));
+ CatalogTestUtil.checkEquals(table, (CatalogTable) catalog.getTable(path1));
assertTrue(catalog.partitionExists(path1, catalogPartitionSpec));
catalog.renameTable(path1, t2, false);
- CatalogTestUtil.checkEquals(table, (GenericCatalogTable) catalog.getTable(path3));
+ CatalogTestUtil.checkEquals(table, (CatalogTable) catalog.getTable(path3));
assertTrue(catalog.partitionExists(path3, catalogPartitionSpec));
assertFalse(catalog.tableExists(path1));
assertFalse(catalog.partitionExists(path1, catalogPartitionSpec));
@@ -962,35 +961,44 @@ public class GenericInMemoryCatalogTest extends CatalogTestBase {
}
private GenericCatalogTable createStreamingTable() {
- return CatalogTestUtil.createTable(
+ return new GenericCatalogTable(
createTableSchema(),
- getStreamingTableProperties(), TABLE_COMMENT);
+ new TableStats(0),
+ getStreamingTableProperties(),
+ TABLE_COMMENT);
}
@Override
- public GenericCatalogTable createTable() {
- return CatalogTestUtil.createTable(
+ public CatalogTable createTable() {
+ return new GenericCatalogTable(
createTableSchema(),
- getBatchTableProperties(), TABLE_COMMENT);
+ new TableStats(0),
+ getBatchTableProperties(),
+ TABLE_COMMENT);
}
- private GenericCatalogTable createAnotherTable() {
- return CatalogTestUtil.createTable(
+ @Override
+ public CatalogTable createAnotherTable() {
+ return new GenericCatalogTable(
createAnotherTableSchema(),
- getBatchTableProperties(), TABLE_COMMENT);
+ new TableStats(0),
+ getBatchTableProperties(),
+ TABLE_COMMENT);
}
- protected GenericCatalogTable createPartitionedTable() {
- return CatalogTestUtil.createPartitionedTable(
+ protected CatalogTable createPartitionedTable() {
+ return new GenericCatalogTable(
createTableSchema(),
+ new TableStats(0),
createPartitionKeys(),
getBatchTableProperties(),
TABLE_COMMENT);
}
- protected GenericCatalogTable createAnotherPartitionedTable() {
- return CatalogTestUtil.createPartitionedTable(
+ protected CatalogTable createAnotherPartitionedTable() {
+ return new GenericCatalogTable(
createAnotherTableSchema(),
+ new TableStats(0),
createPartitionKeys(),
getBatchTableProperties(),
TABLE_COMMENT);
diff --git a/flink-table/flink-table-common/src/test/java/org/apache/flink/table/catalog/CatalogTestBase.java b/flink-table/flink-table-common/src/test/java/org/apache/flink/table/catalog/CatalogTestBase.java
index 83a8f2b..5457d34 100644
--- a/flink-table/flink-table-common/src/test/java/org/apache/flink/table/catalog/CatalogTestBase.java
+++ b/flink-table/flink-table-common/src/test/java/org/apache/flink/table/catalog/CatalogTestBase.java
@@ -238,4 +238,11 @@ public abstract class CatalogTestBase {
* @return a CatalogTable instance
*/
public abstract CatalogTable createTable();
+
+ /**
+ * Create another CatalogTable instance by specific catalog implementation.
+ *
+ * @return another CatalogTable instance
+ */
+ public abstract CatalogTable createAnotherTable();
}
diff --git a/flink-table/flink-table-api-java/src/test/java/org/apache/flink/table/catalog/CatalogTestUtil.java b/flink-table/flink-table-common/src/test/java/org/apache/flink/table/catalog/CatalogTestUtil.java
similarity index 58%
rename from flink-table/flink-table-api-java/src/test/java/org/apache/flink/table/catalog/CatalogTestUtil.java
rename to flink-table/flink-table-common/src/test/java/org/apache/flink/table/catalog/CatalogTestUtil.java
index 33d1ea1..0700736 100644
--- a/flink-table/flink-table-api-java/src/test/java/org/apache/flink/table/catalog/CatalogTestUtil.java
+++ b/flink-table/flink-table-common/src/test/java/org/apache/flink/table/catalog/CatalogTestUtil.java
@@ -18,16 +18,8 @@
package org.apache.flink.table.catalog;
-import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
-import org.apache.flink.api.common.typeinfo.TypeInformation;
-import org.apache.flink.api.java.typeutils.RowTypeInfo;
-import org.apache.flink.table.api.TableSchema;
import org.apache.flink.table.plan.stats.TableStats;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
import static org.junit.Assert.assertEquals;
/**
@@ -35,42 +27,10 @@ import static org.junit.Assert.assertEquals;
*/
public class CatalogTestUtil {
- public static GenericCatalogTable createTable(String comment) {
- TableSchema tableSchema = TableSchema.fromTypeInfo(getRowTypeInfo());
- return new GenericCatalogTable(tableSchema, createTableStats(), new HashMap<>(), comment);
- }
-
- public static RowTypeInfo getRowTypeInfo() {
- return new RowTypeInfo(
- new TypeInformation[] {BasicTypeInfo.INT_TYPE_INFO, BasicTypeInfo.INT_TYPE_INFO},
- new String[] {"a", "b"});
- }
-
- public static TableStats createTableStats() {
- return new TableStats(2);
- }
-
- public static GenericCatalogTable createTable(
- TableSchema schema,
- Map<String, String> tableProperties,
- String comment) {
-
- return new GenericCatalogTable(schema, new TableStats(0), tableProperties, comment);
- }
-
- public static GenericCatalogTable createPartitionedTable(
- TableSchema schema,
- List<String> partitionKeys,
- Map<String, String> tableProperties,
- String comment) {
-
- return new GenericCatalogTable(schema, new TableStats(0), partitionKeys, tableProperties, comment);
- }
-
- public static void checkEquals(GenericCatalogTable t1, GenericCatalogTable t2) {
+ public static void checkEquals(CatalogTable t1, CatalogTable t2) {
assertEquals(t1.getSchema(), t2.getSchema());
checkEquals(t1.getStatistics(), t2.getStatistics());
- assertEquals(t1.getComment(), t2.getComment());
+ assertEquals(t1.getDescription(), t2.getDescription());
}
protected static void checkEquals(TableStats ts1, TableStats ts2) {