Skip to content

Commit d16f223

Browse files
author
xiaohongbo
committed
just ignore NotImplementedException to avoid failure caused by external paimon table
1 parent f489968 commit d16f223

File tree

3 files changed

+86
-47
lines changed

3 files changed

+86
-47
lines changed

paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,9 +1019,11 @@ private Schema inferSchemaIfExternalPaimonTable(Schema schema) throws Exception
10191019
schemaManager.createTable(schema, true);
10201020
Schema existsSchema = latest.get().toSchema();
10211021
// use `owner` and `path` from the user provide schema
1022-
existsSchema
1023-
.options()
1024-
.put(Catalog.OWNER_PROP, schema.options().get(Catalog.OWNER_PROP));
1022+
if (Objects.nonNull(schema.options().get(Catalog.OWNER_PROP))) {
1023+
existsSchema
1024+
.options()
1025+
.put(Catalog.OWNER_PROP, schema.options().get(Catalog.OWNER_PROP));
1026+
}
10251027
existsSchema.options().put(PATH.key(), schema.options().get(PATH.key()));
10261028
return existsSchema;
10271029
}

paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2258,7 +2258,7 @@ private TableMetadata createTableMetadata(
22582258
Identifier identifier, long schemaId, Schema schema, String uuid, boolean isExternal) {
22592259
Map<String, String> options = new HashMap<>(schema.options());
22602260
Path path =
2261-
isExternal
2261+
isExternal && Objects.nonNull(schema.options().get(PATH.key()))
22622262
? new Path(schema.options().get(PATH.key()))
22632263
: catalog.getTableLocation(identifier);
22642264
String restPath = path.toString();

paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogTest.java

Lines changed: 80 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package org.apache.paimon.rest;
2020

21+
import org.apache.paimon.CoreOptions;
2122
import org.apache.paimon.PagedList;
2223
import org.apache.paimon.Snapshot;
2324
import org.apache.paimon.TableType;
@@ -2686,66 +2687,102 @@ public void testCreateExternalTable(@TempDir java.nio.file.Path path) throws Exc
26862687
Table tableAgain = catalog.getTable(identifier);
26872688
assertThat(tableAgain).isNotNull();
26882689
assertThat(tableAgain.comment()).isEqualTo(Optional.of("External table for testing"));
2690+
}
2691+
2692+
@Test
2693+
public void testCreateExternalTableWithSchemaInference(@TempDir java.nio.file.Path path)
2694+
throws Exception {
2695+
Path externalTablePath = new Path(path.toString(), "external_table_inference_location");
2696+
DEFAULT_TABLE_SCHEMA.options().put(CoreOptions.PATH.key(), externalTablePath.toString());
2697+
restCatalog.createDatabase("test_schema_inference_db", true);
2698+
Identifier identifier =
2699+
Identifier.create("test_schema_inference_db", "external_inference_table");
2700+
try {
2701+
catalog.dropTable(identifier, true);
2702+
} catch (Exception e) {
2703+
// Ignore drop errors
2704+
}
2705+
2706+
createExternalTableDirectory(externalTablePath, DEFAULT_TABLE_SCHEMA);
2707+
Schema emptySchema =
2708+
new Schema(
2709+
Lists.newArrayList(),
2710+
Collections.emptyList(),
2711+
Collections.emptyList(),
2712+
DEFAULT_TABLE_SCHEMA.options(),
2713+
"");
2714+
catalog.createTable(identifier, emptySchema, false);
26892715

2690-
testReadSystemTables();
2716+
Table table = catalog.getTable(identifier);
2717+
assertThat(table).isNotNull();
2718+
assertThat(table.rowType().getFieldCount()).isEqualTo(3);
2719+
assertThat(table.rowType().getFieldNames()).containsExactly("pk", "col1", "col2");
26912720

2692-
// Verify external table path still exists after operations
2693-
assertTrue(
2694-
fileIO.exists(externalTablePath),
2695-
"External table path should still exist after operations");
2721+
Schema clientProvidedSchema =
2722+
new Schema(
2723+
Lists.newArrayList(
2724+
new DataField(0, "pk", DataTypes.INT()),
2725+
new DataField(1, "col1", DataTypes.STRING())),
2726+
Collections.emptyList(),
2727+
Collections.emptyList(),
2728+
DEFAULT_TABLE_SCHEMA.options(),
2729+
"");
2730+
// schema mismatch should throw an exception
2731+
Assertions.assertThrows(
2732+
RuntimeException.class,
2733+
() -> catalog.createTable(identifier, clientProvidedSchema, false));
2734+
DEFAULT_TABLE_SCHEMA.options().remove(CoreOptions.PATH.key());
2735+
}
26962736

