From f8eda0c7770be3676572c3012e09afdf7a13a045 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Osipiuk?= Date: Thu, 24 Mar 2022 19:33:39 +0100 Subject: [PATCH] Provide memory estimation for Delta split --- .../plugin/deltalake/DeltaLakeColumnHandle.java | 10 ++++++++++ .../trino/plugin/deltalake/DeltaLakeSplit.java | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeColumnHandle.java b/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeColumnHandle.java index aa54a597676c..93ccb70566d9 100644 --- a/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeColumnHandle.java +++ b/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeColumnHandle.java @@ -18,10 +18,12 @@ import io.trino.plugin.hive.HiveColumnHandle; import io.trino.spi.connector.ColumnHandle; import io.trino.spi.type.Type; +import org.openjdk.jol.info.ClassLayout; import java.util.Objects; import java.util.Optional; +import static io.airlift.slice.SizeOf.estimatedSizeOf; import static io.trino.plugin.deltalake.DeltaHiveTypeTranslator.toHiveType; import static io.trino.plugin.deltalake.DeltaLakeColumnType.SYNTHESIZED; import static io.trino.spi.type.BigintType.BIGINT; @@ -32,6 +34,8 @@ public class DeltaLakeColumnHandle implements ColumnHandle { + private static final int INSTANCE_SIZE = ClassLayout.parseClass(DeltaLakeColumnHandle.class).instanceSize(); + public static final String ROW_ID_COLUMN_NAME = "$row_id"; public static final Type ROW_ID_COLUMN_TYPE = BIGINT; @@ -92,6 +96,12 @@ public boolean equals(Object obj) this.columnType == other.columnType; } + public long getRetainedSizeInBytes() + { + // type is not accounted for as the instances are cached (by TypeRegistry) and shared + return INSTANCE_SIZE + estimatedSizeOf(name); + } + @Override public int hashCode() { diff --git a/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeSplit.java b/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeSplit.java index 3abbffb87489..b179d54e45b0 100644 --- a/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeSplit.java +++ b/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeSplit.java @@ -17,9 +17,11 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import io.airlift.slice.SizeOf; import io.trino.spi.HostAddress; import io.trino.spi.connector.ConnectorSplit; import io.trino.spi.predicate.TupleDomain; +import org.openjdk.jol.info.ClassLayout; import java.util.List; import java.util.Map; @@ -27,11 +29,15 @@ import java.util.Optional; import static com.google.common.base.MoreObjects.toStringHelper; +import static io.airlift.slice.SizeOf.estimatedSizeOf; +import static io.airlift.slice.SizeOf.sizeOf; import static java.util.Objects.requireNonNull; public class DeltaLakeSplit implements ConnectorSplit { + private static final int INSTANCE_SIZE = ClassLayout.parseClass(DeltaLakeSplit.class).instanceSize(); + private final String path; private final long start; private final long length; @@ -120,6 +126,16 @@ public Map> getPartitionKeys() return partitionKeys; } + @Override + public long getRetainedSizeInBytes() + { + return INSTANCE_SIZE + + estimatedSizeOf(path) + + estimatedSizeOf(addresses, HostAddress::getRetainedSizeInBytes) + + statisticsPredicate.getRetainedSizeInBytes(DeltaLakeColumnHandle::getRetainedSizeInBytes) + + estimatedSizeOf(partitionKeys, SizeOf::estimatedSizeOf, value -> sizeOf(value, SizeOf::estimatedSizeOf)); + } + @Override public Object getInfo() {