Skip to content

Commit 6fdf1a9

Browse files
committed
[core] Introduce paimon-api module for light rest api, part 3
1 parent c29b162 commit 6fdf1a9

File tree

24 files changed

+854
-530
lines changed

24 files changed

+854
-530
lines changed

docs/content/concepts/rest/overview.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,11 @@ RESTCatalog supports multiple access authentication methods, including the follo
6262

6363
1. [Bear Token]({{< ref "concepts/rest/bear" >}}).
6464
2. [DLF Token]({{< ref "concepts/rest/dlf" >}}).
65+
66+
## REST Open API
67+
68+
See [REST API]({{< ref "concepts/rest/rest-api" >}}).
69+
70+
## REST Java API
71+
72+
See [REST Java API]({{< ref "program-api/rest-api" >}}).

docs/content/program-api/catalog-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "Catalog API"
3-
weight: 3
3+
weight: 4
44
type: docs
55
aliases:
66
- /api/catalog-api.html

docs/content/program-api/flink-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "Flink API"
3-
weight: 1
3+
weight: 2
44
type: docs
55
aliases:
66
- /api/flink-api.html

docs/content/program-api/java-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "Java API"
3-
weight: 2
3+
weight: 3
44
type: docs
55
aliases:
66
- /api/java-api.html

