This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 2ed7dc60c5b [fix](orc) Preserve signed zero equivalence in Bloom 
pruning (#70862)
2ed7dc60c5b is described below

commit 2ed7dc60c5bc327cd744999409cf9ea779ccba60
Author: Gabriel <[email protected]>
AuthorDate: Mon Nov 23 21:32:07 2026 +0800

    [fix](orc) Preserve signed zero equivalence in Bloom pruning (#70862)
    
    ### Background
    
    Doris translates supported ORC scan predicates into search arguments.
    The ORC library uses file statistics and Bloom filters to skip stripes
    or row groups before Doris evaluates SQL predicates on the remaining
    rows.
    
    ### What problem does this PR solve?
    
    Issue Number: None
    Related PR: #65183 (introduced the current SARG builder; the legacy path
    was already affected)
    PR Type: Bugfix
    
    Problem Summary:
    
    ORC scans with floating-point Bloom filters can omit matching rows when
    a zero predicate and stored zeros have opposite signs. This change
    probes both zero bit patterns in one IN leaf so pruning preserves SQL's
    equality of positive and negative zero. Most of the diff adds real-file
    unit and SQL regression coverage.
    
    For the checked-in row-group fixture, a count with `WHERE d = 0.0` and
    SARG enabled produced:
    
    | Before | After | Expected |
    | --- | --- | --- |
    | 1000 | 2000 | 2000 |
    
    ### Details
    
    - **Change map:** Production code +22/-11; tests and fixture generator
    +403/-0; generated regression output +13/-0; documentation +0/-0. Two
    ORC fixtures total 132,252 bytes. Tests account for most of the change.
    - **Frequency:** Always in the reproduced layout: zero signs occupy
    different Bloom filters, and pruning probes only the opposite sign. It
    affects FLOAT and DOUBLE equality, null-safe equality and IN predicates.
    - **Root cause:** ORC Bloom filters hash the raw floating-point bits,
    while SQL equates both signs of zero. The SARG builder previously
    supplied only the literal's sign, allowing a matching group to be
    rejected before row filtering.
    - **Why existing tests missed it:**
    `NewOrcReaderTest.SargFloatWideningCastConjunctPrunesStripes` covers
    floating ranges without signed-zero Bloom filters, while the binary
    Bloom tests cover strings. The closest SQL suite,
    `test_orc_condition_cache_seek`, covers integer seek/cache behavior.
    Neither layer tests opposite-sign zero groups. The new SQL suite is in
    the External pipeline's `p0,external` group.
    - **Fix:** Normalize zero equality and IN candidates at the shared Doris
    SARG adapter by adding the opposite sign to one IN leaf. ORC merges
    separate equality leaves for the two signs, so an OR of equalities would
    still be unsafe. Nonzero equality and IN Bloom pruning remain covered.
    - **Other paths and branches:** This fixes the native ORC SARG path
    shared by TVFs and catalogs on master. Parquet uses a separate
    implementation. Static checks found the same defect in branch-3.1,
    branch-4.0, branch-4.1 and branch-4.2; those need separate backports,
    including legacy reader paths where present. Release branches were not
    dynamically tested. #65183 introduced the current builder, not the
    original defect.
    
    ### Testing
    
    - Locally ran 20 new parameterized real-ORC tests across FLOAT/DOUBLE
    and row-group/stripe layouts. Before the fix, 12 equality/IN tests
    failed and eight controls passed; after it, all 20 passed. Together with
    the existing `NewOrcReaderTest` suite, all 217 ASAN tests passed.
    - Locally ran `run-regression-test.sh --run -d external_table_p0/tvf -s
    test_orc_signed_zero_bloom`, after generating output through the runner.
    All 336 complete ordered-ID comparisons passed with SARG and lazy
    materialization each on/off, both column widths and both layouts; one
    suite, zero failures and zero skips. The baseline failed by losing the
    negative-zero IDs.
    - Regenerated both fixtures byte-for-byte and independently decoded
    their zero signs, NULLs and stripe layouts with PyArrow.
    
    ### Notes for Reviewers
    
    SQL regression ran against a disposable local S3 emulator.
    Provider-specific remote S3 and Azure uploads were not exercised
    locally; the suite follows the existing provider-aware upload and
    cleanup pattern.
    
    ### Release note
    
    Fix missing rows in ORC scans when floating-point Bloom pruning
    encounters equality or IN predicates involving positive and negative
    zero.
    
    ### Check List (For Author)
    
    - Behavior changed: No
    - Does this need documentation: No
    - Pre-submission status: Ready
    
    ### AI Disclosure
    
    - Tool: Codex (GPT-6)
    - Generated: Code, unit tests, regression tests, fixture generator and
    this description.
    - Human review: Not stated by the author.
---
 be/src/format_v2/orc/orc_search_argument.cpp       |  33 ++--
 be/test/format_v2/orc/orc_search_argument_test.cpp | 218 +++++++++++++++++++++
 .../tvf/test_data/GenerateOrcSignedZeroBloom.cpp   |  65 ++++++
 .../tvf/test_data/signed_zero_bloom_row_groups.orc | Bin 0 -> 65829 bytes
 .../tvf/test_data/signed_zero_bloom_stripes.orc    | Bin 0 -> 66423 bytes
 .../tvf/test_orc_signed_zero_bloom.out             |  13 ++
 .../tvf/test_orc_signed_zero_bloom.groovy          | 120 ++++++++++++
 7 files changed, 438 insertions(+), 11 deletions(-)

diff --git a/be/src/format_v2/orc/orc_search_argument.cpp 
b/be/src/format_v2/orc/orc_search_argument.cpp
index 0b91596a17a..96dabf207da 100644
--- a/be/src/format_v2/orc/orc_search_argument.cpp
+++ b/be/src/format_v2/orc/orc_search_argument.cpp
@@ -1336,6 +1336,25 @@ bool can_emit_timestamp_sarg(const OrcSargColumn& 
column, const cctz::time_zone&
     return TimezoneUtils::try_get_fixed_offset_seconds(timezone, 
&offset_seconds);
 }
 
+OrcSargNode make_in_node(OrcSargColumn column, std::vector<::orc::Literal> 
literals) {
+    DORIS_CHECK(!literals.empty());
+    // SQL equates signed zeros, but ORC Bloom filters hash their different 
bit patterns.
+    // Keep both in one IN leaf: separate x = +0 and x = -0 leaves are merged 
by ORC.
+    if (column.predicate_type == ::orc::PredicateDataType::FLOAT) {
+        const auto zero = std::ranges::find_if(
+                literals, [](const auto& literal) { return literal.getFloat() 
== 0.0; });
+        if (zero != literals.end()) {
+            literals.emplace_back(-zero->getFloat());
+        }
+    }
+    return OrcSargNode {
+            .kind = literals.size() == 1 ? OrcSargNodeKind::EQUALS : 
OrcSargNodeKind::IN,
+            .column = column,
+            .literals = std::move(literals),
+            .children = {},
+    };
+}
+
 OrcSargNode make_comparison_node(OrcSargComparison comparison) {
     OrcSargNodeKind kind;
     bool negate = false;
@@ -1367,23 +1386,15 @@ OrcSargNode make_comparison_node(OrcSargComparison 
comparison) {
         __builtin_unreachable();
     }
 
-    auto node = make_literal_node(kind, comparison.column, 
std::move(comparison.literal));
+    auto node = kind == OrcSargNodeKind::EQUALS
+                        ? make_in_node(comparison.column, {comparison.literal})
+                        : make_literal_node(kind, comparison.column, 
comparison.literal);
     if (negate) {
         return make_not_node(std::move(node));
     }
     return node;
 }
 
-OrcSargNode make_in_node(OrcSargColumn column, std::vector<::orc::Literal> 
literals) {
-    DORIS_CHECK(!literals.empty());
-    return OrcSargNode {
-            .kind = literals.size() == 1 ? OrcSargNodeKind::EQUALS : 
OrcSargNodeKind::IN,
-            .column = column,
-            .literals = std::move(literals),
-            .children = {},
-    };
-}
-
 OrcSargNode make_is_null_node(OrcSargColumn column) {
     return OrcSargNode {
             .kind = OrcSargNodeKind::IS_NULL,
diff --git a/be/test/format_v2/orc/orc_search_argument_test.cpp 
b/be/test/format_v2/orc/orc_search_argument_test.cpp
new file mode 100644
index 00000000000..426fb42a9e4
--- /dev/null
+++ b/be/test/format_v2/orc/orc_search_argument_test.cpp
@@ -0,0 +1,218 @@
+// 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_v2/orc/orc_search_argument.h"
+
+#include <gtest/gtest.h>
+
+#include <memory>
+#include <numeric>
+#include <orc/OrcFile.hh>
+#include <orc/sargs/SearchArgument.hh>
+#include <string>
+#include <tuple>
+#include <vector>
+
+#include "core/data_type/data_type_nullable.h"
+#include "core/data_type/data_type_number.h"
+#include "core/field.h"
+#include "exprs/vectorized_fn_call.h"
+#include "exprs/vin_predicate.h"
+#include "exprs/vliteral.h"
+#include "exprs/vslot_ref.h"
+#include "format/orc/orc_memory_stream_test.h"
+
+namespace doris {
+namespace {
+
+class OrcSearchArgumentSignedZeroTest : public 
testing::TestWithParam<std::tuple<bool, bool>> {
+protected:
+    static constexpr int64_t ROWS_PER_GROUP = 1000;
+
+    void SetUp() override {
+        const auto [use_float, multiple_stripes] = GetParam();
+        _value_type = use_float ? 
DataTypePtr(std::make_shared<DataTypeFloat32>())
+                                : 
DataTypePtr(std::make_shared<DataTypeFloat64>());
+        _type = ::orc::Type::buildTypeFromString(use_float ? 
"struct<id:bigint,value:float>"
+                                                           : 
"struct<id:bigint,value:double>");
+        MemoryOutputStream output(1024 * 1024);
+        ::orc::WriterOptions options;
+        options.setRowIndexStride(ROWS_PER_GROUP)
+                .setStripeSize(multiple_stripes ? 1 : 1024 * 1024)
+                .setColumnsUseBloomFilter({2})
+                .setBloomFilterFPP(0.000001)
+                .setCompression(::orc::CompressionKind_NONE);
+        auto writer = ::orc::createWriter(*_type, &output, options);
+        auto batch = writer->createRowBatch(ROWS_PER_GROUP);
+        auto& root = dynamic_cast<::orc::StructVectorBatch&>(*batch);
+        auto& ids = dynamic_cast<::orc::LongVectorBatch&>(*root.fields[0]);
+        auto& values = 
dynamic_cast<::orc::DoubleVectorBatch&>(*root.fields[1]);
+        for (int64_t group = 0; group < 4; ++group) {
+            root.numElements = ids.numElements = values.numElements = 
ROWS_PER_GROUP;
+            values.hasNulls = group == 3;
+            for (int64_t row = 0; row < ROWS_PER_GROUP; ++row) {
+                ids.data[row] = group * ROWS_PER_GROUP + row;
+                values.notNull[row] = group != 3;
+                // Separate signs into different Bloom filters; min/max alone 
keeps both zeros.
+                if (group == 0) {
+                    values.data[row] = -0.0;
+                } else if (group == 1) {
+                    values.data[row] = 0.0;
+                } else {
+                    values.data[row] = row % 2 ? 1.0 : 3.0;
+                }
+            }
+            writer->add(*batch);
+        }
+        writer->close();
+        _file.assign(output.getData(), output.getLength());
+        auto reader = create_orc_reader();
+        ASSERT_EQ(reader->getNumberOfStripes(), multiple_stripes ? 4 : 1);
+    }
+
+    std::unique_ptr<::orc::Reader> create_orc_reader() const {
+        return 
::orc::createReader(std::make_unique<MemoryInputStream>(_file.data(), 
_file.size()),
+                                   ::orc::ReaderOptions());
+    }
+
+    VExprSPtr literal(double value) const {
+        const auto field = std::get<0>(GetParam())
+                                   ? 
Field::create_field<TYPE_FLOAT>(static_cast<float>(value))
+                                   : Field::create_field<TYPE_DOUBLE>(value);
+        return VLiteral::create_shared(_value_type, field);
+    }
+
+    VExprSPtr predicate(TExprOpcode::type op, std::vector<VExprSPtr> values,
+                        bool literal_on_left = false) const {
+        const bool is_in = op == TExprOpcode::FILTER_IN;
+        TExprNode node;
+        auto node_type = TExprNodeType::BINARY_PRED;
+        if (is_in) {
+            node_type = TExprNodeType::IN_PRED;
+        } else if (op == TExprOpcode::EQ_FOR_NULL) {
+            node_type = TExprNodeType::NULL_AWARE_BINARY_PRED;
+        }
+        node.__set_node_type(node_type);
+        node.__set_opcode(op);
+        
node.__set_type(make_nullable(std::make_shared<DataTypeUInt8>())->to_thrift());
+        node.__set_is_nullable(true);
+        node.in_predicate.__set_is_not_in(false);
+        VExprSPtr expr = is_in ? VExprSPtr(VInPredicate::create_shared(node))
+                               : 
VExprSPtr(VectorizedFnCall::create_shared(node));
+        auto slot = VSlotRef::create_shared(1, 1, -1, 
make_nullable(_value_type), "value");
+        if (literal_on_left) {
+            expr->add_child(values.front());
+            expr->add_child(slot);
+        } else {
+            expr->add_child(slot);
+            for (const auto& value : values) {
+                expr->add_child(value);
+            }
+        }
+        return expr;
+    }
+
+    std::vector<int64_t> selected_ids(const VExprSPtr& expr) const {
+        format::FileScanRequest request;
+        request.local_positions.emplace(format::LocalColumnId(1), 
format::LocalIndex(1));
+        auto builder = ::orc::SearchArgumentFactory::newBuilder();
+        const bool pushed = format::orc::build_orc_search_argument(
+                request, *_type, cctz::utc_time_zone(), {}, expr, builder);
+        EXPECT_TRUE(pushed);
+        if (!pushed) {
+            return {};
+        }
+        ::orc::RowReaderOptions options;
+        options.searchArgument(builder->build());
+        auto reader = create_orc_reader();
+        auto row_reader = reader->createRowReader(options);
+        auto batch = row_reader->createRowBatch(512);
+        auto& root = dynamic_cast<::orc::StructVectorBatch&>(*batch);
+        auto& ids = dynamic_cast<::orc::LongVectorBatch&>(*root.fields[0]);
+        std::vector<int64_t> result;
+        while (row_reader->next(*batch)) {
+            for (uint64_t row = 0; row < batch->numElements; ++row) {
+                result.push_back(ids.data[row]);
+            }
+        }
+        return result;
+    }
+
+    static std::vector<int64_t> group_ids(int64_t first, int64_t count) {
+        std::vector<int64_t> ids(count * ROWS_PER_GROUP);
+        std::iota(ids.begin(), ids.end(), first * ROWS_PER_GROUP);
+        return ids;
+    }
+
+    DataTypePtr _value_type;
+    std::unique_ptr<::orc::Type> _type;
+    std::string _file;
+};
+
+TEST_P(OrcSearchArgumentSignedZeroTest, EqualityKeepsBothSigns) {
+    for (double zero : {0.0, -0.0}) {
+        for (bool literal_on_left : {false, true}) {
+            EXPECT_EQ(selected_ids(predicate(TExprOpcode::EQ, {literal(zero)}, 
literal_on_left)),
+                      group_ids(0, 2));
+        }
+    }
+}
+
+TEST_P(OrcSearchArgumentSignedZeroTest, NullSafeEqualityKeepsBothSigns) {
+    for (double zero : {0.0, -0.0}) {
+        for (bool literal_on_left : {false, true}) {
+            EXPECT_EQ(selected_ids(predicate(TExprOpcode::EQ_FOR_NULL, 
{literal(zero)},
+                                             literal_on_left)),
+                      group_ids(0, 2));
+        }
+    }
+}
+
+TEST_P(OrcSearchArgumentSignedZeroTest, InKeepsBothSigns) {
+    for (double zero : {0.0, -0.0}) {
+        EXPECT_EQ(selected_ids(predicate(TExprOpcode::FILTER_IN, 
{literal(zero)})),
+                  group_ids(0, 2));
+        EXPECT_EQ(selected_ids(predicate(TExprOpcode::FILTER_IN, 
{literal(2.0), literal(zero)})),
+                  group_ids(0, 2));
+        EXPECT_EQ(selected_ids(predicate(TExprOpcode::FILTER_IN,
+                                         {literal(zero), literal(-zero), 
literal(2.0)})),
+                  group_ids(0, 2));
+        auto null_literal = 
VLiteral::create_shared(make_nullable(_value_type), Field());
+        EXPECT_EQ(selected_ids(predicate(TExprOpcode::FILTER_IN, 
{literal(zero), null_literal})),
+                  group_ids(0, 2));
+    }
+}
+
+TEST_P(OrcSearchArgumentSignedZeroTest, NullSafeNullStillSelectsOnlyNullGroup) 
{
+    auto null_literal = VLiteral::create_shared(make_nullable(_value_type), 
Field());
+    EXPECT_EQ(selected_ids(predicate(TExprOpcode::EQ_FOR_NULL, 
{null_literal})), group_ids(3, 1));
+}
+
+TEST_P(OrcSearchArgumentSignedZeroTest, NonzeroBloomPruningIsPreserved) {
+    // 2 is inside the [1, 3] bounds, so only Bloom can reject this nonzero 
candidate.
+    EXPECT_TRUE(selected_ids(predicate(TExprOpcode::EQ, 
{literal(2.0)})).empty());
+    EXPECT_TRUE(
+            selected_ids(predicate(TExprOpcode::FILTER_IN, {literal(2.0), 
literal(2.5)})).empty());
+    EXPECT_EQ(selected_ids(predicate(TExprOpcode::EQ, {literal(1.0)})), 
group_ids(2, 1));
+    EXPECT_EQ(selected_ids(predicate(TExprOpcode::LE, {literal(0.0)})), 
group_ids(0, 2));
+}
+
+INSTANTIATE_TEST_SUITE_P(FloatAndDoubleRowGroupsAndStripes, 
OrcSearchArgumentSignedZeroTest,
+                         testing::Combine(testing::Bool(), testing::Bool()));
+
+} // namespace
+} // namespace doris
diff --git 
a/regression-test/data/external_table_p0/tvf/test_data/GenerateOrcSignedZeroBloom.cpp
 
b/regression-test/data/external_table_p0/tvf/test_data/GenerateOrcSignedZeroBloom.cpp
new file mode 100644
index 00000000000..179d290b47b
--- /dev/null
+++ 
b/regression-test/data/external_table_p0/tvf/test_data/GenerateOrcSignedZeroBloom.cpp
@@ -0,0 +1,65 @@
+// 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 <memory>
+#include <orc/OrcFile.hh>
+#include <orc/Writer.hh>
+
+// Link against Doris's ORC library. Pass the row-group fixture path followed 
by
+// the multi-stripe fixture path. Signed zeros must remain in separate Bloom 
filters.
+int main(int argc, char** argv) {
+    if (argc != 3) {
+        return 1;
+    }
+    constexpr int64_t rows = 1000;
+    for (int fixture = 1; fixture <= 2; ++fixture) {
+        auto output = orc::writeLocalFile(argv[fixture]);
+        auto type = 
orc::Type::buildTypeFromString("struct<id:int,f:float,d:double>");
+        orc::WriterOptions options;
+        options.setRowIndexStride(rows)
+                .setStripeSize(fixture == 1 ? 1024 * 1024 : 1)
+                .setColumnsUseBloomFilter({2, 3})
+                .setBloomFilterFPP(0.000001)
+                .setCompression(orc::CompressionKind_NONE);
+        auto writer = orc::createWriter(*type, output.get(), options);
+        auto batch = writer->createRowBatch(rows);
+        auto& root = dynamic_cast<orc::StructVectorBatch&>(*batch);
+        auto& ids = dynamic_cast<orc::LongVectorBatch&>(*root.fields[0]);
+        auto& floats = dynamic_cast<orc::DoubleVectorBatch&>(*root.fields[1]);
+        auto& doubles = dynamic_cast<orc::DoubleVectorBatch&>(*root.fields[2]);
+        for (int64_t group = 0; group < 4; ++group) {
+            root.numElements = ids.numElements = floats.numElements = 
doubles.numElements = rows;
+            floats.hasNulls = doubles.hasNulls = group == 3;
+            for (int64_t row = 0; row < rows; ++row) {
+                ids.data[row] = group * rows + row;
+                floats.notNull[row] = doubles.notNull[row] = group != 3;
+                // Nonzero values straddle 2, so rejecting x = 2 requires 
Bloom rather than bounds.
+                double value = row % 2 ? 1.0 : 3.0;
+                if (group == 0) {
+                    value = -0.0;
+                } else if (group == 1) {
+                    value = 0.0;
+                }
+                floats.data[row] = doubles.data[row] = value;
+            }
+            writer->add(*batch);
+        }
+        writer->close();
+        output->close();
+    }
+    return 0;
+}
diff --git 
a/regression-test/data/external_table_p0/tvf/test_data/signed_zero_bloom_row_groups.orc
 
b/regression-test/data/external_table_p0/tvf/test_data/signed_zero_bloom_row_groups.orc
new file mode 100644
index 00000000000..cfd9d3f2c2f
Binary files /dev/null and 
b/regression-test/data/external_table_p0/tvf/test_data/signed_zero_bloom_row_groups.orc
 differ
diff --git 
a/regression-test/data/external_table_p0/tvf/test_data/signed_zero_bloom_stripes.orc
 
b/regression-test/data/external_table_p0/tvf/test_data/signed_zero_bloom_stripes.orc
new file mode 100644
index 00000000000..b65148aeb27
Binary files /dev/null and 
b/regression-test/data/external_table_p0/tvf/test_data/signed_zero_bloom_stripes.orc
 differ
diff --git 
a/regression-test/data/external_table_p0/tvf/test_orc_signed_zero_bloom.out 
b/regression-test/data/external_table_p0/tvf/test_orc_signed_zero_bloom.out
new file mode 100644
index 00000000000..dadaa9a805f
--- /dev/null
+++ b/regression-test/data/external_table_p0/tvf/test_orc_signed_zero_bloom.out
@@ -0,0 +1,13 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !fixture --
+0      -0.0    -0
+1000   0.0     0
+2000   3.0     3
+3000   \N      \N
+
+-- !fixture --
+0      -0.0    -0
+1000   0.0     0
+2000   3.0     3
+3000   \N      \N
+
diff --git 
a/regression-test/suites/external_table_p0/tvf/test_orc_signed_zero_bloom.groovy
 
b/regression-test/suites/external_table_p0/tvf/test_orc_signed_zero_bloom.groovy
new file mode 100644
index 00000000000..c0cf5a2590f
--- /dev/null
+++ 
b/regression-test/suites/external_table_p0/tvf/test_orc_signed_zero_bloom.groovy
@@ -0,0 +1,120 @@
+// 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.
+
+import com.azure.storage.blob.BlobClientBuilder
+import com.azure.storage.common.StorageSharedKeyCredential
+
+suite("test_orc_signed_zero_bloom", "p0,external") {
+    String provider = getS3Provider()
+    String endpoint = getS3Endpoint()
+    if (provider.equalsIgnoreCase("AZURE")) {
+        if (endpoint == "azure-endpoint") {
+            endpoint = "https://${getS3AK()}.blob.core.windows.net"
+        } else if (!endpoint.contains("://")) {
+            endpoint = "https://${endpoint}";
+        }
+    }
+    String bucket = context.config.otherConfigs.get("s3BucketName")
+    String prefix = "orc_signed_zero_bloom/${UUID.randomUUID()}"
+    Map<String, String> originalSettings = [:]
+    for (String variable : ["enable_orc_filter_by_min_max", 
"enable_orc_lazy_materialization",
+                            "enable_sql_cache", "enable_query_cache", 
"enable_condition_cache"]) {
+        originalSettings[variable] = sql("SHOW VARIABLES LIKE 
'${variable}'")[0][1].toString()
+    }
+    try {
+        sql "SET enable_sql_cache = false"
+        sql "SET enable_query_cache = false"
+        sql "SET enable_condition_cache = false"
+        for (String layout : ["row_groups", "stripes"]) {
+            String key = "${prefix}/${layout}.orc"
+            File fixture = new File(context.dataPath, 
"test_data/signed_zero_bloom_${layout}.orc")
+            def blobClient = null
+            def s3Client = null
+            boolean uploaded = false
+            try {
+                if (provider.equalsIgnoreCase("AZURE")) {
+                    blobClient = new 
BlobClientBuilder().endpoint(endpoint).containerName(bucket)
+                            .blobName(key).credential(new 
StorageSharedKeyCredential(getS3AK(), getS3SK()))
+                            .buildClient()
+                    blobClient.uploadFromFile(fixture.absolutePath)
+                } else {
+                    s3Client = getS3Client()
+                    s3Client.putObject(bucket, key, fixture)
+                }
+                uploaded = true
+                String source = """S3('uri'='s3://${bucket}/${key}', 
'format'='orc',
+                        'provider'='${provider}', 's3.endpoint'='${endpoint}', 
's3.region'='${getS3Region()}',
+                        's3.access_key'='${getS3AK()}', 
's3.secret_key'='${getS3SK()}')"""
+                for (boolean sarg : [false, true]) {
+                    sql "SET enable_orc_filter_by_min_max = ${sarg}"
+                    for (boolean lazy : [false, true]) {
+                        sql "SET enable_orc_lazy_materialization = ${lazy}"
+                        for (String column : ["f", "d"]) {
+                            String type = column == "f" ? "FLOAT" : "DOUBLE"
+                            String positive = "CAST('0.0' AS ${type})"
+                            String negative = "CAST('-0.0' AS ${type})"
+                            // IDs are an independent oracle: negative zeros 
[0,1000), positive
+                            // zeros [1000,2000), alternating 3/1 [2000,3000), 
NULLs [3000,4000).
+                            def cases = [
+                                    ["${column} = ${positive}", "id < 2000"],
+                                    ["${column} = ${negative}", "id < 2000"],
+                                    ["${negative} = ${column}", "id < 2000"],
+                                    ["${column} <=> ${positive}", "id < 2000"],
+                                    ["${negative} <=> ${column}", "id < 2000"],
+                                    ["${column} IN (${negative})", "id < 
2000"],
+                                    ["${column} IN (${positive}, 2.0)", "id < 
2000"],
+                                    ["${column} IN (2.0, ${negative})", "id < 
2000"],
+                                    ["${column} IN (${positive}, ${negative}, 
NULL)", "id < 2000"],
+                                    ["${column} != ${negative}", "id >= 2000 
AND id < 3000"],
+                                    ["NOT (${column} = ${positive})", "id >= 
2000 AND id < 3000"],
+                                    ["${column} NOT IN (${negative}, 2.0)", 
"id >= 2000 AND id < 3000"],
+                                    ["${column} NOT IN (${positive}, NULL)", 
"FALSE"],
+                                    ["(${column} = ${negative} AND id >= 1000) 
OR ${column} = 3.0",
+                                     "(id >= 1000 AND id < 2000) OR (id >= 
2000 AND id < 3000 AND id % 2 = 0)"],
+                                    ["(${column} IN (${positive}, 2.0) OR 
${column} IS NULL)",
+                                     "id < 2000 OR id >= 3000"],
+                                    ["(${column} <=> ${negative}) OR id = 
3999", "id < 2000 OR id = 3999"],
+                                    ["CAST(${column} AS DOUBLE) = 
${positive}", "id < 2000"],
+                                    ["${column} = 1.0", "id >= 2000 AND id < 
3000 AND id % 2 = 1"],
+                                    ["${column} IN (2.0, 2.5)", "FALSE"],
+                                    ["${column} <= ${negative}", "id < 2000"],
+                                    ["${column} <=> CAST(NULL AS ${type})", 
"id >= 3000"]
+                            ]
+                            cases.eachWithIndex { testCase, index ->
+                                
quickTest("${layout}_${sarg}_${lazy}_${column}_${index}",
+                                        "SELECT id FROM ${source} WHERE 
${testCase[0]} ORDER BY id",
+                                        "SELECT id FROM (SELECT number AS id 
FROM numbers('number'='4000')) ids " +
+                                                "WHERE ${testCase[1]} ORDER BY 
id")
+                            }
+                        }
+                    }
+                }
+                order_qt_fixture "SELECT id, f, d FROM ${source} WHERE id IN 
(0, 1000, 2000, 3000)"
+            } finally {
+                if (uploaded) {
+                    if (blobClient != null) {
+                        blobClient.delete()
+                    } else {
+                        s3Client.deleteObject(bucket, key)
+                    }
+                }
+            }
+        }
+    } finally {
+        originalSettings.each { variable, value -> sql "SET ${variable} = 
${value}" }
+    }
+}


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

Reply via email to