Skip to content

Commit b8a18ef

Browse files
committed
[fix](be) Skip condition cache for complex object literals
### What problem does this PR solve? Issue Number: None Problem Summary: With the condition cache enabled, a valid scan predicate such as `bitmap_count(IF(id = 1, to_bitmap(1), CAST(NULL AS BITMAP))) > 0` fails while preparing its digest. VLiteral delegates to the column's xxHash interface, which ColumnComplexType does not implement, including through nullable/constant wrappers. Return the existing unsupported-digest sentinel (0) for BITMAP, HLL and QUANTILE_STATE literals. Parent expressions propagate zero and the scan evaluates its predicates without using the condition cache. Keep the general column hashing contract unchanged: it also serves aggregation and does not define zero as an unsupported value. ### Release note Fix valid queries containing complex object literals in scan predicates failing when the condition cache is enabled. Such scans now bypass the condition cache. ### Check List (For Author) - Test: - Unit Test: Add typed NULL and non-NULL object literals, parent digest propagation, and scalar digest controls. - Regression test: Add IF/CASE predicate execution with the condition cache toggled on/off/on, plus a projection control. - Local validation: clang-format 16, build hygiene and clang-tidy passed. clang-tidy used the generated UT compilation flags with the missing PCH removed and the toolchain resource directory supplied. - BE UT execution was blocked before compilation/linking by missing local third-party archives libsimdutf.a and libpaimon_c.a. The regression was not run locally; the reported test host is unreachable. No runtime pass is claimed. - Behavior changed: Yes. Unsupported literal digests disable the affected scan's condition cache instead of failing the query. - Does this need documentation: No.
1 parent b551ff8 commit b8a18ef

3 files changed

Lines changed: 139 additions & 2 deletions

File tree

‎be/src/exprs/vliteral.cpp‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,17 @@ bool VLiteral::equals(const VExpr& other) {
100100
}
101101

102102
uint64_t VLiteral::get_digest(uint64_t seed) const {
103-
_column_ptr->update_xxHash_with_value(0, 1, seed, nullptr);
104-
return seed;
103+
// ColumnComplexType does not implement xxHash, including when wrapped by
104+
// ColumnNullable/ColumnConst. A zero digest disables the condition cache.
105+
switch (_data_type->get_primitive_type()) {
106+
case TYPE_BITMAP:
107+
case TYPE_HLL:
108+
case TYPE_QUANTILE_STATE:
109+
return 0;
110+
default:
111+
_column_ptr->update_xxHash_with_value(0, 1, seed, nullptr);
112+
return seed;
113+
}
105114
}
106115

107116
} // namespace doris
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
#include <gtest/gtest.h>
19+
20+
#include "core/data_type/data_type_factory.hpp"
21+
#include "core/data_type/data_type_number.h"
22+
#include "core/data_type/data_type_string.h"
23+
#include "exprs/vliteral.h"
24+
#include "testutil/mock/mock_fn_call.h"
25+
26+
namespace doris {
27+
28+
TEST(VLiteralDigestTest, ComplexNullDisablesParentDigest) {
29+
for (auto type : {TYPE_BITMAP, TYPE_HLL, TYPE_QUANTILE_STATE}) {
30+
SCOPED_TRACE(type_to_string(type));
31+
auto data_type = DataTypeFactory::instance().create_data_type(type, true);
32+
auto literal = VLiteral::create_shared(data_type, Field());
33+
EXPECT_EQ(literal->get_digest(42), 0);
34+
35+
// A later scalar child must not revive a digest disabled by the complex literal.
36+
auto parent = MockFnCall::create("if");
37+
parent->add_child(literal);
38+
parent->add_child(VLiteral::create_shared(std::make_shared<DataTypeInt32>(),
39+
Field::create_field<TYPE_INT>(1)));
40+
EXPECT_EQ(parent->get_digest(42), 0);
41+
}
42+
}
43+
44+
TEST(VLiteralDigestTest, NonNullComplexValuesDisableDigest) {
45+
auto bitmap = VLiteral::create_shared(
46+
DataTypeFactory::instance().create_data_type(TYPE_BITMAP, false),
47+
Field::create_field<TYPE_BITMAP>(BitmapValue(1)));
48+
auto hll =
49+
VLiteral::create_shared(DataTypeFactory::instance().create_data_type(TYPE_HLL, false),
50+
Field::create_field<TYPE_HLL>(HyperLogLog()));
51+
auto quantile = VLiteral::create_shared(
52+
DataTypeFactory::instance().create_data_type(TYPE_QUANTILE_STATE, false),
53+
Field::create_field<TYPE_QUANTILE_STATE>(QuantileState()));
54+
EXPECT_EQ(bitmap->get_digest(42), 0);
55+
EXPECT_EQ(hll->get_digest(42), 0);
56+
EXPECT_EQ(quantile->get_digest(42), 0);
57+
}
58+
59+
TEST(VLiteralDigestTest, ScalarValuesKeepDistinctStableDigests) {
60+
auto int_type = std::make_shared<DataTypeInt32>();
61+
auto one = VLiteral::create_shared(int_type, Field::create_field<TYPE_INT>(1));
62+
auto two = VLiteral::create_shared(int_type, Field::create_field<TYPE_INT>(2));
63+
EXPECT_NE(one->get_digest(42), 0);
64+
EXPECT_EQ(one->get_digest(42), one->get_digest(42));
65+
EXPECT_NE(one->get_digest(42), two->get_digest(42));
66+
EXPECT_NE(one->get_digest(42), one->get_digest(43));
67+
68+
auto string_type = std::make_shared<DataTypeString>();
69+
auto a = VLiteral::create_shared(string_type, Field::create_field<TYPE_STRING>(String("a")));
70+
auto b = VLiteral::create_shared(string_type, Field::create_field<TYPE_STRING>(String("b")));
71+
EXPECT_NE(a->get_digest(42), 0);
72+
EXPECT_NE(a->get_digest(42), b->get_digest(42));
73+
74+
auto scalar_null = VLiteral::create_shared(
75+
DataTypeFactory::instance().create_data_type(TYPE_INT, true), Field());
76+
EXPECT_NE(scalar_null->get_digest(42), 0);
77+
}
78+
79+
} // namespace doris
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
suite("test_condition_cache_complex_literal") {
19+
sql "set enable_sql_cache=false"
20+
sql "drop table if exists condition_cache_complex_literal"
21+
sql """
22+
create table condition_cache_complex_literal (id int)
23+
duplicate key(id)
24+
distributed by hash(id) buckets 1
25+
properties("replication_num"="1")
26+
"""
27+
sql "insert into condition_cache_complex_literal values (1), (2)"
28+
29+
// This is an execution regression: computing the scan digest must not throw
30+
// merely because a predicate contains a typed NULL bitmap literal.
31+
for (boolean enabled : [true, false, true]) {
32+
sql "set enable_condition_cache=${enabled}"
33+
sql """
34+
select id from condition_cache_complex_literal
35+
where bitmap_count(if(id=1, to_bitmap(1), cast(null as bitmap))) > 0
36+
order by id
37+
"""
38+
sql """
39+
select id from condition_cache_complex_literal
40+
where bitmap_count(case when id=1 then to_bitmap(1)
41+
else cast(null as bitmap) end) > 0
42+
order by id
43+
"""
44+
}
45+
sql """
46+
select id, bitmap_count(if(id=1, to_bitmap(1), cast(null as bitmap)))
47+
from condition_cache_complex_literal order by id
48+
"""
49+
}

0 commit comments

Comments
 (0)