Skip to content

Commit e63f60e

Browse files
author
xiao.dong
committed
add case
1 parent 19b1f0a commit e63f60e

File tree

4 files changed

+399
-11
lines changed

4 files changed

+399
-11
lines changed

src/iceberg/expression/inclusive_metrics_evaluator.cc

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class InclusiveMetricsVisitor : public BoundVisitor<bool> {
130130
// because lower <= a for all values of a in the file, f(lower) <= f(a).
131131
// when f(lower) >= X then f(a) >= f(lower) >= X, so there is no a such that f(a) < X
132132
// f(lower) >= X means rows cannot match
133-
if (lit >= lower) {
133+
if (lower >= lit) {
134134
return ROWS_CANNOT_MATCH;
135135
}
136136

@@ -156,7 +156,7 @@ class InclusiveMetricsVisitor : public BoundVisitor<bool> {
156156
// because lower <= a for all values of a in the file, f(lower) <= f(a).
157157
// when f(lower) > X then f(a) >= f(lower) > X, so there is no a such that f(a) <= X
158158
// f(lower) > X means rows cannot match
159-
if (lit > lower) {
159+
if (lower > lit) {
160160
return ROWS_CANNOT_MATCH;
161161
}
162162

@@ -176,7 +176,7 @@ class InclusiveMetricsVisitor : public BoundVisitor<bool> {
176176
}
177177
const auto& upper = upper_result.value();
178178

179-
if (lit <= upper) {
179+
if (upper <= lit) {
180180
return ROWS_CANNOT_MATCH;
181181
}
182182

@@ -195,7 +195,7 @@ class InclusiveMetricsVisitor : public BoundVisitor<bool> {
195195
return ROWS_MIGHT_MATCH;
196196
}
197197
const auto& upper = upper_result.value();
198-
if (lit < upper) {
198+
if (upper < lit) {
199199
return ROWS_CANNOT_MATCH;
200200
}
201201

@@ -222,7 +222,7 @@ class InclusiveMetricsVisitor : public BoundVisitor<bool> {
222222
return ROWS_MIGHT_MATCH;
223223
}
224224
const auto& upper = upper_result.value();
225-
if (upper != lit) {
225+
if (upper < lit) {
226226
return ROWS_CANNOT_MATCH;
227227
}
228228

@@ -257,7 +257,7 @@ class InclusiveMetricsVisitor : public BoundVisitor<bool> {
257257
const auto& lower = lower_result.value();
258258
std::vector<Literal> literals;
259259
for (const auto& lit : literal_set) {
260-
if (lit >= lower) {
260+
if (lower <= lit) {
261261
literals.emplace_back(lit);
262262
}
263263
}
@@ -317,7 +317,7 @@ class InclusiveMetricsVisitor : public BoundVisitor<bool> {
317317
// prefix
318318
int length = std::min(prefix.size(), lower_str.size());
319319
// if prefix of lower bound is greater than prefix, rows cannot match
320-
if (lower_str.substr(0, length) > prefix.substr(0, length)) {
320+
if (lower_str.substr(0, length) > prefix) {
321321
return ROWS_CANNOT_MATCH;
322322
}
323323

@@ -331,7 +331,7 @@ class InclusiveMetricsVisitor : public BoundVisitor<bool> {
331331
// prefix
332332
length = std::min(prefix.size(), upper_str.size());
333333
// if prefix of upper bound is less than prefix, rows cannot match
334-
if (upper_str.substr(0, length) < prefix.substr(0, length)) {
334+
if (upper_str.substr(0, length) < prefix) {
335335
return ROWS_CANNOT_MATCH;
336336
}
337337

@@ -524,10 +524,11 @@ InclusiveMetricsEvaluator::InclusiveMetricsEvaluator(
524524
InclusiveMetricsEvaluator::~InclusiveMetricsEvaluator() = default;
525525

526526
Result<std::unique_ptr<InclusiveMetricsEvaluator>> InclusiveMetricsEvaluator::Make(
527-
std::shared_ptr<Expression> expr, const Schema& schema, bool case_sensitive) {
527+
std::shared_ptr<Expression> expr, const std::shared_ptr<Schema>& schema,
528+
bool case_sensitive) {
528529
ICEBERG_ASSIGN_OR_RAISE(auto rewrite_expr, RewriteNot::Visit(std::move(expr)));
529530
ICEBERG_ASSIGN_OR_RAISE(auto bound_expr,
530-
Binder::Bind(schema, rewrite_expr, case_sensitive));
531+
Binder::Bind(*schema, rewrite_expr, case_sensitive));
531532
return std::unique_ptr<InclusiveMetricsEvaluator>(
532533
new InclusiveMetricsEvaluator(std::move(bound_expr)));
533534
}

src/iceberg/expression/inclusive_metrics_evaluator.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ class ICEBERG_EXPORT InclusiveMetricsEvaluator {
5454
/// \param schema The schema of the table
5555
/// \param case_sensitive Whether field name matching is case-sensitive
5656
static Result<std::unique_ptr<InclusiveMetricsEvaluator>> Make(
57-
std::shared_ptr<Expression> expr, const Schema& schema, bool case_sensitive = true);
57+
std::shared_ptr<Expression> expr, const std::shared_ptr<Schema>& schema,
58+
bool case_sensitive = true);
5859

5960
~InclusiveMetricsEvaluator();
6061

src/iceberg/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ add_iceberg_test(expression_test
9494
expression_test.cc
9595
expression_visitor_test.cc
9696
literal_test.cc
97+
inclusive_metrics_evaluator_test.cc
9798
predicate_test.cc)
9899

99100
add_iceberg_test(json_serde_test

0 commit comments

Comments
 (0)