Skip to content

Commit

Permalink
Provide memory estimation for Delta split
Browse files Browse the repository at this point in the history
  • Loading branch information
losipiuk committed Mar 29, 2022
1 parent db5c3ed commit f8eda0c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,27 @@
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;
import java.util.Objects;
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;
Expand Down Expand Up @@ -120,6 +126,16 @@ public Map<String, Optional<String>> 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()
{
Expand Down

0 comments on commit f8eda0c

Please sign in to comment.