Copilot commented on code in PR #62780:
URL: https://github.com/apache/doris/pull/62780#discussion_r3135756256


##########
be/test/format/table/reader_test_util.h:
##########
@@ -0,0 +1,155 @@
+#pragma once
+
+#include <gtest/gtest.h>
+
+#include <functional>
+#include <iostream>
+#include <string>
+#include <vector>
+
+#include "core/assert_cast.h"
+#include "core/block/block.h"
+#include "core/block/column_with_type_and_name.h"
+#include "core/column/column.h"
+#include "core/column/column_array.h"
+#include "core/column/column_nullable.h"
+#include "core/column/column_struct.h"
+#include "core/data_type/data_type.h"
+#include "core/data_type/data_type_array.h"
+#include "core/data_type/data_type_map.h"
+#include "core/data_type/data_type_nullable.h"
+#include "core/data_type/data_type_number.h"
+#include "core/data_type/data_type_string.h"
+#include "core/data_type/data_type_struct.h"
+
+namespace doris::reader_test {
+
+inline const std::vector<std::string>& default_nested_reader_column_names() {
+    static const std::vector<std::string> names = {"name", "profile"};
+    return names;
+}
+
+inline void create_complex_user_profile_types(
+        DataTypePtr& coordinates_struct_type, DataTypePtr& address_struct_type,
+        DataTypePtr& phone_struct_type, DataTypePtr& contact_struct_type,
+        DataTypePtr& hobby_element_struct_type, DataTypePtr& 
hobbies_array_type,
+        DataTypePtr& profile_struct_type, DataTypePtr& name_type) {
+    name_type = make_nullable(std::make_shared<DataTypeString>());
+
+    std::vector<DataTypePtr> coordinates_types = {
+            make_nullable(std::make_shared<DataTypeFloat64>()),
+            make_nullable(std::make_shared<DataTypeFloat64>())};
+    std::vector<std::string> coordinates_names = {"lat", "lng"};
+    coordinates_struct_type =
+            make_nullable(std::make_shared<DataTypeStruct>(coordinates_types, 
coordinates_names));
+
+    std::vector<DataTypePtr> address_types = 
{make_nullable(std::make_shared<DataTypeString>()),
+                                              
make_nullable(std::make_shared<DataTypeString>()),
+                                              coordinates_struct_type};
+    std::vector<std::string> address_names = {"street", "city", "coordinates"};
+    address_struct_type =
+            make_nullable(std::make_shared<DataTypeStruct>(address_types, 
address_names));
+
+    std::vector<DataTypePtr> phone_types = 
{make_nullable(std::make_shared<DataTypeString>()),
+                                            
make_nullable(std::make_shared<DataTypeString>())};
+    std::vector<std::string> phone_names = {"country_code", "number"};
+    phone_struct_type = 
make_nullable(std::make_shared<DataTypeStruct>(phone_types, phone_names));
+
+    std::vector<DataTypePtr> contact_types = 
{make_nullable(std::make_shared<DataTypeString>()),
+                                              phone_struct_type};
+    std::vector<std::string> contact_names = {"email", "phone"};
+    contact_struct_type =
+            make_nullable(std::make_shared<DataTypeStruct>(contact_types, 
contact_names));
+
+    std::vector<DataTypePtr> hobby_element_types = {
+            make_nullable(std::make_shared<DataTypeString>()),
+            make_nullable(std::make_shared<DataTypeInt32>())};
+    std::vector<std::string> hobby_element_names = {"name", "level"};
+    hobby_element_struct_type = make_nullable(
+            std::make_shared<DataTypeStruct>(hobby_element_types, 
hobby_element_names));
+
+    hobbies_array_type = 
make_nullable(std::make_shared<DataTypeArray>(hobby_element_struct_type));
+
+    std::vector<DataTypePtr> profile_types = {address_struct_type, 
contact_struct_type,
+                                              hobbies_array_type};
+    std::vector<std::string> profile_names = {"address", "contact", "hobbies"};
+    profile_struct_type =
+            make_nullable(std::make_shared<DataTypeStruct>(profile_types, 
profile_names));
+}
+
+inline Block make_name_profile_block(const DataTypePtr& name_type,
+                                     const DataTypePtr& profile_struct_type) {
+    Block block;
+    block.insert(ColumnWithTypeAndName(name_type->create_column(), name_type, 
"name"));
+    block.insert(ColumnWithTypeAndName(profile_struct_type->create_column(), 
profile_struct_type,
+                                       "profile"));
+    return block;
+}
+
+inline void verify_nested_reader_block(Block& block, size_t read_rows,
+                                       const std::vector<std::string>& 
expected_column_names =
+                                               
default_nested_reader_column_names()) {
+    EXPECT_GT(read_rows, 0) << "Should read at least one row";
+    EXPECT_EQ(block.rows(), read_rows);
+    EXPECT_EQ(block.columns(), expected_column_names.size());
+
+    auto columns_with_names = block.get_columns_with_type_and_name();
+    for (size_t i = 0; i < expected_column_names.size(); ++i) {
+        EXPECT_EQ(columns_with_names[i].name, expected_column_names[i]);
+    }
+
+    EXPECT_TRUE(columns_with_names[0].type->get_name().find("String") != 
std::string::npos);
+    EXPECT_TRUE(columns_with_names[1].type->get_name().find("Struct") != 
std::string::npos);
+
+    std::cout << "Block rows: " << block.rows() << std::endl;
+
+    std::function<void(const ColumnPtr&, const DataTypePtr&, const 
std::string&, int, bool)>
+            print_column_rows = [&](const ColumnPtr& col, const DataTypePtr& 
type,
+                                    const std::string& name, int depth, bool 
allow_empty) {
+                std::string indent(depth * 2, ' ');
+                std::cout << indent << name << " row count: " << col->size() 
<< std::endl;
+                if (!allow_empty) {

Review Comment:
   verify_nested_reader_block prints to stdout unconditionally, which will spam 
CI logs and slow down unit test runs. Please remove these std::cout diagnostics 
or gate them behind a debug flag / only print on assertion failure.



##########
be/test/format/jni/paimon_jni_reader_real_test.cpp:
##########
@@ -0,0 +1,279 @@
+// 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.
+
+#include <gtest/gtest.h>
+
+#include <array>
+#include <cstdio>
+#include <cstdlib>
+#include <filesystem>
+#include <fstream>
+#include <memory>
+#include <sstream>
+#include <string>
+#include <vector>
+
+#include "common/status.h"
+#include "core/assert_cast.h"
+#include "core/block/block.h"
+#include "core/column/column_nullable.h"
+#include "core/column/column_vector.h"
+#include "core/data_type/data_type_number.h"
+#include "format/table/paimon_jni_reader.h"
+#include "runtime/runtime_profile.h"
+#include "runtime/runtime_state.h"
+#include "testutil/desc_tbl_builder.h"
+#include "util/jni-util.h"
+
+namespace doris {
+
+class PaimonJniReaderRealTest : public testing::Test {
+protected:
+    struct SerializedPaimonInputs {
+        std::string serialized_table;
+        std::string serialized_split;
+        std::string serialized_predicate;
+    };
+
+    void SetUp() override {
+        _query_options.__set_batch_size(16);
+        _runtime_state = std::make_unique<RuntimeState>(_query_options, 
_query_globals);
+        _runtime_state->set_timezone("UTC");
+    }
+
+    std::vector<SlotDescriptor*> build_file_slot_descs() {
+        DescriptorTblBuilder builder(&_object_pool);
+        builder.declare_tuple() << 
std::make_tuple(std::make_shared<DataTypeInt32>(), "id");
+        return builder.build()->get_tuple_descriptor(0)->slots();
+    }
+
+    static Block make_block(const std::vector<SlotDescriptor*>& slots) {
+        Block block;
+        for (auto* slot : slots) {
+            auto type = slot->get_data_type_ptr();
+            block.insert({type->create_column(), type, slot->col_name()});
+        }
+        return block;
+    }
+
+    static std::filesystem::path repo_root() {
+        const char* root = std::getenv("ROOT");
+        DORIS_CHECK(root != nullptr);
+        return root;
+    }
+
+    static std::filesystem::path paimon_warehouse_root() {
+        return repo_root() / 
"docker/thirdparties/docker-compose/hive/scripts/paimon1";
+    }
+
+    static std::string shell_quote(const std::string& value) {
+        std::string quoted = "'";
+        for (char ch : value) {
+            if (ch == '\'') {
+                quoted.append("'\"'\"'");
+            } else {
+                quoted.push_back(ch);
+            }
+        }
+        quoted.push_back('\'');
+        return quoted;
+    }
+
+    static std::string run_command_and_capture_output(const std::string& 
command) {
+        std::array<char, 4096> buffer {};
+        std::string output;
+        FILE* pipe = popen(command.c_str(), "r");
+        DORIS_CHECK(pipe != nullptr);
+        while (fgets(buffer.data(), static_cast<int>(buffer.size()), pipe) != 
nullptr) {
+            output.append(buffer.data());
+        }
+        const int exit_code = pclose(pipe);
+        CHECK_EQ(exit_code, 0) << output;
+        return output;
+    }
+
+    static SerializedPaimonInputs build_serialized_inputs() {
+        const auto helper_dir =
+                std::filesystem::temp_directory_path() / 
"paimon_jni_reader_real_test_helper";
+        std::filesystem::remove_all(helper_dir);
+        std::filesystem::create_directories(helper_dir);
+
+        const auto helper_source = helper_dir / 
"PaimonSerializationHelper.java";
+        std::ofstream out(helper_source);
+        out << R"(import org.apache.paimon.catalog.Catalog;
+import org.apache.paimon.catalog.CatalogContext;
+import org.apache.paimon.catalog.CatalogFactory;
+import org.apache.paimon.catalog.Identifier;
+import org.apache.paimon.options.Options;
+import org.apache.paimon.predicate.Predicate;
+import org.apache.paimon.predicate.PredicateBuilder;
+import org.apache.paimon.table.Table;
+import org.apache.paimon.table.source.Split;
+import org.apache.paimon.utils.InstantiationUtil;
+
+import java.util.Base64;
+import java.util.Collections;
+import java.util.List;
+
+public class PaimonSerializationHelper {
+    private static String encodeObject(Object value) throws Exception {
+        return 
Base64.getEncoder().encodeToString(InstantiationUtil.serializeObject(value));
+    }
+
+    public static void main(String[] args) throws Exception {
+        Options options = new Options();
+        options.setString("warehouse", args[0]);
+        Catalog catalog = 
CatalogFactory.createCatalog(CatalogContext.create(options));
+        Table table = catalog.getTable(Identifier.create(args[1], args[2]));
+        List<Split> splits = table.newReadBuilder().newScan().plan().splits();
+        if (splits.size() != 1) {
+            throw new IllegalStateException("Expected exactly one split but 
got " + splits.size());
+        }
+
+        PredicateBuilder predicateBuilder = new 
PredicateBuilder(table.rowType());
+        Predicate predicate = 
predicateBuilder.greaterOrEqual(predicateBuilder.indexOf("id"), 2);
+
+        System.out.println("TABLE=" + encodeObject(table));
+        System.out.println("SPLIT=" + encodeObject(splits.get(0)));
+        System.out.println("PREDICATE=" + 
encodeObject(Collections.singletonList(predicate)));
+        catalog.close();
+    }
+}
+)";
+        out.close();
+        DORIS_CHECK(out.good());
+
+        std::string classpath = (repo_root() /
+                                 
"output/be/lib/java_extensions/paimon-scanner/"
+                                 "paimon-scanner-jar-with-dependencies.jar")
+                                        .string();
+        const auto hadoop_deps_root = repo_root() / 
"output/be/lib/hadoop_hdfs";
+        for (const auto& entry : 
std::filesystem::directory_iterator(hadoop_deps_root)) {
+            if (entry.is_regular_file() && entry.path().extension() == ".jar") 
{
+                classpath.append(":").append(entry.path().string());
+            }
+        }
+        if (std::filesystem::exists(hadoop_deps_root / "lib")) {
+            for (const auto& entry :
+                 std::filesystem::directory_iterator(hadoop_deps_root / 
"lib")) {
+                if (entry.is_regular_file() && entry.path().extension() == 
".jar") {
+                    classpath.append(":").append(entry.path().string());
+                }
+            }
+        }
+
+        const auto java_bin = std::filesystem::path(std::getenv("JAVA_HOME")) 
/ "bin/java";
+        DORIS_CHECK(std::filesystem::exists(java_bin));

Review Comment:
   This test depends on external environment (ROOT, JAVA_HOME), local build 
artifacts under output/be/lib, and iterating output/be/lib/hadoop_hdfs without 
checking it exists (directory_iterator will throw). To avoid flaky/unit-test 
failures, please add prerequisite checks and GTEST_SKIP() when env 
vars/directories/jars aren’t present, or move this to an 
integration/real-environment test target.



##########
be/test/format/table/transactional_hive_common_test.cpp:
##########
@@ -0,0 +1,275 @@
+// 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.
+
+#include "format/table/transactional_hive_common.h"
+
+#include <gtest/gtest.h>
+
+#include <algorithm>
+#include <string>
+#include <unordered_set>
+#include <vector>
+
+namespace doris {
+
+// ============================================================================
+// AcidRowID — Hash, Equality, Ordering
+// ============================================================================
+class AcidRowIDTest : public ::testing::Test {};
+
+TEST_F(AcidRowIDTest, EqualityBasic) {
+    AcidRowID a {100, 0, 42};
+    AcidRowID b {100, 0, 42};
+    AcidRowID c {100, 0, 43};
+    AcidRowID::Eq eq;
+    EXPECT_TRUE(eq(a, b));
+    EXPECT_FALSE(eq(a, c));
+}
+
+TEST_F(AcidRowIDTest, EqualityDiffTransaction) {
+    AcidRowID a {100, 0, 42};
+    AcidRowID b {101, 0, 42};
+    AcidRowID::Eq eq;
+    EXPECT_FALSE(eq(a, b));
+}
+
+TEST_F(AcidRowIDTest, EqualityDiffBucket) {
+    AcidRowID a {100, 0, 42};
+    AcidRowID b {100, 1, 42};
+    AcidRowID::Eq eq;
+    EXPECT_FALSE(eq(a, b));
+}
+
+TEST_F(AcidRowIDTest, HashConsistency) {
+    AcidRowID a {100, 0, 42};
+    AcidRowID b {100, 0, 42};
+    AcidRowID::Hash hasher;
+    EXPECT_EQ(hasher(a), hasher(b));
+}
+
+TEST_F(AcidRowIDTest, HashDistribution) {
+    AcidRowID::Hash hasher;
+    // Different row IDs should produce different hashes (probabilistic)
+    AcidRowID a {100, 0, 1};
+    AcidRowID b {100, 0, 2};
+    AcidRowID c {200, 0, 1};
+    // While hash collisions are possible, these specific inputs should differ
+    EXPECT_NE(hasher(a), hasher(b));
+    EXPECT_NE(hasher(a), hasher(c));

Review Comment:
   This test asserts that different inputs produce different hash values. Hash 
collisions are allowed by contract, so this can be flaky (even if unlikely) and 
may fail if the hash implementation changes. Consider removing the EXPECT_NE 
checks and instead validate that the hash is stable and that unordered 
containers using AcidRowID::Hash/Eq behave correctly.
   



##########
be/test/format/table/paimon_cpp_reader_test.cpp:
##########
@@ -78,6 +98,24 @@ TEST_F(PaimonCppReaderTest, 
CountPushDownUsesTableLevelRowCount) {
     EXPECT_TRUE(eof);
 }
 
+TEST_F(PaimonCppReaderTest, CountPushDownHandlesZeroTableLevelRowCount) {
+    auto range = _build_range_with_table_level_row_count(0);
+    PaimonCppReader reader(_file_slot_descs, _runtime_state.get(), &_profile, 
range, nullptr);
+    reader.set_push_down_agg_type(TPushAggOp::type::COUNT);
+

Review Comment:
   This new test uses _file_slot_descs, but the fixture never initializes it 
(so it stays empty). That makes the test less representative and can miss 
failures in code paths that depend on slot descriptors. Consider populating 
_file_slot_descs in SetUp (e.g., via _build_file_slot_descs) or constructing 
the reader with explicit slot descs in this test.



##########
be/test/format/orc/orc_reader_test.cpp:
##########
@@ -181,4 +263,26 @@ TEST_F(OrcReaderTest, test_build_search_argument) {
     }
 }
 
+TEST_F(OrcReaderTest, test_read_orc_line_smoke) {
+    size_t read_rows = 0;
+    bool eof = false;
+    auto block_dump = read_orc_line_dump(0, &read_rows, &eof);
+    EXPECT_EQ(read_rows, 1);
+    EXPECT_EQ(
+            block_dump,
+            
"+----------------------+--------------------+----------------------+------------------"
+            
"----+----------------------+---------------------+-------------------+----------------"
+            
"--------+----------------------+\n|col1(Nullable(BIGINT))|col2(Nullable(BOOL))|col3("
+            
"Nullable(String))|col4(Nullable(DateV2))|col5(Nullable(DOUBLE))|col6(Nullable(FLOAT))|"
+            
"col7(Nullable(INT))|col8(Nullable(SMALLINT))|col9(Nullable(String))|\n+---------------"
+            
"-------+--------------------+----------------------+----------------------+-----------"
+            
"-----------+---------------------+-------------------+------------------------+-------"
+            "---------------+\n|                     0|                NULL|   
              "
+            "doris|                  NULL|                 1.567|              
  1.567|            "
+            "  12345|                       1|                 "
+            
"doris|\n+----------------------+--------------------+----------------------+----------"
+            
"------------+----------------------+---------------------+-------------------+--------"
+            "----------------+----------------------+\n");

Review Comment:
   This smoke test compares the full Block::dump_data output string, which is 
very brittle (formatting changes, padding, type names, etc. will break it). 
Consider asserting on key substrings/values (e.g., expected column names and a 
couple of cell values) instead of exact dump formatting.
   



##########
run-be-ut.sh:
##########
@@ -397,6 +428,10 @@ if [[ -d "${LIB_DIR}/hadoop_hdfs/" ]]; then
     done
 fi
 
+if [[ -n "${DORIS_PRELOAD_JAR}" ]]; then
+    DORIS_CLASSPATH="${DORIS_PRELOAD_JAR}:${DORIS_CLASSPATH}"

Review Comment:
   When DORIS_PRELOAD_JAR is set but no other jars were added, this builds a 
classpath like "<jar>:" (empty trailing element). In Java classpaths an empty 
element maps to the current working directory, which can change test behavior 
and is a security footgun. Please only prepend with ':' when DORIS_CLASSPATH is 
non-empty (or build the classpath via an array join).
   



##########
fe/fe-core/src/test/java/org/apache/doris/datasource/paimon/source/PaimonScanNodeTest.java:
##########
@@ -457,6 +457,60 @@ public void 
testPaimonDataSystemTableForceJniEvenWhenNativeSupported() throws Us
         Assert.assertNotNull(((PaimonSplit) auditLogSplits.get(0)).getSplit());
     }
 
+    @Test
+    public void testMixedNativeAndJniSplits() throws UserException {
+        TupleDescriptor desc = new TupleDescriptor(new TupleId(3));
+        PaimonScanNode paimonScanNode = new PaimonScanNode(new PlanNodeId(1), 
desc, false, sv, ScanContext.EMPTY);
+        PaimonScanNode spyPaimonScanNode = Mockito.spy(paimonScanNode);
+
+        DataSplit nativeSplit = createDataSplit("native.parquet", true);
+        DataSplit jniSplit = createDataSplit("jni.binary", false);
+        Mockito.doReturn(new ArrayList<org.apache.paimon.table.source.Split>() 
{
+            {
+                add(nativeSplit);
+                add(jniSplit);
+            }
+        }).when(spyPaimonScanNode).getPaimonSplitFromAPI();

Review Comment:
   Avoid double-brace initialization here (anonymous ArrayList subclass). It 
creates an extra class, can capture the outer instance, and is generally 
discouraged; a plain List.of/Arrays.asList wrapped in a new ArrayList is 
clearer and avoids side effects.
   



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to