Skip to content

Commit

Permalink
chore: refactor runner name & improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aceforeverd committed Nov 3, 2023
1 parent f315fd2 commit c5813ca
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 26 deletions.
21 changes: 21 additions & 0 deletions cases/query/fail_query.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,24 @@ cases:
SELECT 100 + 1s;
expect:
success: false
- id: 3
desc: unsupport join
inputs:
- name: t1
columns: ["c1 string","c2 int","c4 timestamp"]
indexs: ["index1:c1:c4"]
rows:
- ["aa",20,1000]
- ["bb",30,1000]
- name: t2
columns: ["c2 int","c4 timestamp"]
indexs: ["index1:c2:c4"]
rows:
- [20,3000]
- [20,2000]
sql: |
select t1.c1 as id, t2.* from t1 right join t2
on t1.c2 = t2.c2
expect:
success: false
msg: unsupport join type RightJoin
28 changes: 27 additions & 1 deletion cases/query/left_join.yml
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ cases:
t3.c1 as c1r,
t3.c2 as c2r,
t4.c3 as c3x
from t2 left join t3
from t2 left outer join t3
on t2.c1 = t3.c1 and t2.c2 > t3.c2
left join t4
on t2.c1 = t4.c1 and t3.c3 < t4.c3
Expand Down Expand Up @@ -354,3 +354,29 @@ cases:
bb, bb, NULL, NULL, NULL
cc, cc, cc, 27, NULL
dd, NULL, NULL, NULL, NULL
- id: 5
desc: simple left join
mode: request-unsupport
inputs:
- name: t1
columns: ["c1 string","c2 int","c4 timestamp"]
indexs: ["index1:c1:c4"]
rows:
- ["aa",20,1000]
- ["bb",30,1000]
- name: t2
columns: ["c2 int","c4 timestamp"]
indexs: ["index1:c2:c4"]
rows:
- [20,3000]
- [20,2000]
sql: |
select t1.c1 as id, t2.* from t1 left join t2
on t1.c2 = t2.c2
expect:
order: c1
columns: ["id string", "c2 int","c4 timestamp"]
data: |
aa, 20, 3000
aa, 20, 2000
bb, NULL, NULL
10 changes: 6 additions & 4 deletions hybridse/src/vm/runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ void WindowAggRunner::RunWindowAggOnKey(
}
}

