Skip to content

Commit 1ccdefd

Browse files
committed
Updating mixin definitions, rewiring AwsCloudWatchConfiguration,AwsCloudWatchEventListener AwsCloudWatchEventListenerTest
1 parent 0a957b0 commit 1ccdefd

File tree

13 files changed

+1081
-224
lines changed

13 files changed

+1081
-224
lines changed
Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,12 @@
1717
* under the License.
1818
*/
1919

20-
package org.apache.polaris.service.events.json.serde;
20+
package org.apache.polaris.service.config;
2121

22-
import com.fasterxml.jackson.core.JsonGenerator;
23-
import com.fasterxml.jackson.databind.JsonSerializer;
24-
import com.fasterxml.jackson.databind.SerializerProvider;
25-
import java.io.IOException;
26-
import org.apache.iceberg.catalog.TableIdentifier;
22+
import jakarta.inject.Qualifier;
23+
import java.lang.annotation.Retention;
24+
import java.lang.annotation.RetentionPolicy;
2725

28-
public class TableIdentifierToStringSerializer extends JsonSerializer<TableIdentifier> {
29-
30-
@Override
31-
public void serialize(TableIdentifier value, JsonGenerator gen, SerializerProvider serializers)
32-
throws IOException {
33-
34-
if (value == null) {
35-
gen.writeNull();
36-
return;
37-
}
38-
gen.writeString(value.toString());
39-
}
40-
}
26+
@Qualifier
27+
@Retention(RetentionPolicy.RUNTIME)
28+
public @interface PolarisAWSCloudWatchObjectMapper {}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.polaris.service.config;
21+
22+
import com.fasterxml.jackson.annotation.JsonAutoDetect;
23+
import com.fasterxml.jackson.annotation.PropertyAccessor;
24+
import com.fasterxml.jackson.core.StreamReadConstraints;
25+
import com.fasterxml.jackson.databind.DeserializationFeature;
26+
import com.fasterxml.jackson.databind.ObjectMapper;
27+
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
28+
import io.quarkus.runtime.configuration.MemorySize;
29+
import io.quarkus.runtime.configuration.MemorySizeConverter;
30+
import io.smallrye.config.WithConverter;
31+
import jakarta.enterprise.inject.Produces;
32+
import jakarta.inject.Inject;
33+
import jakarta.inject.Singleton;
34+
import org.apache.polaris.service.events.PolarisEvent;
35+
import org.apache.polaris.service.events.json.mixins.IcebergMixins;
36+
import org.apache.polaris.service.events.json.mixins.PolarisEventBaseMixin;
37+
import org.eclipse.microprofile.config.inject.ConfigProperty;
38+
import org.slf4j.Logger;
39+
import org.slf4j.LoggerFactory;
40+
41+
/** This mapper is isolated and used exclusively for CloudWatch event serializations */
42+
public class PolarisAWSCloudWatchObjectMapperProducer {
43+
private static final Logger LOGGER =
44+
LoggerFactory.getLogger(PolarisAWSCloudWatchObjectMapperProducer.class);
45+
46+
private final long maxBodySize;
47+
48+
@Inject
49+
public PolarisAWSCloudWatchObjectMapperProducer(
50+
@ConfigProperty(name = "polaris.aws.cloudwatch.max-body-size", defaultValue = "16M")
51+
@WithConverter(MemorySizeConverter.class)
52+
MemorySize maxBodySize) {
53+
this.maxBodySize = maxBodySize.asLongValue();
54+
}
55+
56+
@Produces
57+
@Singleton
58+
@PolarisAWSCloudWatchObjectMapper
59+
public ObjectMapper produce() {
60+
61+
// Use Snake_case for these such
62+
ObjectMapper mapper = new ObjectMapper();
63+
mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
64+
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
65+
mapper.setPropertyNamingStrategy(new PropertyNamingStrategies.KebabCaseStrategy());
66+
// Register Iceberg/Polaris specific mixins
67+
mapper.addMixIn(PolarisEvent.class, PolarisEventBaseMixin.class);
68+
mapper.addMixIn(
69+
org.apache.iceberg.catalog.TableIdentifier.class, IcebergMixins.TableIdentifierMixin.class);
70+
mapper.addMixIn(org.apache.iceberg.catalog.Namespace.class, IcebergMixins.NamespaceMixin.class);
71+
72+
// Size Constraint
73+
mapper
74+
.getFactory()
75+
.setStreamReadConstraints(
76+
StreamReadConstraints.builder().maxDocumentLength(maxBodySize).build());
77+
78+
LOGGER.info(
79+
"Produced PolarisIcebergAWSCloudWatchObjectMapper (max body size: {} bytes)", maxBodySize);
80+
return mapper;
81+
}
82+
}

