morningman commented on code in PR #46911: URL: https://github.com/apache/doris/pull/46911#discussion_r1966788091
########## fe/fe-core/src/main/java/org/apache/doris/datasource/paimon/source/PaimonScanNode.java: ########## @@ -295,33 +292,27 @@ public List<Split> getSplits(int numBackends) throws UserException { splitStats.add(splitStat); } + // if applyCountPushdown is true, calcute row count for count pushdown + if (applyCountPushdown) { Review Comment: In this block, you traverse the `paimonSplits` 3 times, which is not efficient. I suggest to use a simple way to do this instead of using `stream()` ``` boolean applyTableCountPushdown = true; long totalCount = 0; long deletionVectorCount = 0; for (org.apache.paimon.table.source.Split s : paimonSplits) { totalCount += s.rowCount(); Optional<List<DeletionFile>> deletionFiles = s.deletionFiles(); if (deletionFiles.isPresent()) { for (DeletionFile dv : deletionFiles.get()) { if (dv != null) { if (dv.cardinality() == null) { applyTableCountPushdown = false; break; } deletionVectorCount += dv.cardinality(); } } } if (!applyTableCountPushdown) { break; } } if (applyTableCountPushdown) { assignCountToSplits(splits, totalCount - deletionVectorCount); } ``` ########## fe/fe-core/src/main/java/org/apache/doris/datasource/paimon/source/PaimonScanNode.java: ########## @@ -245,38 +246,34 @@ public List<Split> getSplits(int numBackends) throws UserException { splitStat.setType(SplitReadType.NATIVE); splitStat.setRawFileConvertable(true); List<RawFile> rawFiles = optRawFiles.get(); - if (optDeletionFiles.isPresent()) { - List<DeletionFile> deletionFiles = optDeletionFiles.get(); - for (int i = 0; i < rawFiles.size(); i++) { - RawFile file = rawFiles.get(i); - DeletionFile deletionFile = deletionFiles.get(i); - LocationPath locationPath = new LocationPath(file.path(), - source.getCatalog().getProperties()); - try { - List<Split> dorisSplits = FileSplitter.splitFile( - locationPath, - getRealFileSplitSize(0), - null, - file.length(), - -1, - true, - null, - PaimonSplit.PaimonSplitCreator.DEFAULT); - for (Split dorisSplit : dorisSplits) { - // the element in DeletionFiles might be null - if (deletionFile != null) { - splitStat.setHasDeletionVector(true); - ((PaimonSplit) dorisSplit).setDeletionFile(deletionFile); - } - splits.add(dorisSplit); + for (int i = 0; i < rawFiles.size(); i++) { + RawFile file = rawFiles.get(i); + LocationPath locationPath = new LocationPath(file.path(), + source.getCatalog().getProperties()); + try { + List<Split> dorisSplits = FileSplitter.splitFile( + locationPath, + // if applyCountPushdown is true, we can't to split the file + // becasue the raw file and deletion vector is one-to-one mapping + getRealFileSplitSize(applyCountPushdown ? Long.MAX_VALUE : 0), + null, + file.length(), + -1, + true, + null, + PaimonSplit.PaimonSplitCreator.DEFAULT); + for (Split dorisSplit : dorisSplits) { + // try to set deletion file + if (optDeletionFiles.isPresent() && optDeletionFiles.get().get(i) != null) { + ((PaimonSplit) dorisSplit).setDeletionFile(optDeletionFiles.get().get(i)); + splitStat.setHasDeletionVector(true); } - ++rawFileSplitNum; - } catch (IOException e) { - throw new UserException("Paimon error to split file: " + e.getMessage(), e); } + splits.addAll(dorisSplits); + ++rawFileSplitNum; + } catch (IOException e) { + throw new UserException("Paimon error to split file: " + e.getMessage(), e); } - } else { - createRawFileSplits(rawFiles, splits, applyCountPushdown ? Long.MAX_VALUE : 0); Review Comment: Why do not need this anymore? ########## regression-test/suites/external_table_p0/paimon/test_paimon_deletion_vector.groovy: ########## @@ -0,0 +1,58 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +suite("test_paimon_deletion_vector", "p0,external,doris,external_docker,external_docker_doris") { + + logger.info("start paimon test") + String enabled = context.config.otherConfigs.get("enablePaimonTest") + if (enabled == null || !enabled.equalsIgnoreCase("true")) { + logger.info("disabled paimon test") + return + } + + try { + String catalog_name = "test_paimon_deletion_vector" + String hdfs_port = context.config.otherConfigs.get("hive2HdfsPort") + String externalEnvIp = context.config.otherConfigs.get("externalEnvIp") + sql """drop catalog if exists ${catalog_name}""" + sql """create catalog if not exists ${catalog_name} properties ( + "type" = "paimon", + "paimon.catalog.type"="filesystem", + "warehouse" = "hdfs://${externalEnvIp}:${hdfs_port}/user/doris/paimon1" + );""" + sql """use `${catalog_name}`.`db1`""" + + def test_cases = { String force -> + sql """ set force_jni_scanner=${force} """ + qt_1 """select count(*) from deletion_vector_orc;""" Review Comment: 2 questions: 1. Is your paimon table generated by paimon 1.0? 2. How to make sure that `count(*)` optimization is work? better test it by, eg, checking the info in `explain` result? ########## fe/fe-core/src/main/java/org/apache/doris/datasource/paimon/source/PaimonScanNode.java: ########## @@ -295,33 +292,27 @@ public List<Split> getSplits(int numBackends) throws UserException { splitStats.add(splitStat); } + // if applyCountPushdown is true, calcute row count for count pushdown + if (applyCountPushdown) { Review Comment: And please add UT for this logic, here is the test case generated by Cursor, I didn't run it, but maybe can help you: ``` package org.apache.doris.datasource.paimon.source; import org.apache.doris.analysis.TupleDescriptor; import org.apache.doris.planner.PlanNodeId; import org.apache.doris.qe.SessionVariable; import org.apache.doris.spi.Split; import org.apache.doris.thrift.TPushAggOp; import org.apache.paimon.table.source.DeletionFile; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Optional; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; public class PaimonScanNodeTest { @Mock private TupleDescriptor tupleDescriptor; @Mock private SessionVariable sessionVariable; private PaimonScanNode scanNode; @Before public void setUp() { MockitoAnnotations.initMocks(this); scanNode = new PaimonScanNode(new PlanNodeId(1), tupleDescriptor, false, sessionVariable); } @Test public void testNoDeleteVector() { // Prepare test data List<org.apache.paimon.table.source.Split> paimonSplits = new ArrayList<>(); // Create 3 splits without deletion files for (int i = 0; i < 3; i++) { org.apache.paimon.table.source.Split split = mock(org.apache.paimon.table.source.Split.class); when(split.rowCount()).thenReturn(100L); when(split.deletionFiles()).thenReturn(Optional.empty()); paimonSplits.add(split); } List<Split> splits = createPaimonSplits(paimonSplits); // Test count pushdown scanNode.assignCountToSplits(splits, 300L); // Verify results for (Split split : splits) { assertEquals(100L, ((PaimonSplit) split).getRowCount().get().longValue()); } } @Test public void testAllDeleteVectorsWithCardinality() { List<org.apache.paimon.table.source.Split> paimonSplits = new ArrayList<>(); // Create 3 splits with deletion files that have cardinality for (int i = 0; i < 3; i++) { org.apache.paimon.table.source.Split split = mock(org.apache.paimon.table.source.Split.class); when(split.rowCount()).thenReturn(100L); DeletionFile deletionFile = mock(DeletionFile.class); when(deletionFile.cardinality()).thenReturn(20L); when(split.deletionFiles()).thenReturn(Optional.of(Arrays.asList(deletionFile))); paimonSplits.add(split); } List<Split> splits = createPaimonSplits(paimonSplits); // Total count should be 300 - (3 * 20) = 240 scanNode.assignCountToSplits(splits, 240L); // Verify results (240 / 3 = 80 per split) for (Split split : splits) { assertEquals(80L, ((PaimonSplit) split).getRowCount().get().longValue()); } } @Test public void testSomeDeleteVectorsWithoutCardinality() { List<org.apache.paimon.table.source.Split> paimonSplits = new ArrayList<>(); // Create 2 splits with cardinality and 1 without for (int i = 0; i < 3; i++) { org.apache.paimon.table.source.Split split = mock(org.apache.paimon.table.source.Split.class); when(split.rowCount()).thenReturn(100L); DeletionFile deletionFile = mock(DeletionFile.class); // Third split has no cardinality when(deletionFile.cardinality()).thenReturn(i == 2 ? null : 20L); when(split.deletionFiles()).thenReturn(Optional.of(Arrays.asList(deletionFile))); paimonSplits.add(split); } List<Split> splits = createPaimonSplits(paimonSplits); // Should not apply count pushdown when some deletion vectors don't have cardinality for (Split split : splits) { assertEquals(Optional.empty(), ((PaimonSplit) split).getRowCount()); } } @Test public void testMixedDeleteVectors() { List<org.apache.paimon.table.source.Split> paimonSplits = new ArrayList<>(); // First split: no deletion file org.apache.paimon.table.source.Split split1 = mock(org.apache.paimon.table.source.Split.class); when(split1.rowCount()).thenReturn(100L); when(split1.deletionFiles()).thenReturn(Optional.empty()); paimonSplits.add(split1); // Second split: with deletion file and cardinality org.apache.paimon.table.source.Split split2 = mock(org.apache.paimon.table.source.Split.class); when(split2.rowCount()).thenReturn(100L); DeletionFile deletionFile2 = mock(DeletionFile.class); when(deletionFile2.cardinality()).thenReturn(20L); when(split2.deletionFiles()).thenReturn(Optional.of(Arrays.asList(deletionFile2))); paimonSplits.add(split2); // Third split: with null deletion file org.apache.paimon.table.source.Split split3 = mock(org.apache.paimon.table.source.Split.class); when(split3.rowCount()).thenReturn(100L); when(split3.deletionFiles()).thenReturn(Optional.of(Arrays.asList((DeletionFile) null))); paimonSplits.add(split3); List<Split> splits = createPaimonSplits(paimonSplits); // Total count should be 300 - 20 = 280 scanNode.assignCountToSplits(splits, 280L); // Verify results (280 / 3 ≈ 93.33 per split) assertEquals(93L, ((PaimonSplit) splits.get(0)).getRowCount().get().longValue()); assertEquals(93L, ((PaimonSplit) splits.get(1)).getRowCount().get().longValue()); assertEquals(94L, ((PaimonSplit) splits.get(2)).getRowCount().get().longValue()); } private List<Split> createPaimonSplits(List<org.apache.paimon.table.source.Split> paimonSplits) { List<Split> splits = new ArrayList<>(); for (org.apache.paimon.table.source.Split paimonSplit : paimonSplits) { splits.add(new PaimonSplit(paimonSplit)); } return splits; } } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org