-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[core]Fix drop table in Hive and jdbc catalog when the file path does not exists. #4860
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
import org.apache.paimon.catalog.Catalog; | ||
import org.apache.paimon.catalog.CatalogTestBase; | ||
import org.apache.paimon.catalog.Identifier; | ||
import org.apache.paimon.fs.Path; | ||
import org.apache.paimon.options.CatalogOptions; | ||
import org.apache.paimon.options.Options; | ||
import org.apache.paimon.table.Table; | ||
|
@@ -33,6 +34,7 @@ | |
import java.io.ByteArrayOutputStream; | ||
import java.io.ObjectOutputStream; | ||
import java.sql.SQLException; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
|
@@ -117,6 +119,33 @@ public void testSerializeTable() throws Exception { | |
}); | ||
} | ||
|
||
@Test | ||
public void testDropTable() throws Exception { | ||
String databaseName = "test_db"; | ||
String tableName = "new_table"; | ||
catalog.createDatabase(databaseName, false); | ||
catalog.createTable( | ||
Identifier.create(databaseName, tableName), DEFAULT_TABLE_SCHEMA, false); | ||
JdbcCatalog jdbcCatalog = (JdbcCatalog) catalog; | ||
Path path = jdbcCatalog.getTableLocation(Identifier.create(databaseName, tableName)); | ||
// delete file path | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe "delete table path" is better? |
||
catalog.fileIO().deleteDirectoryQuietly(path); | ||
|
||
assertThatThrownBy(() -> catalog.getTable(Identifier.create(databaseName, tableName))) | ||
.isInstanceOf(RuntimeException.class) | ||
.hasMessage( | ||
"There is no paimon table in " | ||
+ jdbcCatalog.getTableLocation( | ||
Identifier.create(databaseName, tableName))); | ||
|
||
List<String> tablesCon = catalog.listTables(databaseName); | ||
assertThat(tablesCon).contains(tableName); | ||
|
||
catalog.dropTable(Identifier.create(databaseName, tableName), false); | ||
List<String> tables = catalog.listTables(databaseName); | ||
assertThat(tableName).isNotIn(tables); | ||
} | ||
|
||
@Test | ||
public void testAlterDatabase() throws Exception { | ||
this.alterDatabaseWhenSupportAlter(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1442,6 +1442,22 @@ public static String possibleHiveConfPath() { | |
return System.getenv("HIVE_CONF_DIR"); | ||
} | ||
|
||
protected boolean tableExists(Identifier identifier) { | ||
try { | ||
return clients.run( | ||
client -> | ||
client.tableExists( | ||
identifier.getDatabaseName(), identifier.getTableName())); | ||
} catch (TException e) { | ||
throw new RuntimeException( | ||
"Cannot determine if table " + identifier.getFullName() + "exists.", e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "exists." -> " exists." |
||
} catch (InterruptedException e) { | ||
Thread.currentThread().interrupt(); | ||
throw new RuntimeException( | ||
"Interrupted in call to tableExists " + identifier.getFullName(), e); | ||
} | ||
} | ||
|
||
public int getBatchGetTableSize() { | ||
try { | ||
int size = | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
import org.apache.paimon.catalog.CatalogTestBase; | ||
import org.apache.paimon.catalog.Identifier; | ||
import org.apache.paimon.client.ClientPool; | ||
import org.apache.paimon.fs.Path; | ||
import org.apache.paimon.options.CatalogOptions; | ||
import org.apache.paimon.options.Options; | ||
import org.apache.paimon.schema.Schema; | ||
|
@@ -60,6 +61,7 @@ | |
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
/** Tests for {@link HiveCatalog}. */ | ||
|
@@ -277,6 +279,47 @@ public void testAlterHiveTableParameters() { | |
} | ||
} | ||
|
||
@Test | ||
public void testDropTable() { | ||
try { | ||
String databaseName = "test_db"; | ||
catalog.createDatabase(databaseName, false); | ||
String tableName = "new_table"; | ||
Map<String, String> options = new HashMap<>(); | ||
Schema addHiveTableParametersSchema = | ||
new Schema( | ||
Lists.newArrayList( | ||
new DataField(0, "pk", DataTypes.INT()), | ||
new DataField(1, "col1", DataTypes.STRING()), | ||
new DataField(2, "col2", DataTypes.STRING())), | ||
Collections.emptyList(), | ||
Collections.emptyList(), | ||
options, | ||
""); | ||
|
||
catalog.createTable( | ||
Identifier.create(databaseName, tableName), | ||
addHiveTableParametersSchema, | ||
false); | ||
// delete file path | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dito |
||
HiveCatalog hiveCatalog = (HiveCatalog) catalog; | ||
Path path = hiveCatalog.getTableLocation(Identifier.create(databaseName, tableName)); | ||
catalog.fileIO().deleteDirectoryQuietly(path); | ||
assertThrows( | ||
Catalog.TableNotExistException.class, | ||
() -> catalog.getTable(Identifier.create(databaseName, tableName))); | ||
|
||
List<String> tablesCon = catalog.listTables(databaseName); | ||
assertThat(tablesCon).contains(tableName); | ||
|
||
catalog.dropTable(Identifier.create(databaseName, tableName), false); | ||
List<String> tables = catalog.listTables(databaseName); | ||
assertThat(tableName).isNotIn(tables); | ||
} catch (Exception e) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This try statement is very big, maybe add "throw Exception" in the method signature is better? |
||
fail("Test failed due to exception: " + e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testListTablesLock() { | ||
try { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In hive and jdbc catalog, tableExists method has different implement. So I used protected.