tsreaper commented on code in PR #3820:
URL: https://github.com/apache/paimon/pull/3820#discussion_r1694896505
##########
paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/HiveCatalog.java:
##########
@@ -404,8 +405,23 @@ private static boolean isPaimonTable(Table table) {
@Override
public TableSchema getDataTableSchema(Identifier identifier, String
branchName)
throws TableNotExistException {
- assertMainBranch(branchName);
- return getDataTableSchema(identifier);
+ if (!tableExists(identifier)) {
+ throw new TableNotExistException(identifier);
+ }
+ if (branchName.equals(DEFAULT_MAIN_BRANCH)) {
+ return getDataTableSchema(identifier);
+ } else {
+ Path tableLocation = getDataTableLocation(identifier);
+ return new SchemaManager(fileIO, tableLocation, branchName)
+ .latest()
+ .map(
+ s -> {
+ Options branchOptions = new
Options(s.options());
+ branchOptions.set(CoreOptions.BRANCH,
branchName);
+ return s.copy(branchOptions.toMap());
+ })
+ .orElseThrow(() -> new TableNotExistException(identifier));
Review Comment:
Move this into `tableSchemaInFileSystem`, so that it supports reading schema
for branches. `FileSystemCatalog` can also reuse this method.
##########
paimon-hive/paimon-hive-connector-common/src/main/java/org/apache/paimon/hive/HiveSchema.java:
##########
@@ -200,9 +200,15 @@ private static Optional<TableSchema> getExistingSchema(
Path path = new Path(location);
Options options = HiveUtils.extractCatalogConfig(configuration);
options.set(CoreOptions.PATH, location);
+ if (!options.contains(CoreOptions.BRANCH)) {
+ options.set(CoreOptions.BRANCH, "");
+ }
Review Comment:
NIT: Don't set default value here. Use different constructor of
`SchemaManager` below.
##########
paimon-hive/paimon-hive-connector-common/src/test/java/org/apache/paimon/hive/HiveCatalogITCaseBase.java:
##########
@@ -410,6 +410,29 @@ public void testFlinkWriteAndHiveRead() throws Exception {
"Cannot find table '`my_hive`.`test_db`.`hive_table`'
in any of the catalogs [default_catalog, my_hive], nor as a temporary table.");
}
+ @Test
+ public void testFlinkCreateBranchAndHiveRead() throws Exception {
+ tEnv.executeSql(
+ "CREATE TABLE t ( "
+ + "a INT, "
+ + "b STRING"
+ + ") WITH ( 'file.format' = 'avro' )")
+ .await();
+ tEnv.executeSql("Call sys.create_branch('test_db.t','b1')").await();
+ tEnv.executeSql("INSERT INTO t$branch_b1 VALUES (1,'x1'),
(2,'x2')").await();
+ tEnv.executeSql("INSERT INTO t VALUES (3,'x3')").await();
+ hiveShell.execute("SET paimon.branch=b1");
+ assertThat(hiveShell.executeQuery("SELECT * FROM t"))
+ .isEqualTo(Arrays.asList("1\tx1", "2\tx2"));
+
+ tEnv.executeSql("Call sys.create_branch('test_db.t','b2')").await();
+ tEnv.executeSql("INSERT INTO t$branch_b2 VALUES (4,'x1'),
(5,'x2')").await();
+ hiveShell.execute("SET paimon.branch=b2");
+ assertThat(hiveShell.executeQuery("SELECT * FROM t"))
+ .isEqualTo(Arrays.asList("4\tx1", "5\tx2"));
+ hiveShell.execute("SET paimon.branch=null");
Review Comment:
Test that after setting branch to null, we can read from default branch.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]