Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial commit of Iceberg integration. #5277

Merged
merged 31 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
54e0a80
Initial commit of Iceberg integration.
lbooker42 Mar 22, 2024
780f2b1
Ready for auto-spotless anytime!
lbooker42 Mar 22, 2024
585a26e
Refactored to use internal parquet objects instead of re-implementing…
lbooker42 Apr 2, 2024
816f6b3
Merge branch 'main' into lab-iceberg
lbooker42 Apr 2, 2024
c2323d2
Rebased to main.
lbooker42 Apr 2, 2024
62952f4
update to use faster URI creation
lbooker42 Apr 2, 2024
e070b9f
Address PR comments.
lbooker42 Apr 2, 2024
c7487fe
Fix gradle broken-ness.
lbooker42 Apr 2, 2024
d4a80b8
Gradle comments, a few changes to IcebergInstructions
lbooker42 Apr 2, 2024
4f2ba28
Final gradle fix (uncomment the correct lines)
lbooker42 Apr 3, 2024
3bd98f9
Addressed PR comments, more testing needed.
lbooker42 Apr 18, 2024
de402ed
PR comments, improved testing.
lbooker42 Apr 19, 2024
f45e7d8
Merged with main.
lbooker42 Apr 22, 2024
f2900aa
merged with main
lbooker42 May 1, 2024
9762093
WIP
lbooker42 May 3, 2024
d7c2604
WIP, but test code implemented.
lbooker42 May 14, 2024
905c8ac
merged with main
lbooker42 May 15, 2024
a507402
Tests simplified and passing.
lbooker42 May 20, 2024
8db7923
Merge branch 'main' into lab-iceberg
lbooker42 May 20, 2024
0390102
Gradle cleanup.
lbooker42 May 22, 2024
4539bee
Simplified Iceberg instructions.
lbooker42 May 28, 2024
c5d6be1
Addressed many PR comments.
lbooker42 May 30, 2024
23e4a18
Attempted to handle partitioning columns correctly.
lbooker42 May 31, 2024
fa2e79d
Getting close to final.
lbooker42 May 31, 2024
d6065e4
Another rev from comments.
lbooker42 May 31, 2024
ea5ca0e
WIP, some updates.
lbooker42 Jun 3, 2024
35861c1
Merge branch 'main' into lab-iceberg
lbooker42 Jun 3, 2024
e51cf7c
Hadoop gradle version harmonization.
lbooker42 Jun 3, 2024
b408f12
Iceberg project restructure.
lbooker42 Jun 3, 2024
de7d1f3
Exposing 'iceberg-aws' in gradle.
lbooker42 Jun 3, 2024
23d6e32
Addressing PR comments.
lbooker42 Jun 4, 2024
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 @@ -54,7 +54,8 @@ public abstract class IcebergBaseLayout implements TableLocationKeyFinder<Iceber
final Map<URI, IcebergTableLocationKey> cache;

/**
* The {@link ParquetInstructions} object that will be used to read any Parquet data files in this table.
* The {@link ParquetInstructions} object that will be used to read any Parquet data files in this table. Only
* accessed while synchronized on {@code this}.
*/
ParquetInstructions parquetInstructions;