2697-
// Test dropping external table - data should remain
2698-
catalog.dropTable(identifier, false);
2737+
@Test
2738+
public void testReadSystemTablesWithExternalTable(@TempDir java.nio.file.Path path)
2739+
throws Exception {
2740+
// Create an external table
2741+
Path externalTablePath = new Path(path.toString(), "external_sys_table_location");
2742+
DEFAULT_TABLE_SCHEMA.options().put(CoreOptions.PATH.key(), externalTablePath.toString());
26992743

2700-
// Verify external table path still exists after drop (external table behavior)
2701-
assertTrue(
2702-
fileIO.exists(externalTablePath),
2703-
"External table path should still exist after drop");
2744+
restCatalog.createDatabase("test_sys_table_db", true);
2745+
Identifier identifier = Identifier.create("test_sys_table_db", "external_sys_table");
27042746

2705-
// Clean up
27062747
try {
2707-
fileIO.deleteQuietly(externalTablePath);
2748+
catalog.dropTable(identifier, true);
27082749
} catch (Exception e) {
2709-
// Ignore cleanup errors
2750+
// Ignore drop errors
27102751
}
2711-
}
27122752

2713-
private void testReadSystemTables() throws IOException, Catalog.TableNotExistException {
2753+
createExternalTableDirectory(externalTablePath, DEFAULT_TABLE_SCHEMA);
2754+
catalog.createTable(identifier, DEFAULT_TABLE_SCHEMA, false);
2755+
2756+
// Test reading system table with external table
27142757
Identifier allTablesIdentifier = Identifier.create("sys", "tables");
27152758
Table allTablesTable = catalog.getTable(allTablesIdentifier);
2759+
assertThat(allTablesTable).isNotNull();
27162760

2717-
if (allTablesTable != null) {
2718-
ReadBuilder allTablesReadBuilder = allTablesTable.newReadBuilder();
2719-
TableRead allTablesRead = allTablesReadBuilder.newRead();
2720-
List<Split> allTablesSplits = allTablesReadBuilder.newScan().plan().splits();
2761+
ReadBuilder readBuilder = allTablesTable.newReadBuilder();
2762+
TableRead read = readBuilder.newRead();
2763+
List<Split> splits = readBuilder.newScan().plan().splits();
27212764

2722-
List<InternalRow> allTablesResults = new ArrayList<>();
2723-
for (Split split : allTablesSplits) {
2724-
try (RecordReader<InternalRow> reader = allTablesRead.createReader(split)) {
2725-
reader.forEachRemaining(allTablesResults::add);
2726-
}
2765+
List<InternalRow> results = new ArrayList<>();
2766+
for (Split split : splits) {
2767+
try (RecordReader<InternalRow> reader = read.createReader(split)) {
2768+
reader.forEachRemaining(results::add);
27272769
}
2770+
}
27282771

2729-
// Verify that our external table appears in ALL_TABLES
2730-
assertThat(allTablesResults).isNotEmpty();
2731-
2732-
// Find our external table in the results
2733-
boolean foundExternalTable = false;
2734-
for (InternalRow row : allTablesResults) {
2735-
String tableName = row.getString(1).toString(); // table_name column
2736-
String databaseName = row.getString(0).toString(); // database_name column
2737-
if ("external_test_table".equals(tableName)
2738-
&& "test_external_table_db".equals(databaseName)) {
2739-
foundExternalTable = true;
2740-
// Verify table properties
2741-
String tableType = row.getString(2).toString(); // table_type column
2742-
assertThat(tableType)
2743-
.isEqualTo("table"); // External tables are still MANAGED type
2744-
break;
2745-
}
2772+
// Verify external table appears in system table
2773+
assertThat(results).isNotEmpty();
2774+
boolean foundExternalTable = false;
2775+
for (InternalRow row : results) {
2776+
String databaseName = row.getString(0).toString();
2777+
String tableName = row.getString(1).toString();
2778+
if ("test_sys_table_db".equals(databaseName)
2779+
&& "external_sys_table".equals(tableName)) {
2780+
foundExternalTable = true;
2781+
break;
27462782
}
2747-
assertThat(foundExternalTable).isTrue();
27482783
}
2784+
assertThat(foundExternalTable).isTrue();
2785+
DEFAULT_TABLE_SCHEMA.options().remove(CoreOptions.PATH.key());
27492786
}
27502787

27512788
protected void createTable(

0 commit comments

Comments
 (0)