docs/content/program-api/python-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "Python API"
3-
weight: 4
3+
weight: 5
44
type: docs
55
aliases:
66
- /api/python-api.html
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
title: "REST API"
3+
weight: 1
4+
type: docs
5+
aliases:
6+
- /api/rest-api.html
7+
---
8+
<!--
9+
Licensed to the Apache Software Foundation (ASF) under one
10+
or more contributor license agreements. See the NOTICE file
11+
distributed with this work for additional information
12+
regarding copyright ownership. The ASF licenses this file
13+
to you under the Apache License, Version 2.0 (the
14+
"License"); you may not use this file except in compliance
15+
with the License. You may obtain a copy of the License at
16+
17+
http://www.apache.org/licenses/LICENSE-2.0
18+
19+
Unless required by applicable law or agreed to in writing,
20+
software distributed under the License is distributed on an
21+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
22+
KIND, either express or implied. See the License for the
23+
specific language governing permissions and limitations
24+
under the License.
25+
-->
26+
27+
# REST API
28+
29+
This is Java API for [REST]({{< ref "concepts/rest/overview" >}}).
30+
31+
## Dependency
32+
33+
Maven dependency:
34+
35+
```xml
36+
<dependency>
37+
<groupId>org.apache.paimon</groupId>
38+
<artifactId>paimon-api</artifactId>
39+
<version>{{< version >}}</version>
40+
</dependency>
41+
```
42+
43+
Or download the jar file:
44+
{{< stable >}}[Paimon API](https://repo.maven.apache.org/maven2/org/apache/paimon/paimon-api/{{< version >}}/paimon-api-{{< version >}}.jar).{{< /stable >}}
45+
{{< unstable >}}[Paimon API](https://repository.apache.org/snapshots/org/apache/paimon/paimon-api/{{< version >}}/).{{< /unstable >}}
46+
47+
## RESTApi
48+
49+
```java
50+
import org.apache.paimon.options.Options;
51+
import org.apache.paimon.rest.RESTApi;
52+
53+
import java.util.List;
54+
55+
import static org.apache.paimon.options.CatalogOptions.WAREHOUSE;
56+
import static org.apache.paimon.rest.RESTCatalogOptions.DLF_ACCESS_KEY_ID;
57+
import static org.apache.paimon.rest.RESTCatalogOptions.DLF_ACCESS_KEY_SECRET;
58+
import static org.apache.paimon.rest.RESTCatalogOptions.TOKEN_PROVIDER;
59+
import static org.apache.paimon.rest.RESTCatalogOptions.URI;
60+
61+
public class RESTApiExample {
62+
63+
public static void main(String[] args) {
64+
Options options = new Options();
65+
options.set(URI, "<catalog server url>");
66+
options.set(WAREHOUSE, "my_instance_name");
67+
options.set(TOKEN_PROVIDER, "dlf");
68+
options.set(DLF_ACCESS_KEY_ID, "<access-key-id>");
69+
options.set(DLF_ACCESS_KEY_SECRET, "<access-key-secret>");
70+
71+
RESTApi api = new RESTApi(options);
72+
List<String> tables = api.listTables("my_database");
73+
System.out.println(tables);
74+
}
75+
}
76+
```
77+
78+
See more methods in `'RESTApi'`.

paimon-api/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## Paimon API
22

3-
This module is for light API, aims to simplify dependencies as much as possible and avoid
3+
This module is for light SDK, aims to simplify dependencies as much as possible and avoid
44
introducing dependencies such as Hadoop, including:
55

6-
1. Including types, table, view, function and etc.
7-
2. Including http client REST API.
6+
1. Including types, table, view, function etc.
7+
2. Including http client REST API, See `'RESTApi'`.

paimon-common/src/main/java/org/apache/paimon/PagedList.java renamed to paimon-api/src/main/java/org/apache/paimon/PagedList.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
* @since 1.1.0
2929
*/
3030
public class PagedList<T> {
31+
3132
private final List<T> elements;
3233

3334
@Nullable private final String nextPageToken;

paimon-api/src/main/java/org/apache/paimon/rest/HttpClient.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import static okhttp3.ConnectionSpec.MODERN_TLS;
4848
import static org.apache.paimon.rest.LoggingInterceptor.DEFAULT_REQUEST_ID;
4949
import static org.apache.paimon.rest.LoggingInterceptor.REQUEST_ID_KEY;
50-
import static org.apache.paimon.rest.RESTObjectMapper.OBJECT_MAPPER;
5150

5251
/** HTTP client for REST catalog. */
5352
public class HttpClient implements RESTClient {
@@ -125,7 +124,7 @@ public <T extends RESTResponse> T post(
125124
Class<T> responseType,
126125
RESTAuthFunction restAuthFunction) {
127126
try {
128-
String bodyStr = OBJECT_MAPPER.writeValueAsString(body);
127+
String bodyStr = RESTApi.toJson(body);
129128
Map<String, String> authHeaders = getHeaders(path, "POST", bodyStr, restAuthFunction);
130129
RequestBody requestBody = buildRequestBody(bodyStr);
131130
Request request =
@@ -156,7 +155,7 @@ public <T extends RESTResponse> T delete(String path, RESTAuthFunction restAuthF
156155
public <T extends RESTResponse> T delete(
157156
String path, RESTRequest body, RESTAuthFunction restAuthFunction) {
158157
try {
159-
String bodyStr = OBJECT_MAPPER.writeValueAsString(body);
158+
String bodyStr = RESTApi.toJson(body);
160159
Map<String, String> authHeaders = getHeaders(path, "DELETE", bodyStr, restAuthFunction);
161160
RequestBody requestBody = buildRequestBody(bodyStr);
162161
Request request =
@@ -190,7 +189,7 @@ private <T extends RESTResponse> T exec(Request request, Class<T> responseType)
190189
if (!response.isSuccessful()) {
191190
ErrorResponse error;
192191
try {
193-
error = OBJECT_MAPPER.readValue(responseBodyStr, ErrorResponse.class);
192+
error = RESTApi.fromJson(responseBodyStr, ErrorResponse.class);
194193
} catch (JsonProcessingException e) {
195194
error =
196195
new ErrorResponse(
@@ -205,7 +204,7 @@ private <T extends RESTResponse> T exec(Request request, Class<T> responseType)
205204
errorHandler.accept(error, requestId);
206205
}
207206
if (responseType != null && responseBodyStr != null) {
208-
return OBJECT_MAPPER.readValue(responseBodyStr, responseType);
207+
return RESTApi.fromJson(responseBodyStr, responseType);
209208
} else if (responseType == null) {
210209
return null;
211210
} else {

0 commit comments

Comments
 (0)