Expand All @@ -68,6 +69,9 @@ protected IcebergTableLocationKey locationKey(
// Start with user-supplied instructions (if provided).
final ParquetInstructions.Builder builder = new ParquetInstructions.Builder();
lbooker42 marked this conversation as resolved.
Show resolved Hide resolved

// Add the table definition.
builder.setTableDefinition(tableDef);

// Add any column rename mappings.
if (!instructions.columnRenameMap().isEmpty()) {
for (Map.Entry<String, String> entry : instructions.columnRenameMap().entrySet()) {
Expand All @@ -76,9 +80,8 @@ protected IcebergTableLocationKey locationKey(
}

// Add the S3 instructions.
if (instructions.s3Instructions().isPresent()) {
builder.setSpecialInstructions(instructions.s3Instructions().get());
}
instructions.s3Instructions().ifPresent(builder::setSpecialInstructions);

parquetInstructions = builder.build();
}
return new IcebergTableParquetLocationKey(fileUri, 0, partitions, parquetInstructions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,21 @@
* a {@link Snapshot}
*/
public final class IcebergKeyValuePartitionedLayout extends IcebergBaseLayout {
private final String[] partitionColumns;
private final Class<?>[] partitionColumnTypes;
private final String[] inputPartitionColumnNames;

private class ColumnData {
final String name;
final Class<?> type;
final int index;

public ColumnData(String name, Class<?> type, int index) {
this.name = name;
this.type = type;
this.index = index;
}
}

private final List<ColumnData> outputPartitionColumns;

/**
* @param tableDef The {@link TableDefinition} that will be used for the table.
Expand All @@ -37,14 +50,33 @@ public IcebergKeyValuePartitionedLayout(
@NotNull final org.apache.iceberg.Table table,
@NotNull final org.apache.iceberg.Snapshot tableSnapshot,
@NotNull final FileIO fileIO,
@NotNull final PartitionSpec partitionSpec,
lbooker42 marked this conversation as resolved.
Show resolved Hide resolved
@NotNull final IcebergInstructions instructions) {
super(tableDef, table, tableSnapshot, fileIO, instructions);

partitionColumns =
tableDef.getPartitioningColumns().stream().map(ColumnDefinition::getName).toArray(String[]::new);
partitionColumnTypes = Arrays.stream(partitionColumns)
.map(colName -> TypeUtils.getBoxedType(tableDef.getColumn(colName).getDataType()))
.toArray(Class<?>[]::new);
// Get the list of (potentially renamed) columns on which the Iceberg table is partitioned. This will be the
// order of the values in DataFile.partition() collection.
inputPartitionColumnNames = partitionSpec.fields().stream()
.map(PartitionField::name)
.map(col -> instructions.columnRenameMap().getOrDefault(col, col))
.toArray(String[]::new);

outputPartitionColumns = new ArrayList<>();

// Get the list of columns in the table definition that are included in the partition columns.
final List<String> outputCols = tableDef.getColumnNames();
outputCols.retainAll(List.of(inputPartitionColumnNames));

for (String col : outputCols) {
// Is this so inefficient that it's worth it to use a map?
for (int i = 0; i < inputPartitionColumnNames.length; i++) {
if (inputPartitionColumnNames[i].equals(col)) {
outputPartitionColumns
.add(new ColumnData(col, TypeUtils.getBoxedType(tableDef.getColumn(col).getDataType()), i));
break;
}
}
}
lbooker42 marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
Expand All @@ -57,14 +89,15 @@ IcebergTableLocationKey keyFromDataFile(DataFile df, URI fileUri) {
final Map<String, Comparable<?>> partitions = new LinkedHashMap<>();

final PartitionData partitionData = (PartitionData) df.partition();
for (int ii = 0; ii < partitionColumns.length; ++ii) {
final Object value = partitionData.get(ii);
if (value != null && !value.getClass().isAssignableFrom(partitionColumnTypes[ii])) {
throw new TableDataException("Partitioning column " + partitionColumns[ii]
for (ColumnData colData : outputPartitionColumns) {
final String colName = colData.name;
final Object value = partitionData.get(colData.index);
if (value != null && !value.getClass().isAssignableFrom(colData.type)) {
throw new TableDataException("Partitioning column " + colName
+ " has type " + value.getClass().getName()
+ " but expected " + partitionColumnTypes[ii].getName());
+ " but expected " + colData.type.getName());
}
partitions.put(partitionColumns[ii], (Comparable<?>) value);
partitions.put(colName, (Comparable<?>) value);
}
lbooker42 marked this conversation as resolved.
Show resolved Hide resolved
return locationKey(df.format(), fileUri, partitions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import io.deephaven.engine.table.impl.locations.TableLocation;
import io.deephaven.engine.table.impl.locations.impl.TableLocationFactory;
import io.deephaven.engine.table.impl.locations.util.TableDataRefreshService;
import io.deephaven.parquet.table.ParquetInstructions;
import io.deephaven.parquet.table.location.ParquetTableLocation;
import io.deephaven.parquet.table.location.ParquetTableLocationKey;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -22,7 +25,8 @@ public TableLocation makeLocation(@NotNull final TableKey tableKey,
@NotNull final IcebergTableLocationKey locationKey,
@Nullable final TableDataRefreshService refreshService) {
if (locationKey instanceof IcebergTableParquetLocationKey) {
return new IcebergTableParquetLocation(tableKey, locationKey);
return new ParquetTableLocation(tableKey, (ParquetTableLocationKey) locationKey,
(ParquetInstructions) locationKey.readInstructions());
}
throw new UnsupportedOperationException("Unsupported location key type: " + locationKey.getClass());
rcaudy marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public String getImplementationName() {
}

@Override
public Object readInstructions() {
public ParquetInstructions readInstructions() {
return readInstructions;
}
}
Loading
Loading