Skip to content

Commit

Permalink
Minor optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
malhotrashivam committed Jan 29, 2025
1 parent 4527273 commit a8330b7
Showing 1 changed file with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ private void initialize() {
tableInfo = ParquetSchemaReader
.parseMetadata(parquetMetadata.getFileMetaData().getKeyValueMetaData())
.orElse(TableInfo.builder().build());
version = tableInfo.version();
groupingColumns = tableInfo.groupingColumnMap();
columnTypes = tableInfo.columnTypeMap();
sortingColumns = SortColumnInfo.sortColumns(tableInfo.sortingColumns());
version = tableInfo.version();

if (!FILE_URI_SCHEME.equals(tableLocationKey.getURI().getScheme())) {
// We do not have the last modified time for non-file URIs
Expand Down Expand Up @@ -254,17 +254,14 @@ public boolean hasDataIndex(@NotNull final String... columns) {
// Check if the column name matches any of the grouping columns
if (columns.length == 1 && groupingColumns.containsKey(columns[0])) {
// Validate the index file exists (without loading and parsing it)
final IndexFileMetadata metadata = getIndexFileMetadata(getParquetKey().getURI(), tableInfo, columns);
final IndexFileMetadata metadata = getIndexFileMetadata(getParquetKey().getURI(), columns);
return metadata != null && parquetFileExists(metadata.fileURI);
}
// Check if the column names match any of the data indexes
for (final DataIndexInfo dataIndex : tableInfo.dataIndexes()) {
if (dataIndex.matchesColumns(columns)) {
// Validate the index file exists (without loading and parsing it)
final IndexFileMetadata metadata = getIndexFileMetadata(
getParquetKey().getURI(),
tableInfo,
columns);
final IndexFileMetadata metadata = getIndexFileMetadata(getParquetKey().getURI(), columns);
return metadata != null && parquetFileExists(metadata.fileURI);
}
}
Expand All @@ -280,7 +277,7 @@ private static boolean parquetFileExists(@NotNull final URI fileURI) {
@Nullable
public BasicDataIndex loadDataIndex(@NotNull final String... columns) {
initialize();
final IndexFileMetadata indexFileMetaData = getIndexFileMetadata(getParquetKey().getURI(), tableInfo, columns);
final IndexFileMetadata indexFileMetaData = getIndexFileMetadata(getParquetKey().getURI(), columns);
if (indexFileMetaData == null) {
throw new TableDataException(
String.format(
Expand Down Expand Up @@ -326,13 +323,12 @@ private static URI makeRelativeURI(@NotNull final URI parentFileURI, @NotNull fi
}
}

private static IndexFileMetadata getIndexFileMetadata(
private IndexFileMetadata getIndexFileMetadata(
@NotNull final URI parentFileURI,
@NotNull final TableInfo info,
@NotNull final String... keyColumnNames) {
if (keyColumnNames.length == 1) {
// If there's only one key column, there might be (legacy) grouping info
final GroupingColumnInfo groupingColumnInfo = info.groupingColumnMap().get(keyColumnNames[0]);
final GroupingColumnInfo groupingColumnInfo = groupingColumns.get(keyColumnNames[0]);
if (groupingColumnInfo != null) {
return new IndexFileMetadata(
makeRelativeURI(parentFileURI, groupingColumnInfo.groupingTablePath()),
Expand All @@ -343,7 +339,7 @@ private static IndexFileMetadata getIndexFileMetadata(

// Either there are more than 1 key columns, or there was no grouping info, so lets see if there was a
// DataIndex.
final DataIndexInfo dataIndexInfo = info.dataIndexes().stream()
final DataIndexInfo dataIndexInfo = tableInfo.dataIndexes().stream()
.filter(item -> item.matchesColumns(keyColumnNames))
.findFirst()
.orElse(null);
Expand Down

0 comments on commit a8330b7

Please sign in to comment.