commit c80c1b5073872f4fa8e0478d9be903ffaf1b1ec3 Author: Alan Gates Date: Tue Jun 12 14:07:17 2018 -0700 HIVE-19871 add_partitions, create constraint calls and create_table_with_constraints do not properly handle client being configured with a non-Hive catalog diff --git standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java index 8d7b0c394d..04a78d4927 100644 --- standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java +++ standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java @@ -1865,6 +1865,25 @@ private void create_table_core(final RawStore ms, final Table tbl, && checkConstraints == null) { ms.createTable(tbl); } else { + // Check that constraints have catalog name properly set first + if (primaryKeys != null && !primaryKeys.isEmpty() && !primaryKeys.get(0).isSetCatName()) { + for (SQLPrimaryKey pkcol : primaryKeys) pkcol.setCatName(tbl.getCatName()); + } + if (foreignKeys != null && !foreignKeys.isEmpty() && !foreignKeys.get(0).isSetCatName()) { + for (SQLForeignKey fkcol : foreignKeys) fkcol.setCatName(tbl.getCatName()); + } + if (uniqueConstraints != null && !uniqueConstraints.isEmpty() && !uniqueConstraints.get(0).isSetCatName()) { + for (SQLUniqueConstraint uccol : uniqueConstraints) uccol.setCatName(tbl.getCatName()); + } + if (notNullConstraints != null && !notNullConstraints.isEmpty() && !notNullConstraints.get(0).isSetCatName()) { + for (SQLNotNullConstraint nncol : notNullConstraints) nncol.setCatName(tbl.getCatName()); + } + if (defaultConstraints != null && !defaultConstraints.isEmpty() && !defaultConstraints.get(0).isSetCatName()) { + for (SQLDefaultConstraint dccol : defaultConstraints) dccol.setCatName(tbl.getCatName()); + } + if (checkConstraints != null && !checkConstraints.isEmpty() && !checkConstraints.get(0).isSetCatName()) { + for (SQLCheckConstraint cccol : checkConstraints) cccol.setCatName(tbl.getCatName()); + } // Set constraint name if null before sending to listener List constraintNames = ms.createTableWithConstraints(tbl, primaryKeys, foreignKeys, uniqueConstraints, notNullConstraints, defaultConstraints, checkConstraints); @@ -1875,6 +1894,7 @@ private void create_table_core(final RawStore ms, final Table tbl, if (primaryKeys.get(i).getPk_name() == null) { primaryKeys.get(i).setPk_name(constraintNames.get(i)); } + if (!primaryKeys.get(i).isSetCatName()) primaryKeys.get(i).setCatName(tbl.getCatName()); } } int foreignKeySize = 0; @@ -1884,6 +1904,7 @@ private void create_table_core(final RawStore ms, final Table tbl, if (foreignKeys.get(i).getFk_name() == null) { foreignKeys.get(i).setFk_name(constraintNames.get(primaryKeySize + i)); } + if (!foreignKeys.get(i).isSetCatName()) foreignKeys.get(i).setCatName(tbl.getCatName()); } } int uniqueConstraintSize = 0; @@ -1893,6 +1914,7 @@ private void create_table_core(final RawStore ms, final Table tbl, if (uniqueConstraints.get(i).getUk_name() == null) { uniqueConstraints.get(i).setUk_name(constraintNames.get(primaryKeySize + foreignKeySize + i)); } + if (!uniqueConstraints.get(i).isSetCatName()) uniqueConstraints.get(i).setCatName(tbl.getCatName()); } } int notNullConstraintSize = 0; @@ -1901,6 +1923,7 @@ private void create_table_core(final RawStore ms, final Table tbl, if (notNullConstraints.get(i).getNn_name() == null) { notNullConstraints.get(i).setNn_name(constraintNames.get(primaryKeySize + foreignKeySize + uniqueConstraintSize + i)); } + if (!notNullConstraints.get(i).isSetCatName()) notNullConstraints.get(i).setCatName(tbl.getCatName()); } } int defaultConstraintSize = 0; @@ -1910,6 +1933,7 @@ private void create_table_core(final RawStore ms, final Table tbl, defaultConstraints.get(i).setDc_name(constraintNames.get(primaryKeySize + foreignKeySize + uniqueConstraintSize + notNullConstraintSize + i)); } + if (!defaultConstraints.get(i).isSetCatName()) defaultConstraints.get(i).setCatName(tbl.getCatName()); } } if (checkConstraints!= null) { @@ -1920,6 +1944,7 @@ private void create_table_core(final RawStore ms, final Table tbl, + defaultConstraintSize + notNullConstraintSize + i)); } + if (!checkConstraints.get(i).isSetCatName()) checkConstraints.get(i).setCatName(tbl.getCatName()); } } } @@ -2091,6 +2116,10 @@ public void add_primary_key(AddPrimaryKeyRequest req) startFunction("add_primary_key", ": " + constraintName); boolean success = false; Exception ex = null; + if (!primaryKeyCols.isEmpty() && !primaryKeyCols.get(0).isSetCatName()) { + String defaultCat = getDefaultCatalog(conf); + primaryKeyCols.forEach(pk -> pk.setCatName(defaultCat)); + } RawStore ms = getMS(); try { ms.openTransaction(); @@ -2140,6 +2169,10 @@ public void add_foreign_key(AddForeignKeyRequest req) startFunction("add_foreign_key", ": " + constraintName); boolean success = false; Exception ex = null; + if (!foreignKeyCols.isEmpty() && !foreignKeyCols.get(0).isSetCatName()) { + String defaultCat = getDefaultCatalog(conf); + foreignKeyCols.forEach(pk -> pk.setCatName(defaultCat)); + } RawStore ms = getMS(); try { ms.openTransaction(); @@ -2189,6 +2222,10 @@ public void add_unique_constraint(AddUniqueConstraintRequest req) startFunction("add_unique_constraint", ": " + constraintName); boolean success = false; Exception ex = null; + if (!uniqueConstraintCols.isEmpty() && !uniqueConstraintCols.get(0).isSetCatName()) { + String defaultCat = getDefaultCatalog(conf); + uniqueConstraintCols.forEach(pk -> pk.setCatName(defaultCat)); + } RawStore ms = getMS(); try { ms.openTransaction(); @@ -2238,6 +2275,10 @@ public void add_not_null_constraint(AddNotNullConstraintRequest req) startFunction("add_not_null_constraint", ": " + constraintName); boolean success = false; Exception ex = null; + if (!notNullConstraintCols.isEmpty() && !notNullConstraintCols.get(0).isSetCatName()) { + String defaultCat = getDefaultCatalog(conf); + notNullConstraintCols.forEach(pk -> pk.setCatName(defaultCat)); + } RawStore ms = getMS(); try { ms.openTransaction(); @@ -2287,6 +2328,10 @@ public void add_default_constraint(AddDefaultConstraintRequest req) startFunction("add_default_constraint", ": " + constraintName); boolean success = false; Exception ex = null; + if (!defaultConstraintCols.isEmpty() && !defaultConstraintCols.get(0).isSetCatName()) { + String defaultCat = getDefaultCatalog(conf); + defaultConstraintCols.forEach(pk -> pk.setCatName(defaultCat)); + } RawStore ms = getMS(); try { ms.openTransaction(); @@ -2337,6 +2382,10 @@ public void add_check_constraint(AddCheckConstraintRequest req) startFunction("add_check_constraint", ": " + constraintName); boolean success = false; Exception ex = null; + if (!checkConstraintCols.isEmpty() && !checkConstraintCols.get(0).isSetCatName()) { + String defaultCat = getDefaultCatalog(conf); + checkConstraintCols.forEach(pk -> pk.setCatName(defaultCat)); + } RawStore ms = getMS(); try { ms.openTransaction(); diff --git standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java index 4957db9a0a..89909286a7 100644 --- standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java +++ standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java @@ -690,6 +690,11 @@ public int add_partitions(List new_parts) throws TException { return needResults ? new ArrayList<>() : null; } Partition part = parts.get(0); + // Have to set it for each partition too + if (!part.isSetCatName()) { + final String defaultCat = getDefaultCatalog(conf); + parts.forEach(p -> p.setCatName(defaultCat)); + } AddPartitionsRequest req = new AddPartitionsRequest( part.getDbName(), part.getTableName(), parts, ifNotExists); req.setCatName(part.isSetCatName() ? part.getCatName() : getDefaultCatalog(conf)); diff --git standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/NonCatCallsWithCatalog.java standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/NonCatCallsWithCatalog.java index 0194178f0f..f750ca2a9b 100644 --- standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/NonCatCallsWithCatalog.java +++ standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/NonCatCallsWithCatalog.java @@ -44,8 +44,6 @@ import org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint; import org.apache.hadoop.hive.metastore.api.SQLPrimaryKey; import org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint; -import org.apache.hadoop.hive.metastore.api.SerDeInfo; -import org.apache.hadoop.hive.metastore.api.StorageDescriptor; import org.apache.hadoop.hive.metastore.api.Table; import org.apache.hadoop.hive.metastore.api.TableMeta; import org.apache.hadoop.hive.metastore.api.UniqueConstraintsRequest; @@ -66,7 +64,6 @@ import org.junit.After; import org.junit.Assert; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import java.io.File; @@ -75,7 +72,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -91,8 +87,8 @@ "org.apache.hadoop.hive.ql.udf.generic.GenericUDFUpper"; protected Configuration conf; - protected IMetaStoreClient client; + protected abstract IMetaStoreClient getClient() throws Exception; protected abstract String expectedCatalog(); protected abstract String expectedBaseDir() throws MetaException; @@ -116,13 +112,18 @@ public void setUp() throws Exception { client.dropTable(DEFAULT_DATABASE_NAME, tableName, true, true, true); } + Database db = new DatabaseBuilder().setName(OTHER_DATABASE).build(conf); + db.unsetCatalogName(); + client.createDatabase(db); + + testTables[0] = new TableBuilder() .setTableName("test_table") .addCol("test_col1", "int") .addCol("test_col2", "int") .addCol("test_col3", "int") - .create(client, conf); + .build(conf); testTables[1] = new TableBuilder() @@ -131,7 +132,7 @@ public void setUp() throws Exception { .addCol("test_col2", "int") .addCol("test_col3", "int") .setType("VIRTUAL_VIEW") - .create(client, conf); + .build(conf); testTables[2] = new TableBuilder() @@ -139,7 +140,7 @@ public void setUp() throws Exception { .addCol("test_col1", "int") .addCol("test_col2", "int") .addCol("test_col3", "int") - .create(client, conf); + .build(conf); testTables[3] = new TableBuilder() @@ -147,7 +148,7 @@ public void setUp() throws Exception { .addCol("test_col1", "int") .addCol("test_col2", "int") .addPartCol("test_part_col", "int") - .create(client, conf); + .build(conf); testTables[4] = new TableBuilder() @@ -156,24 +157,28 @@ public void setUp() throws Exception { .setLocation(MetaStoreTestUtils.getTestWarehouseDir("/external/table_dir")) .addTableParam("EXTERNAL", "TRUE") .setType("EXTERNAL_TABLE") - .create(client, conf); - - - new DatabaseBuilder().setName(OTHER_DATABASE).create(client, conf); + .build(conf); testTables[5] = new TableBuilder() .setDbName(OTHER_DATABASE) .setTableName("test_table") .addCol("test_col", "int") - .create(client, conf); + .build(conf); + + for (Table t : testTables) { + t.unsetCatName(); + client.createTable(t); + } // Create partitions for the partitioned table for(int i=0; i < 3; i++) { - new PartitionBuilder() + Partition p = new PartitionBuilder() .inTable(testTables[3]) .addValue("a" + i) - .addToTable(client, conf); + .build(conf); + p.unsetCatName(); + client.add_partition(p); } } @@ -196,14 +201,19 @@ public void databases() throws TException, URISyntaxException { // For this one don't specify a location to make sure it gets put in the catalog directory dbs[0] = new DatabaseBuilder() .setName(dbNames[0]) - .create(client, conf); + .build(conf); // For the second one, explicitly set a location to make sure it ends up in the specified place. String db1Location = MetaStoreTestUtils.getTestWarehouseDir(dbNames[1]); dbs[1] = new DatabaseBuilder() .setName(dbNames[1]) .setLocation(db1Location) - .create(client, conf); + .build(conf); + + for (Database db : dbs) { + db.unsetCatalogName(); + client.createDatabase(db); + } Database fetched = client.getDatabase(dbNames[0]); String expectedLocation = new File(expectedBaseDir(), dbNames[0] + ".db").toURI().toString(); @@ -245,7 +255,9 @@ public void tablesCreateDropAlterTruncate() throws TException, URISyntaxExceptio // For this one don't specify a location to make sure it gets put in the catalog directory Database db = new DatabaseBuilder() .setName(dbName) - .create(client, conf); + .build(conf); + db.unsetCatalogName(); + client.createDatabase(db); String[] tableNames = new String[4]; for (int i = 0; i < tableNames.length; i++) { @@ -268,7 +280,9 @@ public void tablesCreateDropAlterTruncate() throws TException, URISyntaxExceptio .addMaterializedViewReferencedTable(dbName + "." + tableNames[0]); } */ - client.createTable(builder.build(conf)); + Table t = builder.build(conf); + t.unsetCatName(); + client.createTable(t); } // Add partitions for the partitioned table @@ -276,10 +290,12 @@ public void tablesCreateDropAlterTruncate() throws TException, URISyntaxExceptio Table partitionedTable = client.getTable(dbName, tableNames[2]); for (int i = 0; i < partVals.length; i++) { partVals[i] = "part" + i; - new PartitionBuilder() + Partition p = new PartitionBuilder() .inTable(partitionedTable) .addValue(partVals[i]) - .addToTable(client, conf); + .build(conf); + p.unsetCatName(); + client.add_partition(p); } // Get tables, make sure the locations are correct @@ -386,17 +402,21 @@ public void tablesGetExists() throws TException { // For this one don't specify a location to make sure it gets put in the catalog directory Database db = new DatabaseBuilder() .setName(dbName) - .create(client, conf); + .build(conf); + db.unsetCatalogName(); + client.createDatabase(db); String[] tableNames = new String[4]; for (int i = 0; i < tableNames.length; i++) { tableNames[i] = "table_in_other_catalog_" + i; - new TableBuilder() + Table table = new TableBuilder() .inDb(db) .setTableName(tableNames[i]) .addCol("col1_" + i, ColumnType.STRING_TYPE_NAME) .addCol("col2_" + i, ColumnType.INT_TYPE_NAME) - .create(client, conf); + .build(conf); + table.unsetCatName(); + client.createTable(table); } Set tables = new HashSet<>(client.getTables(dbName, "*e_in_other_*")); @@ -417,7 +437,9 @@ public void tablesList() throws TException { // For this one don't specify a location to make sure it gets put in the catalog directory Database db = new DatabaseBuilder() .setName(dbName) - .create(client, conf); + .build(conf); + db.unsetCatalogName(); + client.createDatabase(db); String[] tableNames = new String[4]; for (int i = 0; i < tableNames.length; i++) { @@ -428,7 +450,9 @@ public void tablesList() throws TException { .addCol("col1_" + i, ColumnType.STRING_TYPE_NAME) .addCol("col2_" + i, ColumnType.INT_TYPE_NAME); if (i == 0) builder.addTableParam("the_key", "the_value"); - builder.create(client, conf); + Table table = builder.build(conf); + table.unsetCatName(); + client.createTable(table); } String filter = hive_metastoreConstants.HIVE_FILTER_FIELD_PARAMS + "the_key=\"the_value\""; @@ -443,17 +467,21 @@ public void getTableMeta() throws TException { // For this one don't specify a location to make sure it gets put in the catalog directory Database db = new DatabaseBuilder() .setName(dbName) - .create(client, conf); + .build(conf); + db.unsetCatalogName(); + client.createDatabase(db); String[] tableNames = {"table_in_other_catalog_1", "table_in_other_catalog_2", "random_name"}; List expected = new ArrayList<>(tableNames.length); for (int i = 0; i < tableNames.length; i++) { - client.createTable(new TableBuilder() + Table table = new TableBuilder() .inDb(db) .setTableName(tableNames[i]) .addCol("id", "int") .addCol("name", "string") - .build(conf)); + .build(conf); + table.unsetCatName(); + client.createTable(table); expected.add(new TableMeta(dbName, tableNames[i], TableType.MANAGED_TABLE.name())); } @@ -471,7 +499,9 @@ public void addPartitions() throws TException { String dbName = "add_partition_database_in_other_catalog"; Database db = new DatabaseBuilder() .setName(dbName) - .create(client, conf); + .build(conf); + db.unsetCatalogName(); + client.createDatabase(db); String tableName = "table_in_other_catalog"; Table table = new TableBuilder() @@ -480,7 +510,9 @@ public void addPartitions() throws TException { .addCol("id", "int") .addCol("name", "string") .addPartCol("partcol", "string") - .create(client, conf); + .build(conf); + table.unsetCatName(); + client.createTable(table); Partition[] parts = new Partition[5]; for (int i = 0; i < parts.length; i++) { @@ -488,10 +520,11 @@ public void addPartitions() throws TException { .inTable(table) .addValue("a" + i) .build(conf); + parts[i].unsetCatName(); } client.add_partition(parts[0]); Assert.assertEquals(2, client.add_partitions(Arrays.asList(parts[1], parts[2]))); - client.add_partitions(Arrays.asList(parts), true, false); + client.add_partitions(Arrays.asList(parts[3], parts[4]), true, false); for (int i = 0; i < parts.length; i++) { Partition fetched = client.getPartition(dbName, tableName, @@ -509,7 +542,9 @@ public void getPartitions() throws TException { String dbName = "get_partition_database_in_other_catalog"; Database db = new DatabaseBuilder() .setName(dbName) - .create(client, conf); + .build(conf); + db.unsetCatalogName(); + client.createDatabase(db); String tableName = "table_in_other_catalog"; Table table = new TableBuilder() @@ -519,7 +554,9 @@ public void getPartitions() throws TException { .addCol("name", "string") .addPartCol("partcol", "string") .addTableParam("PARTITION_LEVEL_PRIVILEGE", "true") - .create(client, conf); + .build(conf); + table.unsetCatName(); + client.createTable(table); Partition[] parts = new Partition[5]; for (int i = 0; i < parts.length; i++) { @@ -527,6 +564,7 @@ public void getPartitions() throws TException { .inTable(table) .addValue("a" + i) .build(conf); + parts[i].unsetCatName(); } client.add_partitions(Arrays.asList(parts)); @@ -554,7 +592,9 @@ public void listPartitions() throws TException { String dbName = "list_partition_database_in_other_catalog"; Database db = new DatabaseBuilder() .setName(dbName) - .create(client, conf); + .build(conf); + db.unsetCatalogName(); + client.createDatabase(db); String tableName = "table_in_other_catalog"; Table table = new TableBuilder() @@ -563,7 +603,9 @@ public void listPartitions() throws TException { .addCol("id", "int") .addCol("name", "string") .addPartCol("partcol", "string") - .create(client, conf); + .build(conf); + table.unsetCatName(); + client.createTable(table); Partition[] parts = new Partition[5]; for (int i = 0; i < parts.length; i++) { @@ -571,6 +613,7 @@ public void listPartitions() throws TException { .inTable(table) .addValue("a" + i) .build(conf); + parts[i].unsetCatName(); } client.add_partitions(Arrays.asList(parts)); @@ -616,7 +659,9 @@ public void alterPartitions() throws TException { String dbName = "alter_partition_database_in_other_catalog"; Database db = new DatabaseBuilder() .setName(dbName) - .create(client, conf); + .build(conf); + db.unsetCatalogName(); + client.createDatabase(db); String tableName = "table_in_other_catalog"; Table table = new TableBuilder() @@ -625,7 +670,9 @@ public void alterPartitions() throws TException { .addCol("id", "int") .addCol("name", "string") .addPartCol("partcol", "string") - .create(client, conf); + .build(conf); + table.unsetCatName(); + client.createTable(table); Partition[] parts = new Partition[5]; for (int i = 0; i < 5; i++) { @@ -634,6 +681,7 @@ public void alterPartitions() throws TException { .addValue("a" + i) .setLocation(MetaStoreTestUtils.getTestWarehouseDir("b" + i)) .build(conf); + parts[i].unsetCatName(); } client.add_partitions(Arrays.asList(parts)); @@ -679,7 +727,9 @@ public void dropPartitions() throws TException { String dbName = "drop_partition_database_in_other_catalog"; Database db = new DatabaseBuilder() .setName(dbName) - .create(client, conf); + .build(conf); + db.unsetCatalogName(); + client.createDatabase(db); String tableName = "table_in_other_catalog"; Table table = new TableBuilder() @@ -688,7 +738,9 @@ public void dropPartitions() throws TException { .addCol("id", "int") .addCol("name", "string") .addPartCol("partcol", "string") - .create(client, conf); + .build(conf); + table.unsetCatName(); + client.createTable(table); Partition[] parts = new Partition[2]; for (int i = 0; i < parts.length; i++) { @@ -696,6 +748,7 @@ public void dropPartitions() throws TException { .inTable(table) .addValue("a" + i) .build(conf); + parts[i].unsetCatName(); } client.add_partitions(Arrays.asList(parts)); List fetched = client.listPartitions(dbName, tableName, (short)-1); @@ -897,45 +950,53 @@ public void createTableWithConstraints() throws TException { .addCol("col5", "int") .addCol("col6", "int") .build(conf); + table.unsetCatName(); List parentPk = new SQLPrimaryKeyBuilder() .onTable(parentTable) .addColumn("test_col1") .build(conf); + for (SQLPrimaryKey pkcol : parentPk) pkcol.unsetCatName(); client.addPrimaryKey(parentPk); List pk = new SQLPrimaryKeyBuilder() .onTable(table) .addColumn("col2") .build(conf); + for (SQLPrimaryKey pkcol : pk) pkcol.unsetCatName(); List fk = new SQLForeignKeyBuilder() .fromPrimaryKey(parentPk) .onTable(table) .addColumn("col1") .build(conf); + for (SQLForeignKey fkcol : fk) fkcol.unsetCatName(); List dv = new SQLDefaultConstraintBuilder() .onTable(table) .addColumn("col3") .setDefaultVal(0) .build(conf); + for (SQLDefaultConstraint dccol : dv) dccol.unsetCatName(); List nn = new SQLNotNullConstraintBuilder() .onTable(table) .addColumn("col4") .build(conf); + for (SQLNotNullConstraint nncol : nn) nncol.unsetCatName(); List uc = new SQLUniqueConstraintBuilder() .onTable(table) .addColumn("col5") .build(conf); + for (SQLUniqueConstraint uccol : uc) uccol.unsetCatName(); List cc = new SQLCheckConstraintBuilder() .onTable(table) .addColumn("col6") .setCheckExpression("> 0") .build(conf); + for (SQLCheckConstraint cccol : cc) cccol.unsetCatName(); client.createTableWithConstraints(table, pk, fk, uc, nn, dv, cc); @@ -1036,7 +1097,9 @@ public void functions() throws TException { String dbName = "functions_other_catalog_db"; Database db = new DatabaseBuilder() .setName(dbName) - .create(client, conf); + .build(conf); + db.unsetCatalogName(); + client.createDatabase(db); String functionName = "test_function"; Function function = @@ -1047,23 +1110,32 @@ public void functions() throws TException { .setFunctionType(FunctionType.JAVA) .setOwnerType(PrincipalType.ROLE) .setOwner("owner") - .setCreateTime(100) .addResourceUri(new ResourceUri(ResourceType.JAR, "hdfs:///tmp/jar1.jar")) .addResourceUri(new ResourceUri(ResourceType.FILE, "hdfs:///tmp/file1.txt")) .addResourceUri(new ResourceUri(ResourceType.ARCHIVE, "hdfs:///tmp/archive1.tgz")) - .create(client, conf); + .build(conf); + function.unsetCatName(); + client.createFunction(function); Function createdFunction = client.getFunction(dbName, functionName); - // The createTime will be set on the server side, so the comparison should skip it - function.setCreateTime(createdFunction.getCreateTime()); - Assert.assertEquals("Comparing functions", function, createdFunction); + // Creation time will be set by server and not us. + Assert.assertEquals(function.getFunctionName(), createdFunction.getFunctionName()); + Assert.assertEquals(function.getDbName(), createdFunction.getDbName()); + Assert.assertEquals(expectedCatalog(), createdFunction.getCatName()); + Assert.assertEquals(function.getClassName(), createdFunction.getClassName()); + Assert.assertEquals(function.getOwnerName(), createdFunction.getOwnerName()); + Assert.assertEquals(function.getOwnerType(), createdFunction.getOwnerType()); + Assert.assertEquals(function.getFunctionType(), createdFunction.getFunctionType()); + Assert.assertEquals(function.getResourceUris(), createdFunction.getResourceUris()); String f2Name = "testy_function2"; Function f2 = new FunctionBuilder() .inDb(db) .setName(f2Name) .setClass(TEST_FUNCTION_CLASS) - .create(client, conf); + .build(conf); + f2.unsetCatName(); + client.createFunction(f2); Set functions = new HashSet<>(client.getFunctions(dbName, "test*")); Assert.assertEquals(2, functions.size()); @@ -1083,45 +1155,4 @@ public void functions() throws TException { // Expected exception } } - - // Run a test without the builders. They make certain default assumptions about catalogs, etc. - // Make sure things still work without those assumptions. - @Test - public void noBuilders() throws TException { - String dbName = "db_no_builder"; - - Database db = new Database(dbName, "bla", MetaStoreTestUtils.getTestWarehouseDir(dbName), - new HashMap<>()); - client.createDatabase(db); - - Database fetched = client.getDatabase(dbName); - Assert.assertEquals(expectedCatalog(), fetched.getCatalogName()); - - String tableName = "now_I_remember_why_I_made_those_builders"; - List cols = Arrays.asList( - new FieldSchema("col1", "int", ""), - new FieldSchema("col2", "int", "") - ); - List partKeys = Collections.singletonList(new FieldSchema("pk1", "string", "")); - SerDeInfo serdeInfo = new SerDeInfo("serde", "lib", new HashMap<>()); - StorageDescriptor sd = new StorageDescriptor(cols, null, - "org.apache.hadoop.hive.ql.io.HiveInputFormat", - "org.apache.hadoop.hive.ql.io.HiveOutputFormat", false, 0, serdeInfo, new ArrayList<>(), - new ArrayList<>(), new HashMap<>()); - Table table = new Table(tableName, dbName, "me", 0, 0, 0, sd, partKeys, new HashMap<>(), - null, null, TableType.MANAGED_TABLE.name()); - client.createTable(table); - - Table fetchedTable = client.getTable(dbName, tableName); - Assert.assertEquals(expectedCatalog(), fetchedTable.getCatName()); - - List values = Collections.singletonList("p1"); - Partition part = new Partition(values, dbName, tableName, 0, 0, sd, new HashMap<>()); - client.add_partition(part); - - Partition fetchedPart = client.getPartition(dbName, tableName, values); - Assert.assertEquals(expectedCatalog(), fetchedPart.getCatName()); - - client.dropDatabase(dbName, true, false, true); - } }