Skip to content
Merged
Show file tree
Hide file tree
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 @@ -22,6 +22,7 @@

import java.util.Objects;
import java.util.Optional;
import java.util.OptionalInt;

import static io.airlift.slice.SizeOf.estimatedSizeOf;
import static io.trino.plugin.deltalake.DeltaHiveTypeTranslator.toHiveType;
Expand Down Expand Up @@ -57,26 +58,29 @@ public class DeltaLakeColumnHandle

private final String name;
private final Type type;
private final OptionalInt fieldId;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include in getRetainedSizeInBytes too

cc @krvikash

// Hold field names in Parquet files
// The value is same as 'name' when the column mapping mode is none
// The value is same as 'delta.columnMapping.physicalName' when the column mapping mode is name. e.g. col-6707cc9e-f3aa-4e6b-b8ef-1b03d3475680
// The value is same as 'delta.columnMapping.physicalName' when the column mapping mode is id or name. e.g. col-6707cc9e-f3aa-4e6b-b8ef-1b03d3475680
private final String physicalName;
// Hold type in Parquet files
// The value is same as 'type' when the column mapping mode is none
// The value is same as 'delta.columnMapping.physicalName' when the column mapping mode is name. e.g. row(col-5924c8b3-04cf-4146-abb5-2c229e7ff708 integer)
// The value is same as 'delta.columnMapping.physicalName' when the column mapping mode is id or name. e.g. row(col-5924c8b3-04cf-4146-abb5-2c229e7ff708 integer)
private final Type physicalType;
private final DeltaLakeColumnType columnType;

@JsonCreator
public DeltaLakeColumnHandle(
@JsonProperty("name") String name,
@JsonProperty("type") Type type,
@JsonProperty("fieldId") OptionalInt fieldId,
@JsonProperty("physicalName") String physicalName,
@JsonProperty("physicalType") Type physicalType,
@JsonProperty("columnType") DeltaLakeColumnType columnType)
{
this.name = requireNonNull(name, "name is null");
this.type = requireNonNull(type, "type is null");
this.fieldId = requireNonNull(fieldId, "fieldId is null");
this.physicalName = requireNonNull(physicalName, "physicalName is null");
this.physicalType = requireNonNull(physicalType, "physicalType is null");
this.columnType = requireNonNull(columnType, "columnType is null");
Expand All @@ -94,6 +98,12 @@ public Type getType()
return type;
}

@JsonProperty
public OptionalInt getFieldId()
{
return fieldId;
}

