This is an automated email from the ASF dual-hosted git repository.
lzljs3620320 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git
The following commit(s) were added to refs/heads/master by this push:
new 8f01efeef [core] fix query schema throw exception when specifying
schema_id does not exist (#4117)
8f01efeef is described below
commit 8f01efeef34ef90d00d3a531b1888bf9a4272640
Author: herefree <[email protected]>
AuthorDate: Tue Sep 3 16:59:43 2024 +0800
[core] fix query schema throw exception when specifying schema_id does not
exist (#4117)
---
.../main/java/org/apache/paimon/schema/SchemaManager.java | 13 +++++++++++++
.../java/org/apache/paimon/table/system/SchemasTable.java | 10 ++++++----
.../java/org/apache/paimon/flink/CatalogTableITCase.java | 6 ++++++
3 files changed, 25 insertions(+), 4 deletions(-)
diff --git
a/paimon-core/src/main/java/org/apache/paimon/schema/SchemaManager.java
b/paimon-core/src/main/java/org/apache/paimon/schema/SchemaManager.java
index 5d4adeb40..e164213e2 100644
--- a/paimon-core/src/main/java/org/apache/paimon/schema/SchemaManager.java
+++ b/paimon-core/src/main/java/org/apache/paimon/schema/SchemaManager.java
@@ -554,6 +554,19 @@ public class SchemaManager implements Serializable {
}
}
+ /** Check if a schema exists. */
+ public boolean schemaExists(long id) {
+ Path path = toSchemaPath(id);
+ try {
+ return fileIO.exists(path);
+ } catch (IOException e) {
+ throw new RuntimeException(
+ String.format(
+ "Failed to determine if schema '%s' exists in path
%s.", id, path),
+ e);
+ }
+ }
+
public static TableSchema fromPath(FileIO fileIO, Path path) {
try {
return JsonSerdeUtil.fromJson(fileIO.readFileUtf8(path),
TableSchema.class);
diff --git
a/paimon-core/src/main/java/org/apache/paimon/table/system/SchemasTable.java
b/paimon-core/src/main/java/org/apache/paimon/table/system/SchemasTable.java
index b79b75edd..06a4b726d 100644
--- a/paimon-core/src/main/java/org/apache/paimon/table/system/SchemasTable.java
+++ b/paimon-core/src/main/java/org/apache/paimon/table/system/SchemasTable.java
@@ -225,10 +225,12 @@ public class SchemasTable implements ReadonlyTable {
SchemaManager manager = new SchemaManager(fileIO, location,
branch);
Collection<TableSchema> tableSchemas = Collections.emptyList();
- if (predicate != null && predicate.function() instanceof Equal) {
- Object equalValue = predicate.literals().get(0);
- if (equalValue instanceof Long) {
- tableSchemas =
Collections.singletonList(manager.schema((Long) equalValue));
+ if (predicate != null
+ && predicate.function() instanceof Equal
+ && predicate.literals().get(0) instanceof Long) {
+ Long equalValue = (Long) predicate.literals().get(0);
+ if (manager.schemaExists(equalValue)) {
+ tableSchemas =
Collections.singletonList(manager.schema(equalValue));
}
} else {
tableSchemas = manager.listAll();
diff --git
a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/CatalogTableITCase.java
b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/CatalogTableITCase.java
index 3785c3db8..ff4563004 100644
---
a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/CatalogTableITCase.java
+++
b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/CatalogTableITCase.java
@@ -257,6 +257,12 @@ public class CatalogTableITCase extends CatalogITCaseBase {
+ "{\"id\":1,\"name\":\"b\",\"type\":\"INT\"},"
+
"{\"id\":2,\"name\":\"c\",\"type\":\"STRING\"}], [], [\"a\"], "
+
"{\"a.aa.aaa\":\"val1\",\"b.bb.bbb\":\"val2\"}, ]]");
+
+ result =
+ sql(
+ "SELECT schema_id, fields, partition_keys, "
+ + "primary_keys, options, `comment` FROM
T$schemas where schema_id = 5");
+ assertThat(result.toString()).isEqualTo("[]");
}
@Test