Skip to content

Commit

Permalink
fix query schema when specifying schema_id does not exist throw excep…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
herefree committed Sep 3, 2024
1 parent e69a664 commit e8261d5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,19 @@ public TableSchema schema(long id) {
}
}

/** 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,12 @@ public RecordReader<InternalRow> createReader(Split split) {
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ public void testSchemasTable() {
+ "{\"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
Expand Down

0 comments on commit e8261d5

Please sign in to comment.