Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
JingsongLi committed Nov 4, 2024
1 parent ca72869 commit b9f632a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 69 deletions.
21 changes: 5 additions & 16 deletions paimon-core/src/main/java/org/apache/paimon/catalog/Catalog.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.util.stream.Collectors;

import static org.apache.paimon.options.OptionsUtils.convertToPropertiesPrefixKey;
import static org.apache.paimon.utils.BranchManager.DEFAULT_MAIN_BRANCH;
import static org.apache.paimon.utils.Preconditions.checkArgument;

/**
Expand Down Expand Up @@ -514,26 +513,16 @@ public Identifier identifier() {
/** Exception for trying to operate on a table that doesn't exist. */
class TableNotExistException extends Exception {

private static final String MSG_TABLE = "Table %s does not exist.";
private static final String MSG_BRANCH = "Branch %s does not exist.";
private static final String MSG = "Table %s does not exist.";

private final Identifier identifier;

public TableNotExistException(Identifier identifier) {
this(identifier, null, DEFAULT_MAIN_BRANCH);
}

public TableNotExistException(Identifier identifier, String branchName) {
this(identifier, null, branchName);
this(identifier, null);
}

public TableNotExistException(Identifier identifier, Throwable cause, String branchName) {
super(
branchName.equals(DEFAULT_MAIN_BRANCH)
? String.format(MSG_TABLE, identifier.getFullName())
: String.format(
MSG_BRANCH,
identifier.getFullName() + BRANCH_PREFIX + branchName),
cause);
public TableNotExistException(Identifier identifier, Throwable cause) {
super(String.format(MSG, identifier.getFullName()), cause);
this.identifier = identifier;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.apache.paimon.types.RowType;
import org.apache.paimon.view.View;
import org.apache.paimon.view.ViewImpl;
import org.apache.paimon.utils.BranchManager;

import org.apache.paimon.shade.guava30.com.google.common.collect.Lists;
import org.apache.paimon.shade.guava30.com.google.common.collect.Maps;
Expand All @@ -41,7 +40,6 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand All @@ -57,7 +55,7 @@
/** Base test class of paimon catalog in {@link Catalog}. */
public abstract class CatalogTestBase {

@TempDir protected java.nio.file.Path tempFile;
@TempDir java.nio.file.Path tempFile;
protected String warehouse;
protected FileIO fileIO;
protected Catalog catalog;
Expand Down Expand Up @@ -375,28 +373,6 @@ public void testGetTable() throws Exception {
.withMessage("Table non_existing_db.test_table does not exist.");
}

@Test
public void testNewTableLocation() {
Path path =
AbstractCatalog.newTableLocation(
String.valueOf(tempFile),
Identifier.create("test_db", "test_table$branch_a"));
assertThat(path.toString())
.isEqualTo(
new File(
String.valueOf(tempFile),
"test_db"
+ ".db"
+ File.separator
+ "test_table"
+ File.separator
+ "branch"
+ File.separator
+ BranchManager.BRANCH_PREFIX
+ "a")
.toString());
}

@Test
public void testDropTable() throws Exception {
catalog.createDatabase("test_db", false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,18 @@

package org.apache.paimon.jdbc;

import org.apache.paimon.catalog.AbstractCatalog;
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;
import org.apache.paimon.utils.BranchManager;

import org.apache.paimon.shade.guava30.com.google.common.collect.Maps;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.ObjectOutputStream;
import java.sql.SQLException;
import java.util.Map;
Expand Down Expand Up @@ -126,25 +122,4 @@ public void testSerializeTable() throws Exception {
}
});
}

@Test
public void testGetDataTableLocation() {
Path path =
((AbstractCatalog) catalog)
.getDataTableLocation(Identifier.create("test_db", "test_table$branch_a1"));
assertThat(path.toString())
.isEqualTo(
new File(
"file:/" + tempFile,
"test_db"
+ ".db"
+ File.separator
+ "test_table"
+ File.separator
+ "branch"
+ File.separator
+ BranchManager.BRANCH_PREFIX
+ "a1")
.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public void testBranchNotExist() throws Exception {
// call the FileSystemCatalog.getDataTableSchema() function
assertThatThrownBy(() -> paimonTable("T$branch_branch2"))
.isInstanceOf(Catalog.TableNotExistException.class)
.hasMessage("Branch %s does not exist.", "default.T$branch_branch2");
.hasMessage("Table %s does not exist.", "default.T$branch_branch2");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,13 @@ class AlterBranchProcedureTest extends PaimonSparkTestBase with StreamTest {
val table = loadTable("T")
val branchManager = table.branchManager()

// create branch with snapshot
// create branch with tag
checkAnswer(
spark.sql("CALL paimon.sys.create_tag(table => 'test.T', tag => 's_2', snapshot => 2)"),
Row(true) :: Nil)
checkAnswer(
spark.sql(
"CALL paimon.sys.create_branch(table => 'test.T', branch => 'snapshot_branch', snapshot => 2)"),
"CALL paimon.sys.create_branch(table => 'test.T', branch => 'snapshot_branch', tag => 's_2')"),
Row(true) :: Nil)
assert(branchManager.branchExists("snapshot_branch"))

Expand Down

0 comments on commit b9f632a

Please sign in to comment.