runtime/service/src/main/java/org/apache/polaris/service/events/json/mixins/AfterRefreshTableEventMixin.java

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,39 @@
1919

2020
package org.apache.polaris.service.events.json.mixins;
2121

22-
import com.fasterxml.jackson.annotation.JsonValue;
22+
import com.fasterxml.jackson.annotation.JsonIgnore;
23+
import com.fasterxml.jackson.annotation.JsonProperty;
24+
import org.apache.iceberg.catalog.Namespace;
2325

24-
/**
25-
* Mixins for Iceberg classes we don't control, to keep JSON concise. The @JsonValue marks
26-
* toString() as the value to serialize.
27-
*/
28-
public class IcebergThirdPartyMixins {
29-
private IcebergThirdPartyMixins() {}
26+
/** Mixins for Iceberg classes we don't control, to keep JSON concise. */
27+
public final class IcebergMixins {
28+
29+
// Private constructor to prevent instantiation
30+
private IcebergMixins() {}
3031

32+
/** Serializes Namespace as an object like: "namespace": ["sales", "north.america"] */
3133
public abstract static class NamespaceMixin {
34+
@JsonProperty("namespace")
35+
public abstract String[] levels();
36+
3237
@Override
33-
@JsonValue
34-
public abstract String toString(); // serializes "namespace" as "db.sales"
38+
@JsonIgnore
39+
public abstract String toString();
3540
}
3641

42+
/**
43+
* Serializes TableIdentifier as a scalar string like: {"namespace": ["sales", "north.america"],
44+
* "name": "transactions"}
45+
*/
3746
public abstract static class TableIdentifierMixin {
47+
@JsonProperty("namespace")
48+
public abstract Namespace namespace();
49+
50+
@JsonProperty("name")
51+
public abstract String name();
52+
3853
@Override
39-
@JsonValue
40-
public abstract String toString(); // serializes "table_identifier" as "db.sales.orders"
54+
@JsonIgnore
55+
public abstract String toString();
4156
}
4257
}

runtime/service/src/main/java/org/apache/polaris/service/events/json/mixins/ObjectMapperFactory.java

Lines changed: 0 additions & 52 deletions
This file was deleted.

runtime/service/src/main/java/org/apache/polaris/service/events/json/mixins/PolarisEventBaseMixin.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,9 @@
2020
package org.apache.polaris.service.events.json.mixins;
2121

2222
import com.fasterxml.jackson.annotation.JsonInclude;
23-
import com.fasterxml.jackson.annotation.JsonTypeInfo;
2423
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
2524
import com.fasterxml.jackson.databind.annotation.JsonNaming;
2625

2726
@JsonInclude(JsonInclude.Include.NON_NULL)
2827
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
29-
@JsonTypeInfo(
30-
use = JsonTypeInfo.Id.NAME,
31-
include = JsonTypeInfo.As.EXTERNAL_PROPERTY,
32-
property = "event_type")
3328
public abstract class PolarisEventBaseMixin {}

runtime/service/src/main/java/org/apache/polaris/service/events/jsonEventListener/AfterRefreshTableEventListener.java

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)