rdblue commented on code in PR #18331:
URL: https://github.com/apache/iceberg/pull/18331#discussion_r4157163107
##########
core/src/test/java/org/apache/iceberg/TestMetricsConfig.java:
##########
@@ -288,4 +464,62 @@ public void testLimitingMetricsFieldIds() {
.isEqualTo(MetricsModes.Truncate.withLength(16));
assertThat(wider.columnMode(4)).isEqualTo(MetricsModes.None.get());
}
+
+ @Test
+ public void testMetricsConfigKryoSerialization() throws Exception {
+ Map<String, String> metricsConfig =
+ ImmutableMap.of(
+ TableProperties.DEFAULT_WRITE_METRICS_MODE,
+ "counts",
+ TableProperties.METRICS_MODE_COLUMN_CONF_PREFIX + "col1",
+ "full",
+ TableProperties.METRICS_MODE_COLUMN_CONF_PREFIX + "col2",
+ "truncate(16)");
+
+ Schema schema =
+ new Schema(
+ Types.NestedField.required(1, "col1", Types.IntegerType.get()),
+ Types.NestedField.optional(2, "col2", Types.StringType.get()),
+ Types.NestedField.optional(3, "col3", Types.StringType.get()));
+
+ MetricsConfig config = MetricsTestUtil.from(metricsConfig, schema);
+ MetricsConfig deserialized =
TestHelpers.KryoHelpers.roundTripSerialize(config);
+
+
assertThat(deserialized.columnMode(1)).asString().isEqualTo(MetricsModes.Full.get().toString());
+ assertThat(deserialized.columnMode(2))
+ .asString()
+ .isEqualTo(MetricsModes.Truncate.withLength(16).toString());
+ assertThat(deserialized.columnMode(3))
Review Comment:
Done.
##########
core/src/main/java/org/apache/iceberg/MetricsConfig.java:
##########
@@ -367,15 +367,15 @@ private static Map<String, MetricsMode>
partitionColumnModes(PartitionSpec spec)
private static Map<Integer, String> idToName(
Schema schema, Map<String, MetricsMode> columnModes) {
if (schema != null) {
- ImmutableMap.Builder<Integer, String> builder = ImmutableMap.builder();
- for (String name : columnModes.keySet()) {
- Types.NestedField field = schema.findField(name);
- if (field != null) {
- builder.put(field.fieldId(), name);
+ Map<Integer, String> idToName = Maps.newLinkedHashMap();
+ for (Integer fieldId : SchemaOrder.allFieldIds(schema)) {
Review Comment:
Fixed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]