huaxingao commented on code in PR #18935:
URL: https://github.com/apache/iceberg/pull/18935#discussion_r4649471207
##########
core/src/main/java/org/apache/iceberg/MetricsConfig.java:
##########
@@ -50,6 +50,12 @@
public final class MetricsConfig implements Serializable {
private static final Logger LOG =
LoggerFactory.getLogger(MetricsConfig.class);
+ private static final int FILE_URI_ID_OFFSET = 1;
+ private static final int FILE_SIZE_ID_OFFSET = 3;
+ private static final int FILE_CONTENT_TYPE_ID_OFFSET = 4;
+ private static final int[] FILE_INFERRED_METRIC_ID_OFFSETS = {
+ FILE_URI_ID_OFFSET, FILE_SIZE_ID_OFFSET, FILE_CONTENT_TYPE_ID_OFFSET
Review Comment:
The spec says "Writers should produce statistics for `uri`, `content_type`,
and `inline` fields; other fields may be omitted." Here the inferred fields are
uri, size, and content_type, so size gets bounds while inline only gets counts.
Should this follow the spec, or should the spec be updated to match?
##########
core/src/main/java/org/apache/iceberg/MetricsConfig.java:
##########
@@ -313,6 +332,23 @@ private static Map<String, MetricsMode> defaultColumnModes(
return builder.build();
}
+ private static Map<String, MetricsMode> fileColumnModes(Schema schema,
MetricsMode defaultMode) {
+ ImmutableMap.Builder<String, MetricsMode> builder = ImmutableMap.builder();
+ if (schema != null) {
+ MetricsMode fileMode =
+ defaultMode == MetricsModes.None.get() ? defaultMode :
MetricsModes.Counts.get();
+ for (Types.NestedField field :
TypeUtil.indexById(schema.asStruct()).values()) {
+ if (field.type().isFileType()) {
+ for (Types.NestedField nested : field.type().asFileType().fields()) {
+ builder.put(schema.findColumnName(nested.fieldId()), fileMode);
Review Comment:
`write.metadata.metrics.default` should apply to all columns, but here the
inferred file fields (like size and content_type) are always put in the map as
counts. Within `write.metadata.metrics.max-inferred-column-defaults` (100 by
default), `defaultColumnConf` overrides that later. Past the limit, nothing
does, so they stay at counts while a normal column past the limit gets the
configured default.
For example, this fails on the current code (size and content_type are
counts):
```java
@Test
void configuredDefaultAppliesToFileFieldsPastTheInferredLimit() {
Schema schema =
new Schema(
required(1, "id", Types.LongType.get()), optional(2, "photo",
Types.FileType.of(2)));
Map<String, String> properties =
Map.of(
TableProperties.DEFAULT_WRITE_METRICS_MODE,
"full",
TableProperties.METRICS_MAX_INFERRED_COLUMN_DEFAULTS,
"1");
MetricsConfig config = MetricsTestUtil.from(properties, schema);
assertThat(config.columnMode("photo.size")).isEqualTo(MetricsModes.Full.get());
assertThat(config.columnMode("photo.content_type")).isEqualTo(MetricsModes.Full.get());
}
```
Should this loop only set offset, checksum, and inline? I tried that locally
and the existing tests still pass.
--
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]