Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .palantir/revapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,12 @@ acceptedBreaks:
- code: "java.field.removedWithConstant"
old: "field org.apache.iceberg.TableProperties.ROW_LINEAGE"
justification: "Removing deprecations for 1.10.0"
- code: "java.method.abstractMethodAdded"
new: "method <T extends org.apache.iceberg.rest.RESTResponse> T org.apache.iceberg.rest.BaseHTTPClient::execute(org.apache.iceberg.rest.HTTPRequest,\
\ java.lang.Class<T>, java.util.function.Consumer<org.apache.iceberg.rest.responses.ErrorResponse>,\
\ java.util.function.Consumer<java.util.Map<java.lang.String, java.lang.String>>,\
\ org.apache.iceberg.rest.ParserContext)"
justification: "Add context aware parsing"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: The Justification here is that no one can depend on this api correct? It's solely owned by the client and no one else can extend or use it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

precisely, I am not aware if there are folks who use this API, i just added here to follow existing pattern and make rev-api happy !

- code: "java.method.removed"
old: "method boolean org.apache.iceberg.TableMetadata::rowLineageEnabled()"
justification: "Removing deprecations for 1.10.0"
Expand Down
32 changes: 32 additions & 0 deletions core/src/main/java/org/apache/iceberg/rest/BaseHTTPClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ public <T extends RESTResponse> T get(
return execute(request, responseType, errorHandler, h -> {});
}

@Override
public <T extends RESTResponse> T get(
String path,
Map<String, String> queryParams,
Class<T> responseType,
Map<String, String> headers,
Consumer<ErrorResponse> errorHandler,
ParserContext parserContext) {
HTTPRequest request = buildRequest(HTTPMethod.GET, path, queryParams, headers, null);
return execute(request, responseType, errorHandler, h -> {}, parserContext);
}

