Skip to content

Commit 89bf668

Browse files
committed
[rest] Add path and other options to Table Options
1 parent a5dc3ef commit 89bf668

File tree

9 files changed

+74
-35
lines changed

9 files changed

+74
-35
lines changed

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
import java.io.UncheckedIOException;
9494
import java.util.ArrayList;
9595
import java.util.Collections;
96+
import java.util.HashMap;
9697
import java.util.List;
9798
import java.util.Map;
9899
import java.util.Objects;
@@ -103,6 +104,9 @@
103104
import java.util.stream.Collectors;
104105

105106
import static java.util.Collections.emptyList;
107+
import static org.apache.paimon.CoreOptions.BRANCH;
108+
import static org.apache.paimon.CoreOptions.PATH;
109+
import static org.apache.paimon.catalog.Catalog.DB_LOCATION_PROP;
106110
import static org.apache.paimon.catalog.CatalogUtils.checkNotBranch;
107111
import static org.apache.paimon.catalog.CatalogUtils.checkNotSystemDatabase;
108112
import static org.apache.paimon.catalog.CatalogUtils.checkNotSystemTable;
@@ -229,8 +233,10 @@ public Database getDatabase(String name) throws DatabaseNotExistException {
229233
resourcePaths.database(name),
230234
GetDatabaseResponse.class,
231235
restAuthFunction);
232-
return new Database.DatabaseImpl(
233-
name, response.options(), response.comment().orElse(null));
236+
Map<String, String> options = new HashMap<>(response.getOptions());
237+
options.put(DB_LOCATION_PROP, response.getLocation());
238+
response.putAllTo(options);
239+
return new Database.DatabaseImpl(name, options, options.get(COMMENT_PROP));
234240
} catch (NoSuchResourceException e) {
235241
throw new DatabaseNotExistException(name);
236242
} catch (ForbiddenException e) {
@@ -451,12 +457,19 @@ private TableMetadata loadTableMetadata(Identifier identifier) throws TableNotEx
451457
throw new TableNoPermissionException(identifier, e);
452458
}
453459

454-
return toTableMetadata(response);
460+
return toTableMetadata(identifier.getDatabaseName(), response);
455461
}
456462

