|
33 | 33 | import org.apache.amoro.shade.guava32.com.google.common.collect.Lists;
|
34 | 34 | import org.apache.amoro.shade.guava32.com.google.common.collect.Maps;
|
35 | 35 | import org.apache.amoro.shade.guava32.com.google.common.collect.Sets;
|
| 36 | +import org.apache.amoro.table.TableProperties; |
36 | 37 | import org.apache.amoro.table.TableSnapshot;
|
37 | 38 | import org.apache.iceberg.DataFile;
|
38 | 39 | import org.apache.iceberg.StructLike;
|
@@ -121,6 +122,83 @@ public void testFragmentFiles() {
|
121 | 122 | assertInput(pendingInput, FileInfo.buildFileInfo(dataFiles));
|
122 | 123 | }
|
123 | 124 |
|
| 125 | + @Test |
| 126 | + public void testFragmentFilesWithPartitionFilterTimeStamp() { |
| 127 | + getMixedTable() |
| 128 | + .updateProperties() |
| 129 | + .set(TableProperties.SELF_OPTIMIZING_FILTER, "op_time >= '2022-01-01T12:00:00'") |
| 130 | + .commit(); |
| 131 | + testFragmentFilesWithPartitionFilterDo(true); |
| 132 | + |
| 133 | + getMixedTable() |
| 134 | + .updateProperties() |
| 135 | + .set(TableProperties.SELF_OPTIMIZING_FILTER, "op_time > '2022-01-01T12:00:00'") |
| 136 | + .commit(); |
| 137 | + testFragmentFilesWithPartitionFilterDo(false); |
| 138 | + } |
| 139 | + |
| 140 | + @Test |
| 141 | + public void testFragmentFilesWithPartitionFilterInteger() { |
| 142 | + getMixedTable() |
| 143 | + .updateProperties() |
| 144 | + .set(TableProperties.SELF_OPTIMIZING_FILTER, "id > 0") |
| 145 | + .commit(); |
| 146 | + testFragmentFilesWithPartitionFilterDo(true); |
| 147 | + |
| 148 | + getMixedTable() |
| 149 | + .updateProperties() |
| 150 | + .set(TableProperties.SELF_OPTIMIZING_FILTER, "id > 8") |
| 151 | + .commit(); |
| 152 | + testFragmentFilesWithPartitionFilterDo(false); |
| 153 | + } |
| 154 | + |
| 155 | + @Test |
| 156 | + public void testFragmentFilesWithPartitionFilterString() { |
| 157 | + getMixedTable() |
| 158 | + .updateProperties() |
| 159 | + .set(TableProperties.SELF_OPTIMIZING_FILTER, "name > '0'") |
| 160 | + .commit(); |
| 161 | + testFragmentFilesWithPartitionFilterDo(true); |
| 162 | + |
| 163 | + getMixedTable() |
| 164 | + .updateProperties() |
| 165 | + .set(TableProperties.SELF_OPTIMIZING_FILTER, "name > '8'") |
| 166 | + .commit(); |
| 167 | + testFragmentFilesWithPartitionFilterDo(false); |
| 168 | + } |
| 169 | + |
| 170 | + private void testFragmentFilesWithPartitionFilterDo(boolean isNecessary) { |
| 171 | + closeFullOptimizingInterval(); |
| 172 | + updateBaseHashBucket(1); |
| 173 | + List<DataFile> dataFiles = Lists.newArrayList(); |
| 174 | + List<Record> newRecords = |
| 175 | + OptimizingTestHelpers.generateRecord(tableTestHelper(), 1, 4, "2022-01-01T12:00:00"); |
| 176 | + long transactionId = beginTransaction(); |
| 177 | + dataFiles.addAll( |
| 178 | + OptimizingTestHelpers.appendBase( |
| 179 | + getMixedTable(), |
| 180 | + tableTestHelper().writeBaseStore(getMixedTable(), transactionId, newRecords, false))); |
| 181 | + |
| 182 | + // add more files |
| 183 | + newRecords = |
| 184 | + OptimizingTestHelpers.generateRecord(tableTestHelper(), 5, 8, "2022-01-01T12:00:00"); |
| 185 | + transactionId = beginTransaction(); |
| 186 | + dataFiles.addAll( |
| 187 | + OptimizingTestHelpers.appendBase( |
| 188 | + getMixedTable(), |
| 189 | + tableTestHelper().writeBaseStore(getMixedTable(), transactionId, newRecords, false))); |
| 190 | + |
| 191 | + AbstractOptimizingEvaluator optimizingEvaluator = buildOptimizingEvaluator(); |
| 192 | + if (isNecessary) { |
| 193 | + Assert.assertTrue(optimizingEvaluator.isNecessary()); |
| 194 | + AbstractOptimizingEvaluator.PendingInput pendingInput = |
| 195 | + optimizingEvaluator.getOptimizingPendingInput(); |
| 196 | + assertInput(pendingInput, FileInfo.buildFileInfo(dataFiles)); |
| 197 | + } else { |
| 198 | + Assert.assertFalse(optimizingEvaluator.isNecessary()); |
| 199 | + } |
| 200 | + } |
| 201 | + |
124 | 202 | protected AbstractOptimizingEvaluator buildOptimizingEvaluator() {
|
125 | 203 | TableSnapshot snapshot = IcebergTableUtil.getSnapshot(getMixedTable(), tableRuntime);
|
126 | 204 | return IcebergTableUtil.createOptimizingEvaluator(tableRuntime, getMixedTable(), snapshot, 100);
|
|
0 commit comments