Skip to content
Snippets Groups Projects
Unverified Commit 1d180950 authored by Yichen Wang's avatar Yichen Wang Committed by GitHub
Browse files

Fix float precision in comparison (#963)

* Fix float precision in comparision

Fix type

* Fix UT

* Modify test query

Fix typo

* Fix fmt
parent bba7f08d
No related branches found
No related tags found
No related merge requests found
......@@ -38,8 +38,6 @@ public:
static Value boundValueWithMin(const meta::cpp2::ColumnDef& col);
static Value normalizeValue(const meta::cpp2::ColumnDef& col, const Value& v);
static constexpr double kEpsilon = 0.0000000000000001;
};
} // namespace graph
......
......@@ -115,14 +115,14 @@ TEST(IndexBoundValueTest, DoubleTest) {
EXPECT_EQ(0.0,
OptimizerUtils::boundValue(col, OP::LESS_THAN, Value(-minDouble)).getFloat());
EXPECT_EQ(maxDouble - 0.0000000000000001,
EXPECT_EQ(maxDouble - kEpsilon,
OptimizerUtils::boundValue(col, OP::LESS_THAN, Value(maxDouble)).getFloat());
EXPECT_EQ(-minDouble, OptimizerUtils::boundValue(col, OP::LESS_THAN, Value(0.0)).getFloat());
EXPECT_EQ(5.1 - 0.0000000000000001,
EXPECT_EQ(5.1 - kEpsilon,
OptimizerUtils::boundValue(col, OP::LESS_THAN, Value(5.1)));
EXPECT_EQ(-(5.1 + 0.0000000000000001),
EXPECT_EQ(-(5.1 + kEpsilon),
OptimizerUtils::boundValue(col, OP::LESS_THAN, Value(-5.1)));
EXPECT_EQ(maxDouble,
......@@ -132,10 +132,10 @@ TEST(IndexBoundValueTest, DoubleTest) {
EXPECT_EQ(minDouble, OptimizerUtils::boundValue(col, OP::GREATER_THAN, Value(0.0)).getFloat());
EXPECT_EQ(5.1 + 0.0000000000000001,
EXPECT_EQ(5.1 + kEpsilon,
OptimizerUtils::boundValue(col, OP::GREATER_THAN, Value(5.1)).getFloat());
EXPECT_EQ(-(5.1 - 0.0000000000000001),
EXPECT_EQ(-(5.1 - kEpsilon),
OptimizerUtils::boundValue(col, OP::GREATER_THAN, Value(-5.1)).getFloat());
}
......
......@@ -378,6 +378,20 @@ TEST(IndexScanRuleTest, BoundValueRangeTest) {
EXPECT_EQ(-std::numeric_limits<double>::max(), *hint.begin_value_ref());
EXPECT_EQ(1, *hint.end_value_ref());
}
{
std::vector<storage::cpp2::IndexColumnHint> hints;
// col_double <= 3.0
IndexScanRule::FilterItems items;
items.addItem("col_double", RelationalExpression::Kind::kRelLE, Value(3.0));
auto status = instance->appendColHint(hints, items, col);
EXPECT_TRUE(status.ok());
EXPECT_EQ(1, hints.size());
const auto& hint = hints[0];
EXPECT_EQ("col_double", *hint.column_name_ref());
EXPECT_EQ(storage::cpp2::ScanType::RANGE, *hint.scan_type_ref());
EXPECT_EQ(-std::numeric_limits<double>::max(), *hint.begin_value_ref());
EXPECT_EQ(3 + kEpsilon, *hint.end_value_ref());
}
{
std::vector<storage::cpp2::IndexColumnHint> hints;
// col_double >= 1.0
......@@ -404,8 +418,8 @@ TEST(IndexScanRuleTest, BoundValueRangeTest) {
const auto& hint = hints[0];
EXPECT_EQ("col_double", *hint.column_name_ref());
EXPECT_EQ(storage::cpp2::ScanType::RANGE, *hint.scan_type_ref());
EXPECT_EQ(1 + OptimizerUtils::kEpsilon, *hint.begin_value_ref());
EXPECT_EQ(5 - OptimizerUtils::kEpsilon, *hint.end_value_ref());
EXPECT_EQ(1 + kEpsilon, *hint.begin_value_ref());
EXPECT_EQ(5 + kEpsilon, *hint.end_value_ref());
}
}
{
......
......@@ -302,19 +302,19 @@ Feature: LookUpTest_Vid_Int
"""
Then the result should be, in any order:
| VertexID |
# FIXME(aiee): should not contain vid 220
When executing query:
"""
LOOKUP ON lookup_tag_2 WHERE lookup_tag_2.col3 > 100.5
LOOKUP ON lookup_tag_2
WHERE lookup_tag_2.col3 > 100.5
YIELD lookup_tag_2.col3 AS col3
"""
Then the result should be, in any order:
| VertexID |
| 220 |
| 221 |
| 222 |
| 223 |
| 224 |
| 225 |
| VertexID | col3 |
| 221 | 200.5 |
| 222 | 300.5 |
| 223 | 400.5 |
| 224 | 500.5 |
| 225 | 600.5 |
When executing query:
"""
LOOKUP ON lookup_tag_2 WHERE lookup_tag_2.col3 == 100.5
......@@ -328,15 +328,17 @@ Feature: LookUpTest_Vid_Int
"""
Then the result should be, in any order:
| VertexID |
# FIXME(aiee): should contain vid 222
When executing query:
"""
LOOKUP ON lookup_tag_2 WHERE lookup_tag_2.col3 >= 100.5 AND lookup_tag_2.col3 <= 300.5
LOOKUP ON lookup_tag_2
WHERE lookup_tag_2.col3 >= 100.5 AND lookup_tag_2.col3 <= 300.5
YIELD lookup_tag_2.col3 AS col3
"""
Then the result should be, in any order:
| VertexID |
| 220 |
| 221 |
| VertexID | col3 |
| 220 | 100.5 |
| 221 | 200.5 |
| 222 | 300.5 |
Then drop the used space
Scenario: LookupTest IntVid EdgeConditionScan
......@@ -452,18 +454,18 @@ Feature: LookUpTest_Vid_Int
"""
Then the result should be, in any order:
| SrcVID | DstVID | Ranking |
# FIXME(aiee): should not contains first line
When executing query:
"""
LOOKUP ON lookup_edge_2 WHERE lookup_edge_2.col3 > 100.5
LOOKUP ON lookup_edge_2
WHERE lookup_edge_2.col3 > 100.5
YIELD lookup_edge_2.col3 AS col3
"""
Then the result should be, in any order:
| SrcVID | DstVID | Ranking |
| 220 | 221 | 0 |
| 220 | 222 | 0 |
| 220 | 223 | 0 |
| 220 | 224 | 0 |
| 220 | 225 | 0 |
| SrcVID | DstVID | Ranking | col3 |
| 220 | 222 | 0 | 200.5 |
| 220 | 223 | 0 | 300.5 |
| 220 | 224 | 0 | 400.5 |
| 220 | 225 | 0 | 500.5 |
When executing query:
"""
LOOKUP ON lookup_edge_2 WHERE lookup_edge_2.col3 == 100.5
......@@ -477,16 +479,17 @@ Feature: LookUpTest_Vid_Int
"""
Then the result should be, in any order:
| SrcVID | DstVID | Ranking |
# FIXME(aiee): should contain 220->223
When executing query:
"""
LOOKUP ON lookup_edge_2 WHERE lookup_edge_2.col3 >= 100.5
AND lookup_edge_2.col3 <= 300.5
LOOKUP ON lookup_edge_2
WHERE lookup_edge_2.col3 >= 100.5 AND lookup_edge_2.col3 <= 300.5
YIELD lookup_edge_2.col3 AS col3
"""
Then the result should be, in any order:
| SrcVID | DstVID | Ranking |
| 220 | 221 | 0 |
| 220 | 222 | 0 |
| SrcVID | DstVID | Ranking | col3 |
| 220 | 221 | 0 | 100.5 |
| 220 | 222 | 0 | 200.5 |
| 220 | 223 | 0 | 300.5 |
Then drop the used space
Scenario: LookupTest IntVid FunctionExprTest
......
......@@ -270,19 +270,19 @@ Feature: LookUpTest_Vid_String
"""
Then the result should be, in any order:
| VertexID |
# FIXME(aiee): should not contains vid 220
When executing query:
"""
LOOKUP ON lookup_tag_2 WHERE lookup_tag_2.col3 > 100.5
LOOKUP ON lookup_tag_2
WHERE lookup_tag_2.col3 > 100.5
YIELD lookup_tag_2.col3 AS col3
"""
Then the result should be, in any order:
| VertexID |
| "220" |
| "221" |
| "222" |
| "223" |
| "224" |
| "225" |
| VertexID | col3 |
| "221" | 200.5 |
| "222" | 300.5 |
| "223" | 400.5 |
| "224" | 500.5 |
| "225" | 600.5 |
When executing query:
"""
LOOKUP ON lookup_tag_2 WHERE lookup_tag_2.col3 == 100.5
......@@ -296,15 +296,17 @@ Feature: LookUpTest_Vid_String
"""
Then the result should be, in any order:
| VertexID |
# FIXME(aiee): should contain vid 222
When executing query:
"""
LOOKUP ON lookup_tag_2 WHERE lookup_tag_2.col3 >= 100.5 AND lookup_tag_2.col3 <= 300.5
LOOKUP ON lookup_tag_2
WHERE lookup_tag_2.col3 >= 100.5 AND lookup_tag_2.col3 <= 300.5
YIELD lookup_tag_2.col3 AS col3
"""
Then the result should be, in any order:
| VertexID |
| "220" |
| "221" |
| VertexID | col3 |
| "220" | 100.5 |
| "221" | 200.5 |
| "222" | 300.5 |
Then drop the used space
Scenario: LookupTest EdgeConditionScan
......@@ -413,18 +415,18 @@ Feature: LookUpTest_Vid_String
"""
Then the result should be, in any order:
| SrcVID | DstVID | Ranking |
# FIXME(aiee): shouble not contain first line
When executing query:
"""
LOOKUP ON lookup_edge_2 WHERE lookup_edge_2.col3 > 100.5
LOOKUP ON lookup_edge_2
WHERE lookup_edge_2.col3 > 100.5
YIELD lookup_edge_2.col3 AS col3
"""
Then the result should be, in any order:
| SrcVID | DstVID | Ranking |
| "220" | "221" | 0 |
| "220" | "222" | 0 |
| "220" | "223" | 0 |
| "220" | "224" | 0 |
| "220" | "225" | 0 |
| SrcVID | DstVID | Ranking | col3 |
| "220" | "222" | 0 | 200.5 |
| "220" | "223" | 0 | 300.5 |
| "220" | "224" | 0 | 400.5 |
| "220" | "225" | 0 | 500.5 |
When executing query:
"""
LOOKUP ON lookup_edge_2 WHERE lookup_edge_2.col3 == 100.5
......@@ -438,16 +440,17 @@ Feature: LookUpTest_Vid_String
"""
Then the result should be, in any order:
| SrcVID | DstVID | Ranking |
# FIXME(aiee): should contain edge 200->223
When executing query:
"""
LOOKUP ON lookup_edge_2 WHERE lookup_edge_2.col3 >= 100.5
AND lookup_edge_2.col3 <= 300.5
LOOKUP ON lookup_edge_2
WHERE lookup_edge_2.col3 >= 100.5 AND lookup_edge_2.col3 <= 300.5
YIELD lookup_edge_2.col3 AS col3
"""
Then the result should be, in any order:
| SrcVID | DstVID | Ranking |
| "220" | "221" | 0 |
| "220" | "222" | 0 |
| SrcVID | DstVID | Ranking | col3 |
| "220" | "221" | 0 | 100.5 |
| "220" | "222" | 0 | 200.5 |
| "220" | "223" | 0 | 300.5 |
Then drop the used space
Scenario: LookupTest FunctionExprTest
......@@ -560,12 +563,6 @@ Feature: LookUpTest_Vid_String
# """
# Then the result should be, in any order:
# | VertexID |
# When executing query:
# """
# LOOKUP ON lookup_tag_2 WHERE lookup_tag_2.col4 == strcasecmp("HelLo", "hello")
# """
# Then the result should be, in any order:
# | VertexID |
When executing query:
"""
LOOKUP ON lookup_tag_2 WHERE lookup_tag_2.col2 != lookup_tag_2.col3
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment