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

Fix Delta ANALYZE for mixed case columns #18583

Merged
merged 1 commit into from
Aug 8, 2023
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 @@ -2817,9 +2817,7 @@ public ConnectorAnalyzeMetadata getStatisticsCollectionMetadata(ConnectorSession
}

List<DeltaLakeColumnMetadata> columnsMetadata = extractSchema(metadata, typeManager);
Map<String, String> physicalColumnNameMapping = columnsMetadata.stream()
.collect(toImmutableMap(DeltaLakeColumnMetadata::getName, DeltaLakeColumnMetadata::getPhysicalName));
Set<String> allColumnNames = physicalColumnNameMapping.keySet();
Set<String> allColumnNames = columnsMetadata.stream().map(columnMetadata -> columnMetadata.getName().toLowerCase(ENGLISH)).collect(Collectors.toSet());
Optional<Set<String>> analyzeColumnNames = getColumnNames(analyzeProperties);
if (analyzeColumnNames.isPresent()) {
Set<String> columnNames = analyzeColumnNames.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,15 +444,35 @@ public void testStatisticsWithColumnCaseSensitivity()
assertThat(stats.getMaxValues().orElseThrow().get("UPPER_CASE")).isEqualTo(20);
assertThat(stats.getNullCount("UPPER_CASE").orElseThrow()).isEqualTo(1);

assertUpdate("UPDATE " + tableName + " SET upper_case = 30", 3);
assertUpdate("UPDATE " + tableName + " SET upper_case = upper_case + 10", 3);

List<DeltaLakeTransactionLogEntry> transactionLogAfterUpdate = getEntriesFromJson(1, tableLocation.resolve("_delta_log").toString(), FILE_SYSTEM).orElseThrow();
assertThat(transactionLogAfterUpdate).hasSize(2);
AddFileEntry updateAddFileEntry = transactionLogAfterUpdate.get(1).getAdd();
List<DeltaLakeTransactionLogEntry> transactionLogAfterUpdate = getEntriesFromJson(2, tableLocation.resolve("_delta_log").toString(), FILE_SYSTEM).orElseThrow();
assertThat(transactionLogAfterUpdate).hasSize(3);
AddFileEntry updateAddFileEntry = transactionLogAfterUpdate.get(2).getAdd();
DeltaLakeFileStatistics updateStats = updateAddFileEntry.getStats().orElseThrow();
assertThat(updateStats.getMinValues().orElseThrow().get("UPPER_CASE")).isEqualTo(10);
assertThat(updateStats.getMaxValues().orElseThrow().get("UPPER_CASE")).isEqualTo(20);
assertThat(updateStats.getMinValues().orElseThrow().get("UPPER_CASE")).isEqualTo(20);
assertThat(updateStats.getMaxValues().orElseThrow().get("UPPER_CASE")).isEqualTo(30);
assertThat(updateStats.getNullCount("UPPER_CASE").orElseThrow()).isEqualTo(1);

assertQuery(
"SHOW STATS FOR " + tableName,
"""
VALUES
('upper_case', null, 2.0, 0.3333333333333333, null, 20, 30),
('part', null, 1.0, 0.0, null, null, null),
(null, null, null, null, 3.0, null, null)
""");

assertUpdate(format("ANALYZE %s WITH(mode = 'full_refresh')", tableName));

assertQuery(
"SHOW STATS FOR " + tableName,
"""
VALUES
('upper_case', null, 2.0, 0.3333333333333333, null, 20, 30),
('part', null, 1.0, 0.0, null, null, null),
(null, null, null, null, 3.0, null, null)
""");
}

@DataProvider
Expand Down