-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change limit to expression. #2878
Changes from all commits
85d625a
1908e8a
43a114f
992f63b
d939c46
0f74fe7
9f895e8
23fb973
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,19 @@ class Explore : public SingleInputNode { | |
|
||
bool dedup() const { return dedup_; } | ||
|
||
int64_t limit() const { return limit_; } | ||
// Get the constant limit value | ||
int64_t limit() const { | ||
QueryExpressionContext ctx; | ||
DCHECK(ExpressionUtils::isEvaluableExpr(limit_)); | ||
return DCHECK_NOTNULL(limit_)->eval(ctx).getInt(); | ||
} | ||
|
||
// Get the limit value in runtime | ||
int64_t limit(QueryExpressionContext& ctx) const { | ||
return DCHECK_NOTNULL(limit_)->eval(ctx).getInt(); | ||
} | ||
|
||
Expression* limitExpr() const { return limit_; } | ||
|
||
const Expression* filter() const { return filter_; } | ||
|
||
|
@@ -45,7 +57,9 @@ class Explore : public SingleInputNode { | |
|
||
void setDedup(bool dedup = true) { dedup_ = dedup; } | ||
|
||
void setLimit(int64_t limit) { limit_ = limit; } | ||
void setLimit(int64_t limit) { limit_ = ConstantExpression::make(qctx_->objPool(), limit); } | ||
|
||
void setLimit(Expression* limit) { limit_ = limit; } | ||
|
||
void setFilter(Expression* filter) { filter_ = filter; } | ||
|
||
|
@@ -62,6 +76,21 @@ class Explore : public SingleInputNode { | |
int64_t limit, | ||
Expression* filter, | ||
std::vector<storage::cpp2::OrderBy> orderBy) | ||
: SingleInputNode(qctx, kind, input), | ||
space_(space), | ||
dedup_(dedup), | ||
limit_(ConstantExpression::make(qctx_->objPool(), limit)), | ||
filter_(std::move(filter)), | ||
orderBy_(std::move(orderBy)) {} | ||
|
||
Explore(QueryContext* qctx, | ||
Kind kind, | ||
PlanNode* input, | ||
GraphSpaceID space, | ||
bool dedup, | ||
Expression* limit, | ||
Expression* filter, | ||
std::vector<storage::cpp2::OrderBy> orderBy) | ||
: SingleInputNode(qctx, kind, input), | ||
space_(space), | ||
dedup_(dedup), | ||
|
@@ -77,7 +106,9 @@ class Explore : public SingleInputNode { | |
protected: | ||
GraphSpaceID space_; | ||
bool dedup_{false}; | ||
int64_t limit_{std::numeric_limits<int64_t>::max()}; | ||
// Use expression to get the limit value in runtime | ||
// Now for the GetNeighbors/Limit in Loop | ||
Expression* limit_{nullptr}; | ||
Expression* filter_{nullptr}; | ||
std::vector<storage::cpp2::OrderBy> orderBy_; | ||
}; | ||
|
@@ -640,9 +671,34 @@ class Limit final : public SingleInputNode { | |
return qctx->objPool()->add(new Limit(qctx, input, offset, count)); | ||
} | ||
|
||
static Limit* make(QueryContext* qctx, | ||
PlanNode* input, | ||
int64_t offset = -1, | ||
Expression* count = nullptr) { | ||
return qctx->objPool()->add(new Limit(qctx, input, offset, count)); | ||
} | ||
|
||
int64_t offset() const { return offset_; } | ||
|
||
int64_t count() const { return count_; } | ||
// Get constant count value | ||
int64_t count() const { | ||
if (count_ == nullptr) { | ||
return -1; | ||
} | ||
DCHECK(ExpressionUtils::isEvaluableExpr(count_)); | ||
QueryExpressionContext ctx; | ||
return count_->eval(ctx).getInt(); | ||
} | ||
Comment on lines
+684
to
+691
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this interface necessary? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Compatible. |
||
|
||
// Get count in runtime | ||
int64_t count(QueryExpressionContext& ctx) const { | ||
if (count_ == nullptr) { | ||
return -1; | ||
} | ||
return count_->eval(ctx).getInt(); | ||
} | ||
|
||
const Expression* countExpr() const { return count_; } | ||
|
||
PlanNode* clone() const override; | ||
std::unique_ptr<PlanNodeDescription> explain() const override; | ||
|
@@ -651,14 +707,20 @@ class Limit final : public SingleInputNode { | |
Limit(QueryContext* qctx, PlanNode* input, int64_t offset, int64_t count) | ||
: SingleInputNode(qctx, Kind::kLimit, input) { | ||
offset_ = offset; | ||
count_ = ConstantExpression::make(qctx_->objPool(), count); | ||
} | ||
|
||
Limit(QueryContext* qctx, PlanNode* input, int64_t offset, Expression* count) | ||
: SingleInputNode(qctx, Kind::kLimit, input) { | ||
offset_ = offset; | ||
count_ = count; | ||
} | ||
|
||
void cloneMembers(const Limit&); | ||
|
||
private: | ||
int64_t offset_{-1}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. offset won't push down There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is better to ensure consistency in use.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is used for new syntax for |
||
int64_t count_{-1}; | ||
Expression* count_{nullptr}; | ||
}; | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use DCHECK to debug your code if it's the regular branch you need to handle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't happen in correct state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So why did you do the same check in line 54?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle exception scenes