|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +package org.apache.doris.datasource.iceberg.source; |
| 19 | + |
| 20 | +import org.apache.doris.datasource.iceberg.IcebergUtils; |
| 21 | + |
| 22 | +import com.google.common.collect.ImmutableMap; |
| 23 | +import org.junit.jupiter.api.Assertions; |
| 24 | +import org.junit.jupiter.api.Test; |
| 25 | + |
| 26 | +import java.util.Collections; |
| 27 | +import java.util.Map; |
| 28 | + |
| 29 | +public class IcebergCountPushDownTest { |
| 30 | + |
| 31 | + private static Map<String, String> summary(String equalityDeletes, String positionDeletes, String totalRecords) { |
| 32 | + ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); |
| 33 | + if (equalityDeletes != null) { |
| 34 | + builder.put(IcebergUtils.TOTAL_EQUALITY_DELETES, equalityDeletes); |
| 35 | + } |
| 36 | + if (positionDeletes != null) { |
| 37 | + builder.put(IcebergUtils.TOTAL_POSITION_DELETES, positionDeletes); |
| 38 | + } |
| 39 | + if (totalRecords != null) { |
| 40 | + builder.put(IcebergUtils.TOTAL_RECORDS, totalRecords); |
| 41 | + } |
| 42 | + return builder.build(); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + public void testMissingCounterFallsBackToScan() { |
| 47 | + // Snapshots written by compaction/replace (and some writers) may omit |
| 48 | + // total-* counters. The pushdown previously NPE'd on the missing key; |
| 49 | + // it must now fall back to a normal scan (return -1). |
| 50 | + Assertions.assertEquals(-1L, IcebergUtils.getCountFromSummary(summary(null, "0", "100"), false)); |
| 51 | + Assertions.assertEquals(-1L, IcebergUtils.getCountFromSummary(summary("0", null, "100"), false)); |
| 52 | + Assertions.assertEquals(-1L, IcebergUtils.getCountFromSummary(summary("0", "0", null), false)); |
| 53 | + Assertions.assertEquals(-1L, IcebergUtils.getCountFromSummary(Collections.emptyMap(), false)); |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + public void testUtilityMissingCounterReturnsUnknownCount() { |
| 58 | + Assertions.assertEquals(-1L, IcebergUtils.getCountFromSummary(summary("0", null, "100"), true)); |
| 59 | + } |
| 60 | + |
| 61 | + @Test |
| 62 | + public void testNoDeletesPushesDownTotalRecords() { |
| 63 | + Assertions.assertEquals(100L, IcebergUtils.getCountFromSummary(summary("0", "0", "100"), false)); |
| 64 | + } |
| 65 | + |
| 66 | + @Test |
| 67 | + public void testEqualityDeletesCannotPushDown() { |
| 68 | + Assertions.assertEquals(-1L, IcebergUtils.getCountFromSummary(summary("3", "0", "100"), false)); |
| 69 | + } |
| 70 | + |
| 71 | + @Test |
| 72 | + public void testPositionDeletesRespectIgnoreDangling() { |
| 73 | + // ignoreDanglingDelete = true -> total-records minus position-deletes |
| 74 | + Assertions.assertEquals(90L, IcebergUtils.getCountFromSummary(summary("0", "10", "100"), true)); |
| 75 | + // ignoreDanglingDelete = false -> cannot push down (fall back to scan) |
| 76 | + Assertions.assertEquals(-1L, IcebergUtils.getCountFromSummary(summary("0", "10", "100"), false)); |
| 77 | + } |
| 78 | + |
| 79 | + @Test |
| 80 | + public void testZeroCountWithPositionDeletesIsPushedDown() { |
| 81 | + // total-records == position-deletes -> count is 0. With ignore_iceberg_dangling_delete this |
| 82 | + // is a valid pushed-down count; FE returns 0 and BE honors it via CountReader(0) (the BE |
| 83 | + // table-level guard accepts table_level_row_count >= 0). It must NOT fall back to -1. |
| 84 | + Assertions.assertEquals(0L, IcebergUtils.getCountFromSummary(summary("0", "100", "100"), true)); |
| 85 | + } |
| 86 | +} |
0 commit comments