@Override
public <T extends RESTResponse> T post(
String path,
Expand All @@ -100,6 +112,19 @@ public <T extends RESTResponse> T post(
return execute(request, responseType, errorHandler, responseHeaders);
}

@Override
public <T extends RESTResponse> T post(
String path,
RESTRequest body,
Class<T> responseType,
Map<String, String> headers,
Consumer<ErrorResponse> errorHandler,
Consumer<Map<String, String>> responseHeaders,
ParserContext parserContext) {
HTTPRequest request = buildRequest(HTTPMethod.POST, path, null, headers, body);
return execute(request, responseType, errorHandler, responseHeaders, parserContext);
}

@Override
public <T extends RESTResponse> T postForm(
String path,
Expand All @@ -123,4 +148,11 @@ protected abstract <T extends RESTResponse> T execute(
Class<T> responseType,
Consumer<ErrorResponse> errorHandler,
Consumer<Map<String, String>> responseHeaders);

protected abstract <T extends RESTResponse> T execute(
HTTPRequest request,
Class<T> responseType,
Consumer<ErrorResponse> errorHandler,
Consumer<Map<String, String>> responseHeaders,
ParserContext parserContext);
}
20 changes: 19 additions & 1 deletion core/src/main/java/org/apache/iceberg/rest/HTTPClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import org.apache.hc.client5.http.auth.AuthScope;
Expand Down Expand Up @@ -101,6 +103,7 @@ public class HTTPClient extends BaseHTTPClient {
private final ObjectMapper mapper;
private final AuthSession authSession;
private final boolean isRootClient;
private final ConcurrentMap<Class<?>, ObjectReader> objectReaderCache = Maps.newConcurrentMap();

Comment on lines +106 to 107
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Until initializing the object reader(s) is known to be a bottleneck, I think I'd prefer to not introduce this cache. I haven't gone so deep into the jackson implementation but I'd be kind of surprised if it wasn't already doing this under the hood

Copy link
Contributor Author

@singhpk234 singhpk234 Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, i was on the same boat as i expected Jackson to cache the reader by Type, turns out it doesn't, what jackson does cache is :

  • Deserializers, serializers, type resolvers, etc. — these are cached inside ObjectMapper for performance.
    This means the actual deserialization logic is reused and shared across threads and calls, making repeated deserialization of the same type efficient.

So i proactively went and added a cache for the overall reader so that i can just work with its copy with new injectable, i expect the Cache to be not put memory pressure as we have very limited parsers.
Happy to remove if you feel strongly about it !

private HTTPClient(
URI baseUri,
Expand Down Expand Up @@ -303,6 +306,17 @@ protected <T extends RESTResponse> T execute(
Class<T> responseType,
Consumer<ErrorResponse> errorHandler,
Consumer<Map<String, String>> responseHeaders) {
return execute(
req, responseType, errorHandler, responseHeaders, ParserContext.builder().build());
}

@Override
protected <T extends RESTResponse> T execute(
HTTPRequest req,
Class<T> responseType,
Consumer<ErrorResponse> errorHandler,
Consumer<Map<String, String>> responseHeaders,
ParserContext parserContext) {
HttpUriRequestBase request = new HttpUriRequestBase(req.method().name(), req.requestUri());

req.headers().entries().forEach(e -> request.addHeader(e.name(), e.value()));
Expand Down Expand Up @@ -341,7 +355,11 @@ protected <T extends RESTResponse> T execute(
}

try {
return mapper.readValue(responseBody, responseType);
ObjectReader reader = objectReaderCache.computeIfAbsent(responseType, mapper::readerFor);
if (parserContext != null && !parserContext.isEmpty()) {
reader = reader.with(parserContext.toInjectableValues());
}
return reader.readValue(responseBody);
} catch (JsonProcessingException e) {
throw new RESTException(
e,
Expand Down
64 changes: 64 additions & 0 deletions core/src/main/java/org/apache/iceberg/rest/ParserContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.iceberg.rest;

import com.fasterxml.jackson.databind.InjectableValues;
import java.util.Collections;
import java.util.Map;
import org.apache.hadoop.util.Preconditions;

class ParserContext {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we wrapping InjectableValues? Is there something else we want to add to the interface?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing this is to keep Jackson out of the public interface?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah trying to keep Jackson out of the interface #13191 (comment)


private final Map<String, Object> data;

private ParserContext(Builder builder) {
this.data = Collections.unmodifiableMap(builder.data);
}

public boolean isEmpty() {
return data.isEmpty();
}

public InjectableValues toInjectableValues() {
return new InjectableValues.Std(data);
}

static Builder builder() {
return new Builder();
}

static class Builder {
private Map<String, Object> data;

private Builder() {
this.data = Collections.emptyMap();
}

public Builder add(String key, Object value) {
Preconditions.checkNotNull(key, "Key cannot be null");
Preconditions.checkNotNull(value, "Value cannot be null");
this.data.put(key, value);
return this;
}

public ParserContext build() {
return new ParserContext(this);
}
}
}
27 changes: 27 additions & 0 deletions core/src/main/java/org/apache/iceberg/rest/RESTClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ default <T extends RESTResponse> T get(
return get(path, queryParams, responseType, headers.get(), errorHandler);
}

default <T extends RESTResponse> T get(
String path,
Map<String, String> queryParams,
Class<T> responseType,
Map<String, String> headers,
Consumer<ErrorResponse> errorHandler,
ParserContext parserContext) {
if (parserContext != null) {
throw new UnsupportedOperationException("Parser context is not supported");
}
return get(path, queryParams, responseType, headers, errorHandler);
}

<T extends RESTResponse> T get(
String path,
Map<String, String> queryParams,
Expand All @@ -123,6 +136,20 @@ default <T extends RESTResponse> T post(
return post(path, body, responseType, headers.get(), errorHandler, responseHeaders);
}

default <T extends RESTResponse> T post(
String path,
RESTRequest body,
Class<T> responseType,
Map<String, String> headers,
Consumer<ErrorResponse> errorHandler,
Consumer<Map<String, String>> responseHeaders,
ParserContext parserContext) {
if (parserContext != null) {
throw new UnsupportedOperationException("Parser context is not supported");
}
return post(path, body, responseType, headers, errorHandler, responseHeaders);
}

default <T extends RESTResponse> T post(
String path,
RESTRequest body,
Expand Down
11 changes: 11 additions & 0 deletions core/src/test/java/org/apache/iceberg/rest/RESTCatalogAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,17 @@ protected <T extends RESTResponse> T execute(
Class<T> responseType,
Consumer<ErrorResponse> errorHandler,
Consumer<Map<String, String>> responseHeaders) {
return execute(
request, responseType, errorHandler, responseHeaders, ParserContext.builder().build());
}

@Override
protected <T extends RESTResponse> T execute(
HTTPRequest request,
Class<T> responseType,
Consumer<ErrorResponse> errorHandler,
Consumer<Map<String, String>> responseHeaders,
ParserContext parserContext) {
ErrorResponse.Builder errorBuilder = ErrorResponse.builder();
Pair<Route, Map<String, String>> routeAndVars = Route.from(request.method(), request.path());
if (routeAndVars != null) {
Expand Down