From b3b6e926ac3c3691c17e699e7b01703bfd2f9e1b Mon Sep 17 00:00:00 2001 From: Yuya Ebihara Date: Tue, 19 Nov 2024 19:06:59 +0900 Subject: [PATCH] Make FilesTable.toJson method package-private --- .../io/trino/plugin/iceberg/FilesTable.java | 140 +++++++++--------- 1 file changed, 70 insertions(+), 70 deletions(-) diff --git a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/FilesTable.java b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/FilesTable.java index 715941c12f1f..319a1376b209 100644 --- a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/FilesTable.java +++ b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/FilesTable.java @@ -356,80 +356,12 @@ private List getRecord(StructLike structLike) columns.add(structLike.get(columnNameToPosition.get(SORT_ORDER_ID_COLUMN_NAME), Integer.class)); ReadableMetricsStruct readableMetrics = structLike.get(columnNameToPosition.get(READABLE_METRICS_COLUMN_NAME), ReadableMetricsStruct.class); - columns.add(toJson(readableMetrics)); + columns.add(toJson(readableMetrics, primitiveFields)); checkArgument(columns.size() == types.size(), "Expected %s types in row, but got %s values", types.size(), columns.size()); return columns; } - private String toJson(ReadableMetricsStruct readableMetrics) - { - StringWriter writer = new StringWriter(); - try { - JsonGenerator generator = JSON_FACTORY.createGenerator(writer); - generator.writeStartObject(); - - for (int i = 0; i < readableMetrics.size(); i++) { - Types.NestedField field = primitiveFields.get(i); - generator.writeFieldName(field.name()); - - generator.writeStartObject(); - ReadableColMetricsStruct columnMetrics = readableMetrics.get(i, ReadableColMetricsStruct.class); - - generator.writeFieldName("column_size"); - Long columnSize = columnMetrics.get(0, Long.class); - if (columnSize == null) { - generator.writeNull(); - } - else { - generator.writeNumber(columnSize); - } - - generator.writeFieldName("value_count"); - Long valueCount = columnMetrics.get(1, Long.class); - if (valueCount == null) { - generator.writeNull(); - } - else { - generator.writeNumber(valueCount); - } - - generator.writeFieldName("null_value_count"); - Long nullValueCount = columnMetrics.get(2, Long.class); - if (nullValueCount == null) { - generator.writeNull(); - } - else { - generator.writeNumber(nullValueCount); - } - - generator.writeFieldName("nan_value_count"); - Long nanValueCount = columnMetrics.get(3, Long.class); - if (nanValueCount == null) { - generator.writeNull(); - } - else { - generator.writeNumber(nanValueCount); - } - - generator.writeFieldName("lower_bound"); - SingleValueParser.toJson(field.type(), columnMetrics.get(4, Object.class), generator); - - generator.writeFieldName("upper_bound"); - SingleValueParser.toJson(field.type(), columnMetrics.get(5, Object.class), generator); - - generator.writeEndObject(); - } - - generator.writeEndObject(); - generator.flush(); - return writer.toString(); - } - catch (IOException e) { - throw new UncheckedIOException("JSON conversion failed for: " + readableMetrics, e); - } - } - private SqlMap getIntegerBigintSqlMap(Map value) { if (value == null) { @@ -506,7 +438,75 @@ private static Slice toVarbinarySlice(ByteBuffer value) } } - private static Map getIcebergIdToTypeMapping(Schema schema) + static String toJson(ReadableMetricsStruct readableMetrics, List primitiveFields) + { + StringWriter writer = new StringWriter(); + try { + JsonGenerator generator = JSON_FACTORY.createGenerator(writer); + generator.writeStartObject(); + + for (int i = 0; i < readableMetrics.size(); i++) { + Types.NestedField field = primitiveFields.get(i); + generator.writeFieldName(field.name()); + + generator.writeStartObject(); + ReadableColMetricsStruct columnMetrics = readableMetrics.get(i, ReadableColMetricsStruct.class); + + generator.writeFieldName("column_size"); + Long columnSize = columnMetrics.get(0, Long.class); + if (columnSize == null) { + generator.writeNull(); + } + else { + generator.writeNumber(columnSize); + } + + generator.writeFieldName("value_count"); + Long valueCount = columnMetrics.get(1, Long.class); + if (valueCount == null) { + generator.writeNull(); + } + else { + generator.writeNumber(valueCount); + } + + generator.writeFieldName("null_value_count"); + Long nullValueCount = columnMetrics.get(2, Long.class); + if (nullValueCount == null) { + generator.writeNull(); + } + else { + generator.writeNumber(nullValueCount); + } + + generator.writeFieldName("nan_value_count"); + Long nanValueCount = columnMetrics.get(3, Long.class); + if (nanValueCount == null) { + generator.writeNull(); + } + else { + generator.writeNumber(nanValueCount); + } + + generator.writeFieldName("lower_bound"); + SingleValueParser.toJson(field.type(), columnMetrics.get(4, Object.class), generator); + + generator.writeFieldName("upper_bound"); + SingleValueParser.toJson(field.type(), columnMetrics.get(5, Object.class), generator); + + generator.writeEndObject(); + } + + generator.writeEndObject(); + generator.flush(); + return writer.toString(); + } + catch (IOException e) { + throw new UncheckedIOException("JSON conversion failed for: " + readableMetrics, e); + } + } + + static Map getIcebergIdToTypeMapping(Schema schema) { ImmutableMap.Builder icebergIdToTypeMapping = ImmutableMap.builder(); for (Types.NestedField field : schema.columns()) {