@JsonProperty
public String getPhysicalName()
{
Expand Down Expand Up @@ -124,6 +134,7 @@ public boolean equals(Object obj)
DeltaLakeColumnHandle other = (DeltaLakeColumnHandle) obj;
return Objects.equals(this.name, other.name) &&
Objects.equals(this.type, other.type) &&
Objects.equals(this.fieldId, other.fieldId) &&
Objects.equals(this.physicalName, other.physicalName) &&
Objects.equals(this.physicalType, other.physicalType) &&
this.columnType == other.columnType;
Expand All @@ -138,7 +149,7 @@ public long getRetainedSizeInBytes()
@Override
public int hashCode()
{
return Objects.hash(name, type, physicalName, physicalType, columnType);
return Objects.hash(name, type, fieldId, physicalName, physicalType, columnType);
}

@Override
Expand All @@ -161,16 +172,16 @@ public HiveColumnHandle toHiveColumnHandle()

public static DeltaLakeColumnHandle pathColumnHandle()
{
return new DeltaLakeColumnHandle(PATH_COLUMN_NAME, PATH_TYPE, PATH_COLUMN_NAME, PATH_TYPE, SYNTHESIZED);
return new DeltaLakeColumnHandle(PATH_COLUMN_NAME, PATH_TYPE, OptionalInt.empty(), PATH_COLUMN_NAME, PATH_TYPE, SYNTHESIZED);
}

public static DeltaLakeColumnHandle fileSizeColumnHandle()
{
return new DeltaLakeColumnHandle(FILE_SIZE_COLUMN_NAME, FILE_SIZE_TYPE, FILE_SIZE_COLUMN_NAME, FILE_SIZE_TYPE, SYNTHESIZED);
return new DeltaLakeColumnHandle(FILE_SIZE_COLUMN_NAME, FILE_SIZE_TYPE, OptionalInt.empty(), FILE_SIZE_COLUMN_NAME, FILE_SIZE_TYPE, SYNTHESIZED);
}

public static DeltaLakeColumnHandle fileModifiedTimeColumnHandle()
{
return new DeltaLakeColumnHandle(FILE_MODIFIED_TIME_COLUMN_NAME, FILE_MODIFIED_TIME_TYPE, FILE_MODIFIED_TIME_COLUMN_NAME, FILE_MODIFIED_TIME_TYPE, SYNTHESIZED);
return new DeltaLakeColumnHandle(FILE_MODIFIED_TIME_COLUMN_NAME, FILE_MODIFIED_TIME_TYPE, OptionalInt.empty(), FILE_MODIFIED_TIME_COLUMN_NAME, FILE_MODIFIED_TIME_TYPE, SYNTHESIZED);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.trino.spi.type.Type;

import java.util.Objects;
import java.util.OptionalInt;

import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Locale.ENGLISH;
Expand All @@ -25,12 +26,14 @@
public class DeltaLakeColumnMetadata
{
private final ColumnMetadata columnMetadata;
private final OptionalInt fieldId;
private final String physicalName;
private final Type physicalColumnType;

public DeltaLakeColumnMetadata(ColumnMetadata columnMetadata, String physicalName, Type physicalColumnType)
public DeltaLakeColumnMetadata(ColumnMetadata columnMetadata, OptionalInt fieldId, String physicalName, Type physicalColumnType)
{
this.columnMetadata = requireNonNull(columnMetadata, "columnMetadata is null");
this.fieldId = requireNonNull(fieldId, "fieldId is null");
this.physicalName = physicalName.toLowerCase(ENGLISH);
this.physicalColumnType = requireNonNull(physicalColumnType, "physicalColumnType is null");
}
Expand All @@ -40,6 +43,11 @@ public ColumnMetadata getColumnMetadata()
return columnMetadata;
}

public OptionalInt getFieldId()
{
return fieldId;
}

public String getName()
{
return columnMetadata.getName();
Expand All @@ -65,6 +73,7 @@ public String toString()
{
return toStringHelper(this)
.add("columnMetadata", columnMetadata)
.add("fieldId", fieldId)
.add("physicalName", physicalName)
.add("physicalColumnType", physicalColumnType)
.toString();
Expand All @@ -81,13 +90,14 @@ public boolean equals(Object o)
}
DeltaLakeColumnMetadata that = (DeltaLakeColumnMetadata) o;
return Objects.equals(columnMetadata, that.columnMetadata) &&
Objects.equals(fieldId, that.fieldId) &&
Objects.equals(physicalName, that.physicalName) &&
Objects.equals(physicalColumnType, that.physicalColumnType);
}

@Override
public int hashCode()
{
return Objects.hash(columnMetadata, physicalName, physicalColumnType);
return Objects.hash(columnMetadata, fieldId, physicalName, physicalColumnType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import io.trino.plugin.deltalake.statistics.ExtendedStatisticsAccess;
import io.trino.plugin.deltalake.transactionlog.AddFileEntry;
import io.trino.plugin.deltalake.transactionlog.CommitInfoEntry;
import io.trino.plugin.deltalake.transactionlog.DeltaLakeSchemaSupport.ColumnMappingMode;
import io.trino.plugin.deltalake.transactionlog.MetadataEntry;
import io.trino.plugin.deltalake.transactionlog.MetadataEntry.Format;
import io.trino.plugin.deltalake.transactionlog.ProtocolEntry;
Expand Down Expand Up @@ -133,6 +132,7 @@
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.OptionalLong;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
Expand Down Expand Up @@ -168,7 +168,6 @@
import static io.trino.plugin.deltalake.metastore.HiveMetastoreBackedDeltaLakeMetastore.TABLE_PROVIDER_VALUE;
import static io.trino.plugin.deltalake.procedure.DeltaLakeTableProcedureId.OPTIMIZE;
import static io.trino.plugin.deltalake.transactionlog.DeltaLakeSchemaSupport.APPEND_ONLY_CONFIGURATION_KEY;
import static io.trino.plugin.deltalake.transactionlog.DeltaLakeSchemaSupport.COLUMN_MAPPING_MODE_CONFIGURATION_KEY;
import static io.trino.plugin.deltalake.transactionlog.DeltaLakeSchemaSupport.extractColumnMetadata;
import static io.trino.plugin.deltalake.transactionlog.DeltaLakeSchemaSupport.extractPartitionColumns;
import static io.trino.plugin.deltalake.transactionlog.DeltaLakeSchemaSupport.extractSchema;
Expand All @@ -181,6 +180,7 @@
import static io.trino.plugin.deltalake.transactionlog.DeltaLakeSchemaSupport.serializeSchemaAsJson;
import static io.trino.plugin.deltalake.transactionlog.DeltaLakeSchemaSupport.serializeStatsAsJson;
import static io.trino.plugin.deltalake.transactionlog.DeltaLakeSchemaSupport.validateType;
import static io.trino.plugin.deltalake.transactionlog.DeltaLakeSchemaSupport.verifySupportedColumnMapping;
import static io.trino.plugin.deltalake.transactionlog.MetadataEntry.configurationForNewTable;
import static io.trino.plugin.deltalake.transactionlog.TransactionLogParser.getMandatoryCurrentVersion;
import static io.trino.plugin.deltalake.transactionlog.TransactionLogUtil.getTransactionLogDir;
Expand Down Expand Up @@ -388,12 +388,7 @@ public DeltaLakeTableHandle getTableHandle(ConnectorSession session, SchemaTable

TableSnapshot tableSnapshot = metastore.getSnapshot(tableName, session);
Optional<MetadataEntry> metadata = metastore.getMetadata(tableSnapshot, session);
if (metadata.isPresent()) {
ColumnMappingMode columnMappingMode = getColumnMappingMode(metadata.get());
if (columnMappingMode != ColumnMappingMode.NAME && columnMappingMode != ColumnMappingMode.NONE) {
throw new TrinoException(NOT_SUPPORTED, format("Only 'name' or 'none' is supported for the '%s' table property", COLUMN_MAPPING_MODE_CONFIGURATION_KEY));
}
}
metadata.ifPresent(metadataEntry -> verifySupportedColumnMapping(getColumnMappingMode(metadataEntry)));
return new DeltaLakeTableHandle(
tableName.getSchemaName(),
tableName.getTableName(),
Expand Down Expand Up @@ -564,7 +559,7 @@ private List<DeltaLakeColumnHandle> getColumns(MetadataEntry deltaMetadata)
{
ImmutableList.Builder<DeltaLakeColumnHandle> columns = ImmutableList.builder();
extractSchema(deltaMetadata, typeManager).stream()
.map(column -> toColumnHandle(column.getColumnMetadata(), column.getPhysicalName(), column.getPhysicalColumnType(), deltaMetadata.getCanonicalPartitionColumns()))
.map(column -> toColumnHandle(column.getColumnMetadata(), column.getFieldId(), column.getPhysicalName(), column.getPhysicalColumnType(), deltaMetadata.getCanonicalPartitionColumns()))
.forEach(columns::add);
columns.add(pathColumnHandle());
columns.add(fileSizeColumnHandle());
Expand Down Expand Up @@ -1361,7 +1356,7 @@ public Optional<ConnectorOutputMetadata> finishInsert(
@Override
public ColumnHandle getDeleteRowIdColumnHandle(ConnectorSession session, ConnectorTableHandle tableHandle)
{
return new DeltaLakeColumnHandle(ROW_ID_COLUMN_NAME, ROW_ID_COLUMN_TYPE, ROW_ID_COLUMN_NAME, ROW_ID_COLUMN_TYPE, SYNTHESIZED);
return new DeltaLakeColumnHandle(ROW_ID_COLUMN_NAME, ROW_ID_COLUMN_TYPE, OptionalInt.empty(), ROW_ID_COLUMN_NAME, ROW_ID_COLUMN_TYPE, SYNTHESIZED);
}

@Override
Expand Down Expand Up @@ -1416,7 +1411,7 @@ public ColumnHandle getUpdateRowIdColumnHandle(ConnectorSession session, Connect
RowType.field(RowType.from(unmodifiedColumnFields)));
}

return new DeltaLakeColumnHandle(ROW_ID_COLUMN_NAME, rowIdType, ROW_ID_COLUMN_NAME, rowIdType, SYNTHESIZED);
return new DeltaLakeColumnHandle(ROW_ID_COLUMN_NAME, rowIdType, OptionalInt.empty(), ROW_ID_COLUMN_NAME, rowIdType, SYNTHESIZED);
}

@Override
Expand Down Expand Up @@ -1479,7 +1474,7 @@ public RowChangeParadigm getRowChangeParadigm(ConnectorSession session, Connecto
@Override
public ColumnHandle getMergeRowIdColumnHandle(ConnectorSession session, ConnectorTableHandle tableHandle)
{
return new DeltaLakeColumnHandle(ROW_ID_COLUMN_NAME, MERGE_ROW_ID_TYPE, ROW_ID_COLUMN_NAME, MERGE_ROW_ID_TYPE, SYNTHESIZED);
return new DeltaLakeColumnHandle(ROW_ID_COLUMN_NAME, MERGE_ROW_ID_TYPE, OptionalInt.empty(), ROW_ID_COLUMN_NAME, MERGE_ROW_ID_TYPE, SYNTHESIZED);
}

@Override
Expand Down Expand Up @@ -1818,7 +1813,7 @@ private List<DeltaLakeColumnHandle> getUnmodifiedColumns(DeltaLakeTableHandle ta
Set<String> partitionColumnNames = ImmutableSet.copyOf(tableHandle.getMetadataEntry().getCanonicalPartitionColumns());
List<DeltaLakeColumnMetadata> allColumns = extractSchema(tableHandle.getMetadataEntry(), typeManager);
return allColumns.stream()
.map(column -> toColumnHandle(column.getColumnMetadata(), column.getPhysicalName(), column.getPhysicalColumnType(), partitionColumnNames))
.map(column -> toColumnHandle(column.getColumnMetadata(), column.getFieldId(), column.getPhysicalName(), column.getPhysicalColumnType(), partitionColumnNames))
.filter(columnHandle -> !updatedColumnHandles.contains(columnHandle))
.filter(columnHandle -> !partitionColumnNames.contains(columnHandle.getName()))
.collect(toImmutableList());
Expand Down Expand Up @@ -2490,7 +2485,7 @@ public static TupleDomain<DeltaLakeColumnHandle> createStatisticsPredicate(
schema.stream()
.filter(column -> canUseInPredicate(column.getColumnMetadata()))
.collect(toImmutableMap(
column -> DeltaLakeMetadata.toColumnHandle(column.getColumnMetadata(), column.getPhysicalName(), column.getPhysicalColumnType(), canonicalPartitionColumns),
column -> DeltaLakeMetadata.toColumnHandle(column.getColumnMetadata(), column.getFieldId(), column.getPhysicalName(), column.getPhysicalColumnType(), canonicalPartitionColumns),
column -> buildColumnDomain(column, deltaLakeFileStatistics, canonicalPartitionColumns)))))
.orElseGet(TupleDomain::all);
}
Expand Down Expand Up @@ -2527,7 +2522,7 @@ private static Domain buildColumnDomain(DeltaLakeColumnMetadata column, DeltaLak
}

boolean hasNulls = nullCount.get() > 0;
DeltaLakeColumnHandle deltaLakeColumnHandle = toColumnHandle(column.getColumnMetadata(), column.getPhysicalName(), column.getPhysicalColumnType(), canonicalPartitionColumns);
DeltaLakeColumnHandle deltaLakeColumnHandle = toColumnHandle(column.getColumnMetadata(), column.getFieldId(), column.getPhysicalName(), column.getPhysicalColumnType(), canonicalPartitionColumns);
Optional<Object> minValue = stats.getMinColumnValue(deltaLakeColumnHandle);
if (minValue.isPresent() && isFloatingPointNaN(column.getType(), minValue.get())) {
return allValues(column.getType(), hasNulls);
Expand Down Expand Up @@ -2584,11 +2579,17 @@ private static Domain allValues(Type type, boolean includeNull)
}

private static DeltaLakeColumnHandle toColumnHandle(ColumnMetadata column, String physicalName, Type physicalType, Collection<String> partitionColumns)
{
return toColumnHandle(column, OptionalInt.empty(), physicalName, physicalType, partitionColumns);
}

private static DeltaLakeColumnHandle toColumnHandle(ColumnMetadata column, OptionalInt fieldId, String physicalName, Type physicalType, Collection<String> partitionColumns)
{
boolean isPartitionKey = partitionColumns.stream().anyMatch(partition -> partition.equalsIgnoreCase(column.getName()));
return new DeltaLakeColumnHandle(
column.getName(),
column.getType(),
fieldId,
physicalName,
physicalType,
isPartitionKey ? PARTITION_KEY : REGULAR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.OptionalLong;
import java.util.Set;

import static com.google.common.base.Throwables.throwIfInstanceOf;
import static io.airlift.slice.Slices.utf8Slice;
Expand Down Expand Up @@ -63,6 +64,7 @@ public class DeltaLakePageSource

public DeltaLakePageSource(
List<DeltaLakeColumnHandle> columns,
Set<String> missingColumnNames,
Map<String, Optional<String>> partitionKeys,
List<String> partitionValues,
ConnectorPageSource delegate,
Expand Down Expand Up @@ -111,6 +113,10 @@ else if (column.getName().equals(ROW_ID_COLUMN_NAME)) {
delegateIndexes[outputIndex] = delegateIndex;
delegateIndex++;
}
else if (missingColumnNames.contains(column.getName())) {
prefilledBlocks[outputIndex] = Utils.nativeValueToBlock(column.getType(), null);
delegateIndexes[outputIndex] = -1;
}
else {
delegateIndexes[outputIndex] = delegateIndex;
delegateIndex++;
Expand Down
Loading