Skip to content

Commit

Permalink
Use default FPP when writing orc if not provided in table metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Chaho12 committed Jan 11, 2024
1 parent 0d23278 commit 3ef12a1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -749,11 +749,11 @@ public static List<HiveType> getColumnTypes(Map<String, String> schema)
public static OrcWriterOptions getOrcWriterOptions(Map<String, String> schema, OrcWriterOptions orcWriterOptions)
{
if (schema.containsKey(ORC_BLOOM_FILTER_COLUMNS_KEY)) {
if (!schema.containsKey(ORC_BLOOM_FILTER_FPP_KEY)) {
throw new TrinoException(HIVE_INVALID_METADATA, "FPP for bloom filter is missing");
}
try {
double fpp = parseDouble(schema.get(ORC_BLOOM_FILTER_FPP_KEY));
// use default fpp DEFAULT_BLOOM_FILTER_FPP if fpp key does not exist in table metadata
double fpp = schema.containsKey(ORC_BLOOM_FILTER_FPP_KEY)
? parseDouble(schema.get(ORC_BLOOM_FILTER_FPP_KEY))
: orcWriterOptions.getBloomFilterFpp();
return orcWriterOptions
.withBloomFilterColumns(ImmutableSet.copyOf(COLUMN_NAMES_SPLITTER.splitToList(schema.get(ORC_BLOOM_FILTER_COLUMNS_KEY))))
.withBloomFilterFpp(fpp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,14 @@ private static Map<String, String> createTablePropertiesWithFpp(String fpp)
.put(ORC_BLOOM_FILTER_FPP_KEY, fpp)
.buildOrThrow();
}

@Test
public void testOrcWriterOptionsWithMissingFPPValue()
{
Map<String, String> tableProperties = ImmutableMap.<String, String>builder()
.put(ORC_BLOOM_FILTER_COLUMNS_KEY, "column_with_bloom_filter")
.buildOrThrow();
OrcWriterOptions orcWriterOptions = getOrcWriterOptions(tableProperties, new OrcWriterOptions());
assertThat(orcWriterOptions.getBloomFilterFpp()).isEqualTo(0.05);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,10 @@ private IcebergFileWriter createOrcWriter(
public static OrcWriterOptions withBloomFilterOptions(OrcWriterOptions orcWriterOptions, Map<String, String> storageProperties)
{
if (storageProperties.containsKey(ORC_BLOOM_FILTER_COLUMNS_KEY)) {
if (!storageProperties.containsKey(ORC_BLOOM_FILTER_FPP_KEY)) {
throw new TrinoException(ICEBERG_INVALID_METADATA, "FPP for Bloom filter is missing");
}
try {
double fpp = parseDouble(storageProperties.get(ORC_BLOOM_FILTER_FPP_KEY));
double fpp = storageProperties.containsKey(ORC_BLOOM_FILTER_FPP_KEY)
? parseDouble(storageProperties.get(ORC_BLOOM_FILTER_FPP_KEY))
: orcWriterOptions.getBloomFilterFpp();
return OrcWriterOptions.builderFrom(orcWriterOptions)
.setBloomFilterColumns(ImmutableSet.copyOf(COLUMN_NAMES_SPLITTER.splitToList(storageProperties.get(ORC_BLOOM_FILTER_COLUMNS_KEY))))
.setBloomFilterFpp(fpp)
Expand Down

0 comments on commit 3ef12a1

Please sign in to comment.