Skip to content

Commit

Permalink
[fix] Fix failed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tsreaper committed Jul 31, 2024
1 parent 072f9cc commit f4ff5e6
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ public static String randomNumericString(int len) {
* @return an array of parsed Strings, {@code null} if null String input
*/
public static String[] split(final String str, final String separatorChars) {
return splitWorker(str, separatorChars, -1, false);
return split(str, separatorChars, -1, false);
}

/**
Expand All @@ -388,7 +388,7 @@ public static String[] split(final String str, final String separatorChars) {
* separators; if {@code false}, adjacent separators are treated as one separator.
* @return an array of parsed Strings, {@code null} if null String input
*/
private static String[] splitWorker(
public static String[] split(
final String str,
final String separatorChars,
final int max,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private void splitObjectName() {
return;
}

String[] splits = StringUtils.split(object, Catalog.SYSTEM_TABLE_SPLITTER);
String[] splits = StringUtils.split(object, Catalog.SYSTEM_TABLE_SPLITTER, -1, true);
if (splits.length == 1) {
table = object;
branch = null;
Expand All @@ -130,7 +130,9 @@ private void splitObjectName() {
systemTable = splits[1];
}
} else if (splits.length == 3) {
Preconditions.checkArgument(splits[1].startsWith(Catalog.SYSTEM_BRANCH_PREFIX));
Preconditions.checkArgument(
splits[1].startsWith(Catalog.SYSTEM_BRANCH_PREFIX),
"System table can only contain one '$' separator, but this is: " + object);
table = splits[0];
branch = splits[1].substring(Catalog.SYSTEM_BRANCH_PREFIX.length());
systemTable = splits[2];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,10 @@ public static Identifier identifierFromPath(String tablePath, boolean ignoreIfUn

public static Identifier identifierFromPath(
String tablePath, boolean ignoreIfUnknownDatabase, @Nullable String branchName) {
if (DEFAULT_MAIN_BRANCH.equals(branchName)) {
branchName = null;
}

String[] paths = tablePath.split("/");
if (paths.length < 2) {
if (!ignoreIfUnknownDatabase) {
Expand All @@ -621,6 +625,7 @@ public static Identifier identifierFromPath(
return new Identifier(UNKNOWN_DATABASE, paths[paths.length - 1], branchName, null);
}
database = database.substring(0, index);

return new Identifier(database, paths[paths.length - 1], branchName, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,7 @@ public Identifier identifier() {
? SchemaManager.identifierFromPath(
location().toUri().toString(),
true,
options().containsKey(CoreOptions.BRANCH.key())
? coreOptions().branch()
: null)
options().get(CoreOptions.BRANCH.key()))
: identifier;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public void testCreateTable() throws Exception {
DEFAULT_TABLE_SCHEMA,
false))
.withMessage(
"Cannot 'createTable' for system table 'Identifier{database='test_db', table='$system_table'}', please use data table.");
"Cannot 'createTable' for system table 'Identifier{database='test_db', object='$system_table'}', please use data table.");

// Create table throws DatabaseNotExistException when database does not exist
assertThatExceptionOfType(Catalog.DatabaseNotExistException.class)
Expand Down Expand Up @@ -367,7 +367,7 @@ public void testDropTable() throws Exception {
catalog.dropTable(
Identifier.create("test_db", "$system_table"), false))
.withMessage(
"Cannot 'dropTable' for system table 'Identifier{database='test_db', table='$system_table'}', please use data table.");
"Cannot 'dropTable' for system table 'Identifier{database='test_db', object='$system_table'}', please use data table.");

// Drop table throws TableNotExistException when table does not exist and ignoreIfNotExists
// is false
Expand Down Expand Up @@ -402,7 +402,7 @@ public void testRenameTable() throws Exception {
toTable,
false))
.withMessage(
"Cannot 'renameTable' for system table 'Identifier{database='test_db', table='$system_table'}', please use data table.");
"Cannot 'renameTable' for system table 'Identifier{database='test_db', object='$system_table'}', please use data table.");

assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(
Expand All @@ -412,7 +412,7 @@ public void testRenameTable() throws Exception {
Identifier.create("test_db", "$system_table"),
false))
.withMessage(
"Cannot 'renameTable' for system table 'Identifier{database='test_db', table='$system_table'}', please use data table.");
"Cannot 'renameTable' for system table 'Identifier{database='test_db', object='$system_table'}', please use data table.");

// Rename table throws TableNotExistException when table does not exist
assertThatExceptionOfType(Catalog.TableNotExistException.class)
Expand Down Expand Up @@ -466,7 +466,7 @@ public void testAlterTable() throws Exception {
SchemaChange.addColumn("col2", DataTypes.DATE())),
false))
.withMessage(
"Cannot 'alterTable' for system table 'Identifier{database='test_db', table='$system_table'}', please use data table.");
"Cannot 'alterTable' for system table 'Identifier{database='test_db', object='$system_table'}', please use data table.");

// Alter table throws TableNotExistException when table does not exist
assertThatExceptionOfType(Catalog.TableNotExistException.class)
Expand Down

0 comments on commit f4ff5e6

Please sign in to comment.