Skip to content

Commit

Permalink
fix crash of geo (#5475)
Browse files Browse the repository at this point in the history
* fix crash of geo

* change log(fatal) to log(error)
  • Loading branch information
jievince authored and Sophie-Xie committed Apr 6, 2023
1 parent 10bcb5d commit fb5ea40
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 14 deletions.
35 changes: 26 additions & 9 deletions src/graph/optimizer/rule/GeoPredicateIndexScanBaseRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,39 @@ StatusOr<TransformResult> GeoPredicateIndexScanBaseRule::transform(
}

auto condition = filter->condition();
DCHECK(graph::ExpressionUtils::isGeoIndexAcceleratedPredicate(condition));
if (!graph::ExpressionUtils::isGeoIndexAcceleratedPredicate(condition)) {
return TransformResult::noTransform();
}

auto* geoPredicate = static_cast<FunctionCallExpression*>(condition);
DCHECK_GE(geoPredicate->args()->numArgs(), 2);
if (geoPredicate->args()->numArgs() < 2) {
return TransformResult::noTransform();
}
std::string geoPredicateName = geoPredicate->name();
folly::toLowerAscii(geoPredicateName);
auto* first = geoPredicate->args()->args()[0];
auto* second = geoPredicate->args()->args()[1];
DCHECK(first->kind() == Expression::Kind::kTagProperty ||
first->kind() == Expression::Kind::kEdgeProperty);
DCHECK(second->kind() == Expression::Kind::kConstant);
const auto& secondVal = static_cast<const ConstantExpression*>(second)->value();
DCHECK(secondVal.isGeography());
if (first->kind() != Expression::Kind::kTagProperty &&
first->kind() != Expression::Kind::kEdgeProperty) {
return TransformResult::noTransform();
}

if (!graph::ExpressionUtils::isEvaluableExpr(second, qctx)) {
return TransformResult::noTransform();
}

auto secondVal = second->eval(graph::QueryExpressionContext(qctx->ectx())());
if (!secondVal.isGeography()) {
return TransformResult::noTransform();
}

const auto& geog = secondVal.getGeography();

auto indexItem = indexItems.back();
const auto& fields = indexItem->get_fields();
DCHECK_EQ(fields.size(), 1); // geo field
if (fields.size() != 1) {
return TransformResult::noTransform();
}
auto& geoField = fields.back();
auto& geoColumnTypeDef = geoField.get_type();
bool isPointColumn = geoColumnTypeDef.geo_shape_ref().has_value() &&
Expand All @@ -108,7 +123,9 @@ StatusOr<TransformResult> GeoPredicateIndexScanBaseRule::transform(
} else if (geoPredicateName == "st_coveredby") {
scanRanges = geoIndex.covers(geog);
} else if (geoPredicateName == "st_dwithin") {
DCHECK_GE(geoPredicate->args()->numArgs(), 3);
if (geoPredicate->args()->numArgs() < 3) {
return TransformResult::noTransform();
}
auto* third = geoPredicate->args()->args()[2];
if (!graph::ExpressionUtils::isEvaluableExpr(third, qctx)) {
return TransformResult::noTransform();
Expand Down
2 changes: 1 addition & 1 deletion src/graph/optimizer/rule/PushEFilterDownRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ std::string PushEFilterDownRule::toString() const {
ret = EdgePropertyExpression::make(pool, std::move(edgeNameResult).value(), exp->prop());
break;
default:
DLOG(FATAL) << "Unexpected expr: " << exp->kind();
DLOG(ERROR) << "Unexpected expr: " << exp->kind();
}
return ret;
}
Expand Down
6 changes: 3 additions & 3 deletions src/graph/optimizer/rule/PushFilterDownNodeRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ StatusOr<OptRule::TransformResult> PushFilterDownNodeRule::transform(
auto *append = static_cast<const AppendVertices *>(node);
vFilter = append->vFilter()->clone();
} else {
DLOG(FATAL) << "Unsupported node kind: " << node->kind();
DLOG(ERROR) << "Unsupported node kind: " << node->kind();
return TransformResult::noTransform();
}
auto visitor = graph::ExtractFilterExprVisitor::makePushGetVertices(pool);
Expand Down Expand Up @@ -83,7 +83,7 @@ StatusOr<OptRule::TransformResult> PushFilterDownNodeRule::transform(
append->setVertexFilter(remainedExpr);
append->setFilter(vFilter);
} else {
DLOG(FATAL) << "Unsupported node kind: " << newExplore->kind();
DLOG(ERROR) << "Unsupported node kind: " << newExplore->kind();
return TransformResult::noTransform();
}

Expand Down Expand Up @@ -111,7 +111,7 @@ bool PushFilterDownNodeRule::match(OptContext *octx, const MatchedResult &matche
return false;
}
} else {
DLOG(FATAL) << "Unexpected node kind: " << node->kind();
DLOG(ERROR) << "Unexpected node kind: " << node->kind();
return false;
}
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/graph/optimizer/rule/UnionAllIndexScanBaseRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ StatusOr<TransformResult> UnionAllIndexScanBaseRule::transform(OptContext* ctx,
break;
}
default:
DLOG(FATAL) << "Invalid expression kind: " << static_cast<uint8_t>(conditionType);
DLOG(ERROR) << "Invalid expression kind: " << static_cast<uint8_t>(conditionType);
return TransformResult::noTransform();
}

Expand Down
7 changes: 7 additions & 0 deletions tests/tck/features/geo/GeoBase.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Feature: Geo base
CREATE EDGE any_shape_edge(geo geography);
"""
And wait 3 seconds
Given parameters: {"p4": {"s1":"test","s2":"2020-01-01 10:00:00","s3":[1,2,3,4,5],"longitude":[1.0,2.0,3.0],"latitude":[10.1,11.1,12.1]}}

Scenario: test geo schema
# Desc geo schema
Expand Down Expand Up @@ -543,6 +544,12 @@ Feature: Geo base
| "LINESTRING(3 8, 4.7 73.23)" |
| "POLYGON((0 1, 1 2, 2 3, 0 1))" |
| "POINT(72.3 84.6)" |
When executing query:
"""
LOOKUP ON any_shape WHERE ST_Distance(any_shape.geo, ST_Point($p4.longitude[0], $p4.latitude[1])) < $p4.latitude[2] YIELD id(vertex)
"""
Then the result should be, in any order:
| id(VERTEX) |
When executing query:
"""
LOOKUP ON any_shape WHERE 8909524.383934560 > ST_Distance(any_shape.geo, ST_Point(3, 8)) YIELD ST_ASText(any_shape.geo);
Expand Down

0 comments on commit fb5ea40

Please sign in to comment.