|
| 1 | +package org.apache.arrow.datafusion; |
| 2 | + |
| 3 | +import java.util.Optional; |
| 4 | + |
| 5 | +/** Configures options specific to reading Parquet data */ |
| 6 | +@SuppressWarnings("UnusedReturnValue") |
| 7 | +public class ParquetOptions { |
| 8 | + private final SessionConfig config; |
| 9 | + |
| 10 | + ParquetOptions(SessionConfig config) { |
| 11 | + this.config = config; |
| 12 | + } |
| 13 | + |
| 14 | + /** |
| 15 | + * Get whether parquet data page level metadata (Page Index) statistics are used |
| 16 | + * |
| 17 | + * @return whether using the page index is enabled |
| 18 | + */ |
| 19 | + public boolean enablePageIndex() { |
| 20 | + return SessionConfig.getParquetOptionsEnablePageIndex(config.getPointer()); |
| 21 | + } |
| 22 | + |
| 23 | + /** |
| 24 | + * Set whether to use parquet data page level metadata (Page Index) statistics to reduce the |
| 25 | + * number of rows decoded. |
| 26 | + * |
| 27 | + * @param enabled whether using the page index is enabled |
| 28 | + * @return the modified {@link ParquetOptions} instance |
| 29 | + */ |
| 30 | + public ParquetOptions withEnablePageIndex(boolean enabled) { |
| 31 | + SessionConfig.setParquetOptionsEnablePageIndex(config.getPointer(), enabled); |
| 32 | + return this; |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * Get whether pruning is enabled, meaning reading row groups will be skipped based on metadata |
| 37 | + * |
| 38 | + * @return whether pruning is enabled |
| 39 | + */ |
| 40 | + public boolean pruning() { |
| 41 | + return SessionConfig.getParquetOptionsPruning(config.getPointer()); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * Set whether pruning is enabled, meaning reading row groups will be skipped based on metadata |
| 46 | + * |
| 47 | + * @param enabled whether to enable pruning |
| 48 | + * @return the modified {@link ParquetOptions} instance |
| 49 | + */ |
| 50 | + public ParquetOptions withPruning(boolean enabled) { |
| 51 | + SessionConfig.setParquetOptionsPruning(config.getPointer(), enabled); |
| 52 | + return this; |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Get whether file metadata is skipped, to avoid schema conflicts |
| 57 | + * |
| 58 | + * @return whether metadata is skipped |
| 59 | + */ |
| 60 | + public boolean skipMetadata() { |
| 61 | + return SessionConfig.getParquetOptionsSkipMetadata(config.getPointer()); |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * Set whether file metadata is skipped, to avoid schema conflicts |
| 66 | + * |
| 67 | + * @param enabled whether to skip metadata |
| 68 | + * @return the modified {@link ParquetOptions} instance |
| 69 | + */ |
| 70 | + public ParquetOptions withSkipMetadata(boolean enabled) { |
| 71 | + SessionConfig.setParquetOptionsSkipMetadata(config.getPointer(), enabled); |
| 72 | + return this; |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * Get the metadata size hint |
| 77 | + * |
| 78 | + * @return metadata size hint value |
| 79 | + */ |
| 80 | + public Optional<Long> metadataSizeHint() { |
| 81 | + long sizeHint = SessionConfig.getParquetOptionsMetadataSizeHint(config.getPointer()); |
| 82 | + return sizeHint < 0 ? Optional.empty() : Optional.of(sizeHint); |
| 83 | + } |
| 84 | + |
| 85 | + /** |
| 86 | + * Set the metadata size hint, which is used to attempt to read the full metadata at once rather |
| 87 | + * than needing one read to get the metadata size and then a second read for the metadata itself. |
| 88 | + * |
| 89 | + * @param metadataSizeHint the metadata size hint |
| 90 | + * @return the modified {@link ParquetOptions} instance |
| 91 | + */ |
| 92 | + public ParquetOptions withMetadataSizeHint(Optional<Long> metadataSizeHint) { |
| 93 | + long value = -1L; |
| 94 | + if (metadataSizeHint.isPresent()) { |
| 95 | + value = metadataSizeHint.get(); |
| 96 | + if (value < 0) { |
| 97 | + throw new RuntimeException("metadataSizeHint cannot be negative"); |
| 98 | + } |
| 99 | + } |
| 100 | + SessionConfig.setParquetOptionsMetadataSizeHint(config.getPointer(), value); |
| 101 | + return this; |
| 102 | + } |
| 103 | + |
| 104 | + /** |
| 105 | + * Get whether filter pushdown is enabled, so filters are applied during parquet decoding |
| 106 | + * |
| 107 | + * @return whether filter pushdown is enabled |
| 108 | + */ |
| 109 | + public boolean pushdownFilters() { |
| 110 | + return SessionConfig.getParquetOptionsPushdownFilters(config.getPointer()); |
| 111 | + } |
| 112 | + |
| 113 | + /** |
| 114 | + * Set whether filter pushdown is enabled, so filters are applied during parquet decoding |
| 115 | + * |
| 116 | + * @param enabled whether to pushdown filters |
| 117 | + * @return the modified {@link ParquetOptions} instance |
| 118 | + */ |
| 119 | + public ParquetOptions withPushdownFilters(boolean enabled) { |
| 120 | + SessionConfig.setParquetOptionsPushdownFilters(config.getPointer(), enabled); |
| 121 | + return this; |
| 122 | + } |
| 123 | + |
| 124 | + /** |
| 125 | + * Get whether filter reordering is enabled to minimize evaluation cost |
| 126 | + * |
| 127 | + * @return whether filter reordering is enabled |
| 128 | + */ |
| 129 | + public boolean reorderFilters() { |
| 130 | + return SessionConfig.getParquetOptionsReorderFilters(config.getPointer()); |
| 131 | + } |
| 132 | + |
| 133 | + /** |
| 134 | + * Set whether filter reordering is enabled to minimize evaluation cost |
| 135 | + * |
| 136 | + * @param enabled whether to reorder filters |
| 137 | + * @return the modified {@link ParquetOptions} instance |
| 138 | + */ |
| 139 | + public ParquetOptions withReorderFilters(boolean enabled) { |
| 140 | + SessionConfig.setParquetOptionsReorderFilters(config.getPointer(), enabled); |
| 141 | + return this; |
| 142 | + } |
| 143 | +} |
0 commit comments