Skip to content
Open
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
73 changes: 72 additions & 1 deletion core/src/main/java/org/apache/iceberg/rest/RESTSerializers.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,24 @@
import org.apache.iceberg.catalog.TableIdentifier;
import org.apache.iceberg.catalog.TableIdentifierParser;
import org.apache.iceberg.rest.auth.OAuth2Util;
import org.apache.iceberg.rest.events.Event;
import org.apache.iceberg.rest.events.EventParser;
import org.apache.iceberg.rest.requests.CommitTransactionRequest;
import org.apache.iceberg.rest.requests.CommitTransactionRequestParser;
import org.apache.iceberg.rest.requests.CreateViewRequest;
import org.apache.iceberg.rest.requests.CreateViewRequestParser;
import org.apache.iceberg.rest.requests.FetchScanTasksRequest;
import org.apache.iceberg.rest.requests.FetchScanTasksRequestParser;
import org.apache.iceberg.rest.requests.ImmutableCreateViewRequest;
import org.apache.iceberg.rest.requests.ImmutableQueryEventsRequest;
import org.apache.iceberg.rest.requests.ImmutableRegisterTableRequest;
import org.apache.iceberg.rest.requests.ImmutableRegisterViewRequest;
import org.apache.iceberg.rest.requests.ImmutableRemoteSignRequest;
import org.apache.iceberg.rest.requests.ImmutableReportMetricsRequest;
import org.apache.iceberg.rest.requests.PlanTableScanRequest;
import org.apache.iceberg.rest.requests.PlanTableScanRequestParser;
import org.apache.iceberg.rest.requests.QueryEventsRequest;
import org.apache.iceberg.rest.requests.QueryEventsRequestParser;
import org.apache.iceberg.rest.requests.RegisterTableRequest;
import org.apache.iceberg.rest.requests.RegisterTableRequestParser;
import org.apache.iceberg.rest.requests.RegisterViewRequest;
Expand All @@ -77,6 +82,7 @@
import org.apache.iceberg.rest.responses.FetchScanTasksResponseParser;
import org.apache.iceberg.rest.responses.ImmutableLoadCredentialsResponse;
import org.apache.iceberg.rest.responses.ImmutableLoadViewResponse;
import org.apache.iceberg.rest.responses.ImmutableQueryEventsResponse;
import org.apache.iceberg.rest.responses.ImmutableRemoteSignResponse;
import org.apache.iceberg.rest.responses.LoadCredentialsResponse;
import org.apache.iceberg.rest.responses.LoadCredentialsResponseParser;
Expand All @@ -87,6 +93,8 @@
import org.apache.iceberg.rest.responses.OAuthTokenResponse;
import org.apache.iceberg.rest.responses.PlanTableScanResponse;
import org.apache.iceberg.rest.responses.PlanTableScanResponseParser;
import org.apache.iceberg.rest.responses.QueryEventsResponse;
import org.apache.iceberg.rest.responses.QueryEventsResponseParser;
import org.apache.iceberg.rest.responses.RemoteSignResponse;
import org.apache.iceberg.rest.responses.RemoteSignResponseParser;
import org.apache.iceberg.util.JsonUtil;
Expand Down Expand Up @@ -174,7 +182,18 @@ public static void registerAll(ObjectMapper mapper) {
.addSerializer(RemoteSignResponse.class, new RemoteSignResponseSerializer<>())
.addSerializer(ImmutableRemoteSignResponse.class, new RemoteSignResponseSerializer<>())
.addDeserializer(RemoteSignResponse.class, new RemoteSignResponseDeserializer<>())
.addDeserializer(ImmutableRemoteSignResponse.class, new RemoteSignResponseDeserializer<>());
.addDeserializer(ImmutableRemoteSignResponse.class, new RemoteSignResponseDeserializer<>())
.addSerializer(QueryEventsRequest.class, new QueryEventsRequestSerializer<>())
.addSerializer(ImmutableQueryEventsRequest.class, new QueryEventsRequestSerializer<>())
.addDeserializer(QueryEventsRequest.class, new QueryEventsRequestDeserializer<>())
.addDeserializer(ImmutableQueryEventsRequest.class, new QueryEventsRequestDeserializer<>())
.addSerializer(QueryEventsResponse.class, new QueryEventsResponseSerializer<>())
.addSerializer(ImmutableQueryEventsResponse.class, new QueryEventsResponseSerializer<>())
.addDeserializer(QueryEventsResponse.class, new QueryEventsResponseDeserializer<>())
.addDeserializer(
ImmutableQueryEventsResponse.class, new QueryEventsResponseDeserializer<>())
.addSerializer(Event.class, new EventSerializer())
.addDeserializer(Event.class, new EventDeserializer());

mapper.registerModule(module);
}
Expand Down Expand Up @@ -699,4 +718,56 @@ public T deserialize(JsonParser p, DeserializationContext context) throws IOExce
return (T) RemoteSignResponseParser.fromJson(jsonNode);
}
}

static class QueryEventsRequestSerializer<T extends QueryEventsRequest>
extends JsonSerializer<T> {
@Override
public void serialize(T request, JsonGenerator gen, SerializerProvider serializers)
throws IOException {
QueryEventsRequestParser.toJson(request, gen);
}
}

static class QueryEventsRequestDeserializer<T extends QueryEventsRequest>
extends JsonDeserializer<T> {
@Override
public T deserialize(JsonParser p, DeserializationContext context) throws IOException {
JsonNode jsonNode = p.getCodec().readTree(p);
return (T) QueryEventsRequestParser.fromJson(jsonNode);
}
}

static class QueryEventsResponseSerializer<T extends QueryEventsResponse>
extends JsonSerializer<T> {
@Override
public void serialize(T response, JsonGenerator gen, SerializerProvider serializers)
throws IOException {
QueryEventsResponseParser.toJson(response, gen);
}
}

static class QueryEventsResponseDeserializer<T extends QueryEventsResponse>
extends JsonDeserializer<T> {
@Override
public T deserialize(JsonParser p, DeserializationContext context) throws IOException {
JsonNode jsonNode = p.getCodec().readTree(p);
return (T) QueryEventsResponseParser.fromJson(jsonNode);
}
}

static class EventSerializer extends JsonSerializer<Event> {
@Override
public void serialize(Event event, JsonGenerator gen, SerializerProvider serializers)
throws IOException {
EventParser.toJson(event, gen);
}
}

static class EventDeserializer extends JsonDeserializer<Event> {
@Override
public Event deserialize(JsonParser p, DeserializationContext context) throws IOException {
JsonNode jsonNode = p.getCodec().readTree(p);
return EventParser.fromJson(jsonNode);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.events;

/**
* Base interface for all catalog operations in the IRC Events endpoint.
*
* <p>Each operation type represents a specific catalog change (e.g., creating a table, dropping a
* namespace). The {@link #operationType()} is used as a discriminator for deserialization.
*/
public interface CatalogOperation {

/** The type of operation, used as a discriminator for polymorphic deserialization. */
String operationType();
}
Loading