Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ public Metrics toIceberg(Schema schema, long totalRowCount, List<ColumnStat> fie
valueCounts.put(fieldId, columnStats.getNumValues());
nullValueCounts.put(fieldId, columnStats.getNumNulls());
Type fieldType = icebergField.type();
if (columnStats.getRange().getMinValue() != null) {
lowerBounds.put(
fieldId, Conversions.toByteBuffer(fieldType, columnStats.getRange().getMinValue()));
Object minValue = normalizeStatValue(fieldType, columnStats.getRange().getMinValue());
if (minValue != null) {
lowerBounds.put(fieldId, Conversions.toByteBuffer(fieldType, minValue));
}
if (columnStats.getRange().getMaxValue() != null) {
upperBounds.put(
fieldId, Conversions.toByteBuffer(fieldType, columnStats.getRange().getMaxValue()));
Object maxValue = normalizeStatValue(fieldType, columnStats.getRange().getMaxValue());
if (maxValue != null) {
upperBounds.put(fieldId, Conversions.toByteBuffer(fieldType, maxValue));
}
});
return new Metrics(
Expand Down Expand Up @@ -130,4 +130,18 @@ private Object convertFromIcebergValue(Type fieldType, ByteBuffer value) {
}
return convertedValue;
}

private Object normalizeStatValue(Type fieldType, Object value) {
if (value == null || !(value instanceof Number)) {
return value;
}
switch (fieldType.typeId()) {
case FLOAT:
return ((Number) value).floatValue();
case DOUBLE:
return ((Number) value).doubleValue();
default:
return value;
}
}
}