std::shared_ptr<DataHandler> RequestLastJoinRunner::Run(
std::shared_ptr<DataHandler> RequestJoinRunner::Run(
RunnerContext& ctx,
const std::vector<std::shared_ptr<DataHandler>>& inputs) { // NOLINT
auto fail_ptr = std::shared_ptr<DataHandler>();
Expand All @@ -721,8 +721,10 @@ std::shared_ptr<DataHandler> RequestLastJoinRunner::Run(
return std::shared_ptr<RowHandler>(
new MemRowHandler(join_gen_->RowLastJoin(left_row, right, parameter)));
}
} else if (join_gen_->join_type_ == node::kJoinTypeLeft) {
return join_gen_->LazyJoin(left, right, ctx.GetParameterRow());

Check warning on line 725 in hybridse/src/vm/runner.cc

View check run for this annotation

Codecov / codecov/patch

hybridse/src/vm/runner.cc#L724-L725

Added lines #L724 - L725 were not covered by tests
} else {
// fix later
LOG(WARNING) << "unsupport join type " << node::JoinTypeName(join_gen_->join_type_);
return {};

Check warning on line 728 in hybridse/src/vm/runner.cc

View check run for this annotation

Codecov / codecov/patch

hybridse/src/vm/runner.cc#L727-L728

Added lines #L727 - L728 were not covered by tests
}
} else if (kPartitionHandler == left->GetHandlerType() && right->GetHandlerType() == kPartitionHandler) {
Expand All @@ -735,8 +737,8 @@ std::shared_ptr<DataHandler> RequestLastJoinRunner::Run(
return std::shared_ptr<DataHandler>();
}

std::shared_ptr<DataHandler> LastJoinRunner::Run(RunnerContext& ctx,
const std::vector<std::shared_ptr<DataHandler>>& inputs) {
std::shared_ptr<DataHandler> JoinRunner::Run(RunnerContext& ctx,
const std::vector<std::shared_ptr<DataHandler>>& inputs) {
auto fail_ptr = std::shared_ptr<DataHandler>();
if (inputs.size() < 2) {
LOG(WARNING) << "inputs size < 2";
Expand Down
34 changes: 17 additions & 17 deletions hybridse/src/vm/runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ enum RunnerType {
kRunnerRequestAggUnion,
kRunnerPostRequestUnion,
kRunnerIndexSeek,
kRunnerLastJoin,
kRunnerJoin,
kRunnerConcat,
kRunnerRequestRunProxy,
kRunnerRequestLastJoin,
kRunnerRequestJoin,
kRunnerBatchRequestRunProxy,
kRunnerLimit,
kRunnerUnknow,
Expand Down Expand Up @@ -114,12 +114,12 @@ inline const std::string RunnerTypeName(const RunnerType& type) {
return "POST_REQUEST_UNION";
case kRunnerIndexSeek:
return "INDEX_SEEK";
case kRunnerLastJoin:
return "LASTJOIN";
case kRunnerJoin:
return "JOIN";
case kRunnerConcat:
return "CONCAT";
case kRunnerRequestLastJoin:
return "REQUEST_LASTJOIN";
case kRunnerRequestJoin:
return "REQUEST_JOIN";
case kRunnerLimit:
return "LIMIT";
case kRunnerRequestRunProxy:
Expand Down Expand Up @@ -699,30 +699,30 @@ class PostRequestUnionRunner : public Runner {
OrderGenerator request_ts_gen_;
};

class LastJoinRunner : public Runner {
class JoinRunner : public Runner {
public:
LastJoinRunner(const int32_t id, const SchemasContext* schema, const std::optional<int32_t> limit_cnt,
const Join& join, size_t left_slices, size_t right_slices)
: Runner(id, kRunnerLastJoin, schema, limit_cnt) {
JoinRunner(const int32_t id, const SchemasContext* schema, const std::optional<int32_t> limit_cnt, const Join& join,
size_t left_slices, size_t right_slices)
: Runner(id, kRunnerJoin, schema, limit_cnt) {
join_gen_ = JoinGenerator::Create(join, left_slices, right_slices);
}
~LastJoinRunner() {}
~JoinRunner() {}
std::shared_ptr<DataHandler> Run(
RunnerContext& ctx, // NOLINT
const std::vector<std::shared_ptr<DataHandler>>& inputs)
override; // NOLINT

std::shared_ptr<JoinGenerator> join_gen_;
};
class RequestLastJoinRunner : public Runner {
class RequestJoinRunner : public Runner {
public:
RequestLastJoinRunner(const int32_t id, const SchemasContext* schema, const std::optional<int32_t> limit_cnt,
const Join& join, const size_t left_slices, const size_t right_slices,
const bool output_right_only)
: Runner(id, kRunnerRequestLastJoin, schema, limit_cnt), output_right_only_(output_right_only) {
RequestJoinRunner(const int32_t id, const SchemasContext* schema, const std::optional<int32_t> limit_cnt,
const Join& join, const size_t left_slices, const size_t right_slices,
const bool output_right_only)
: Runner(id, kRunnerRequestJoin, schema, limit_cnt), output_right_only_(output_right_only) {
join_gen_ = JoinGenerator::Create(join, left_slices, right_slices);
}
~RequestLastJoinRunner() {}
~RequestJoinRunner() {}

std::shared_ptr<DataHandler> Run(
RunnerContext& ctx, // NOLINT
Expand Down
8 changes: 4 additions & 4 deletions hybridse/src/vm/runner_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ ClusterTask RunnerBuilder::Build(PhysicalOpNode* node, Status& status) {
switch (op->join().join_type()) {
case node::kJoinTypeLast:
case node::kJoinTypeLeft: {
RequestLastJoinRunner* runner = CreateRunner<RequestLastJoinRunner>(
RequestJoinRunner* runner = CreateRunner<RequestJoinRunner>(
id_++, node->schemas_ctx(), op->GetLimitCnt(), op->join_,
left->output_schemas()->GetSchemaSourceSize(), right->output_schemas()->GetSchemaSourceSize(),
op->output_right_only());
Expand Down Expand Up @@ -414,15 +414,15 @@ ClusterTask RunnerBuilder::Build(PhysicalOpNode* node, Status& status) {
// TableLastJoin convert to Batch Request RequestLastJoin
if (support_cluster_optimized_) {
// looks strange, join op won't run for batch-cluster mode
RequestLastJoinRunner* runner = CreateRunner<RequestLastJoinRunner>(
RequestJoinRunner* runner = CreateRunner<RequestJoinRunner>(
id_++, node->schemas_ctx(), op->GetLimitCnt(), op->join_,
left->output_schemas()->GetSchemaSourceSize(),
right->output_schemas()->GetSchemaSourceSize(), op->output_right_only_);
return RegisterTask(
node, BinaryInherit(left_task, right_task, runner, op->join().index_key(), kLeftBias));
} else {
LastJoinRunner* runner =
CreateRunner<LastJoinRunner>(id_++, node->schemas_ctx(), op->GetLimitCnt(), op->join_,
JoinRunner* runner =
CreateRunner<JoinRunner>(id_++, node->schemas_ctx(), op->GetLimitCnt(), op->join_,
left->output_schemas()->GetSchemaSourceSize(),
right->output_schemas()->GetSchemaSourceSize());
return RegisterTask(node, BinaryInherit(left_task, right_task, runner, Key(), kLeftBias));
Expand Down

0 comments on commit c5813ca

Please sign in to comment.