457-
private TableMetadata toTableMetadata(GetTableResponse response) {
463+
private TableMetadata toTableMetadata(String db, GetTableResponse response) {
458464
TableSchema schema = TableSchema.create(response.getSchemaId(), response.getSchema());
459-
return new TableMetadata(schema, response.isExternal(), response.getId());
465+
Map<String, String> options = new HashMap<>(schema.options());
466+
options.put(PATH.key(), response.getPath());
467+
response.putAllTo(options);
468+
Identifier identifier = Identifier.create(db, response.getName());
469+
if (identifier.getBranchName() != null) {
470+
options.put(BRANCH.key(), identifier.getBranchName());
471+
}
472+
return new TableMetadata(schema.copy(options), response.isExternal(), response.getId());
460473
}
461474

462475
private Table toTable(String db, GetTableResponse response) {
@@ -467,7 +480,7 @@ private Table toTable(String db, GetTableResponse response) {
467480
identifier,
468481
path -> fileIOForData(path, identifier),
469482
this::fileIOFromOptions,
470-
i -> toTableMetadata(response),
483+
i -> toTableMetadata(db, response),
471484
null,
472485
null);
473486
} catch (TableNotExistException e) {

paimon-core/src/main/java/org/apache/paimon/rest/responses/BaseResourceAuditResponse.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@
2424
import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonGetter;
2525
import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonProperty;
2626

27-
/** Base class for database, table, view, audit response. */
27+
import java.util.Map;
28+
29+
/** Base class for database, table, view, audit */
2830
public abstract class BaseResourceAuditResponse implements RESTResponse {
29-
protected static final String FIELD_OWNER = "owner";
30-
protected static final String FIELD_CREATED_AT = "createdAt";
31-
protected static final String FIELD_CREATED_BY = "createdBy";
32-
protected static final String FIELD_UPDATED_AT = "updatedAt";
33-
protected static final String FIELD_UPDATED_BY = "updatedBy";
31+
32+
public static final String FIELD_OWNER = "owner";
33+
public static final String FIELD_CREATED_AT = "createdAt";
34+
public static final String FIELD_CREATED_BY = "createdBy";
35+
public static final String FIELD_UPDATED_AT = "updatedAt";
36+
public static final String FIELD_UPDATED_BY = "updatedBy";
3437

3538
@JsonProperty(FIELD_OWNER)
3639
private final String owner;
@@ -85,4 +88,12 @@ public long getUpdatedAt() {
8588
public String getUpdatedBy() {
8689
return updatedBy;
8790
}
91+
92+
public void putAllTo(Map<String, String> options) {
93+
options.put(FIELD_OWNER, getOwner());
94+
options.put(FIELD_CREATED_BY, String.valueOf(getCreatedBy()));
95+
options.put(FIELD_CREATED_AT, String.valueOf(getCreatedAt()));
96+
options.put(FIELD_UPDATED_BY, String.valueOf(getUpdatedBy()));
97+
options.put(FIELD_UPDATED_AT, String.valueOf(getUpdatedAt()));
98+
}
8899
}

paimon-core/src/main/java/org/apache/paimon/rest/responses/GetDatabaseResponse.java

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

1919
package org.apache.paimon.rest.responses;
2020

21-
import org.apache.paimon.catalog.Database;
2221
import org.apache.paimon.rest.RESTResponse;
2322

2423
import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonCreator;
@@ -27,17 +26,14 @@
2726
import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonProperty;
2827

2928
import java.util.Map;
30-
import java.util.Optional;
31-
32-
import static org.apache.paimon.catalog.Catalog.COMMENT_PROP;
3329

3430
/** Response for getting database. */
3531
@JsonIgnoreProperties(ignoreUnknown = true)
36-
public class GetDatabaseResponse extends BaseResourceAuditResponse
37-
implements RESTResponse, Database {
32+
public class GetDatabaseResponse extends BaseResourceAuditResponse implements RESTResponse {
3833

3934
private static final String FIELD_ID = "id";
4035
private static final String FIELD_NAME = "name";
36+
private static final String FIELD_LOCATION = "location";
4137
private static final String FIELD_OPTIONS = "options";
4238

4339
@JsonProperty(FIELD_ID)
@@ -46,13 +42,17 @@ public class GetDatabaseResponse extends BaseResourceAuditResponse
4642
@JsonProperty(FIELD_NAME)
4743
private final String name;
4844

45+
@JsonProperty(FIELD_LOCATION)
46+
private final String location;
47+
4948
@JsonProperty(FIELD_OPTIONS)
5049
private final Map<String, String> options;
5150

5251
@JsonCreator
5352
public GetDatabaseResponse(
5453
@JsonProperty(FIELD_ID) String id,
5554
@JsonProperty(FIELD_NAME) String name,
55+
@JsonProperty(FIELD_LOCATION) String location,
5656
@JsonProperty(FIELD_OPTIONS) Map<String, String> options,
5757
@JsonProperty(FIELD_OWNER) String owner,
5858
@JsonProperty(FIELD_CREATED_AT) long createdAt,
@@ -62,6 +62,7 @@ public GetDatabaseResponse(
6262
super(owner, createdAt, createdBy, updatedAt, updatedBy);
6363
this.id = id;
6464
this.name = name;
65+
this.location = location;
6566
this.options = options;
6667
}
6768

@@ -75,23 +76,13 @@ public String getName() {
7576
return name;
7677
}
7778

79+
@JsonGetter(FIELD_LOCATION)
80+
public String getLocation() {
81+
return location;
82+
}
83+
7884
@JsonGetter(FIELD_OPTIONS)
7985
public Map<String, String> getOptions() {
8086
return options;
8187
}
82-
83-
@Override
84-
public String name() {
85-
return getName();
86-
}
87-
88-
@Override
89-
public Map<String, String> options() {
90-
return getOptions();
91-
}
92-
93-
@Override
94-
public Optional<String> comment() {
95-
return Optional.ofNullable(options.get(COMMENT_PROP));
96-
}
9788
}

paimon-core/src/main/java/org/apache/paimon/rest/responses/GetTableResponse.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class GetTableResponse extends BaseResourceAuditResponse implements RESTR
3232

3333
private static final String FIELD_ID = "id";
3434
private static final String FIELD_NAME = "name";
35+
private static final String FIELD_PATH = "path";
3536
private static final String FIELD_IS_EXTERNAL = "isExternal";
3637
private static final String FIELD_SCHEMA_ID = "schemaId";
3738
private static final String FIELD_SCHEMA = "schema";
@@ -42,6 +43,9 @@ public class GetTableResponse extends BaseResourceAuditResponse implements RESTR
4243
@JsonProperty(FIELD_NAME)
4344
private final String name;
4445

46+
@JsonProperty(FIELD_PATH)
47+
private final String path;
48+
4549
@JsonProperty(FIELD_IS_EXTERNAL)
4650
private final boolean isExternal;
4751

@@ -55,6 +59,7 @@ public class GetTableResponse extends BaseResourceAuditResponse implements RESTR
5559
public GetTableResponse(
5660
@JsonProperty(FIELD_ID) String id,
5761
@JsonProperty(FIELD_NAME) String name,
62+
@JsonProperty(FIELD_PATH) String path,
5863
@JsonProperty(FIELD_IS_EXTERNAL) boolean isExternal,
5964
@JsonProperty(FIELD_SCHEMA_ID) long schemaId,
6065
@JsonProperty(FIELD_SCHEMA) Schema schema,
@@ -66,6 +71,7 @@ public GetTableResponse(
6671
super(owner, createdAt, createdBy, updatedAt, updatedBy);
6772
this.id = id;
6873
this.name = name;
74+
this.path = path;
6975
this.isExternal = isExternal;
7076
this.schemaId = schemaId;
7177
this.schema = schema;
@@ -81,6 +87,11 @@ public String getName() {
8187
return this.name;
8288
}
8389

90+
@JsonGetter(FIELD_PATH)
91+
public String getPath() {
92+
return this.path;
93+
}
94+
8495
@JsonGetter(FIELD_IS_EXTERNAL)
8596
public boolean isExternal() {
8697
return isExternal;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public static GetDatabaseResponse getDatabaseResponse(String name) {
8080
return new GetDatabaseResponse(
8181
UUID.randomUUID().toString(),
8282
name,
83+
"/tmp/",
8384
options,
8485
"owner",
8586
System.currentTimeMillis(),
@@ -225,6 +226,7 @@ public static GetTableResponse getTableResponse() {
225226
return new GetTableResponse(
226227
UUID.randomUUID().toString(),
227228
"",
229+
"/tmp/",
228230
false,
229231
1,
230232
schema(options),

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,7 @@ private MockResponse databaseHandle(String method, String data, String databaseN
744744
new GetDatabaseResponse(
745745
UUID.randomUUID().toString(),
746746
database.name(),
747+
"/tmp",
747748
database.options(),
748749
"owner",
749750
1L,
@@ -918,6 +919,7 @@ private List<GetTableResponse> listTableDetails(String databaseName) {
918919
new GetTableResponse(
919920
entry.getValue().uuid(),
920921
identifier.getTableName(),
922+
entry.getValue().schema().options().get(PATH.key()),
921923
entry.getValue().isExternal(),
922924
entry.getValue().schema().id(),
923925
entry.getValue().schema().toSchema(),
@@ -953,13 +955,16 @@ private MockResponse tableHandle(String method, String data, Identifier identifi
953955
} else {
954956
tableMetadata = tableMetadataStore.get(identifier.getFullName());
955957
}
958+
Schema schema = tableMetadata.schema().toSchema();
959+
String path = schema.options().remove(PATH.key());
956960
response =
957961
new GetTableResponse(
958962
tableMetadata.uuid(),
959963
identifier.getTableName(),
964+
path,
960965
tableMetadata.isExternal(),
961966
tableMetadata.schema().id(),
962-
tableMetadata.schema().toSchema(),
967+
schema,
963968
"owner",
964969
1L,
965970
"created",

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ public void getDatabaseResponseParseTest() throws Exception {
9595
OBJECT_MAPPER.readValue(responseStr, GetDatabaseResponse.class);
9696
assertEquals(name, parseData.getName());
9797
assertEquals(response.getOptions().size(), parseData.getOptions().size());
98-
assertEquals(response.comment().get(), parseData.comment().get());
9998
}
10099

101100
@Test

paimon-open-api/rest-catalog-open-api.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,6 +1638,8 @@ components:
16381638
type: string
16391639
name:
16401640
type: string
1641+
path:
1642+
type: string
16411643
isExternal:
16421644
type: boolean
16431645
schemaId:
@@ -1965,6 +1967,8 @@ components:
19651967
type: string
19661968
name:
19671969
type: string
1970+
location:
1971+
type: string
19681972
options:
19691973
type: object
19701974
additionalProperties:

paimon-open-api/src/main/java/org/apache/paimon/open/api/RESTCatalogController.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ public GetDatabaseResponse getDatabases(
176176
return new GetDatabaseResponse(
177177
UUID.randomUUID().toString(),
178178
"name",
179+
"/tmp/",
179180
options,
180181
"owner",
181182
System.currentTimeMillis(),
@@ -293,6 +294,7 @@ public ListTableDetailsResponse listTableDetails(
293294
new GetTableResponse(
294295
UUID.randomUUID().toString(),
295296
"",
297+
"/tmp/",
296298
false,
297299
1,
298300
new org.apache.paimon.schema.Schema(
@@ -340,6 +342,7 @@ public GetTableResponse getTable(
340342
return new GetTableResponse(
341343
UUID.randomUUID().toString(),
342344
"",
345+
"/tmp/",
343346
false,
344347
1,
345348
new org.apache.paimon.schema.Schema(

0 commit comments

Comments
 (0)