Skip to content
This repository was archived by the owner on May 9, 2024. It is now read-only.

Commit bf91404

Browse files
bagrorgkurapov-peter
authored andcommitted
Fix review issues and format code
1 parent 0d2e627 commit bf91404

File tree

4 files changed

+72
-71
lines changed

4 files changed

+72
-71
lines changed
Lines changed: 39 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,60 @@
1+
/*
2+
Copyright (c) 2023 Intel Corporation
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
114
#include "AnalyticalTemplatesExtractor.h"
215
#include <limits>
316
#include <stdexcept>
417
#include <vector>
518
#include "QueryEngine/CostModel/Measurements.h"
619
#include "QueryEngine/RelAlgExecutionUnit.h"
720

21+
std::vector<costmodel::AnalyticalTemplate> AnalyticalTemplatesExtractor::extractTemplates(
22+
const RelAlgExecutionUnit& ra_exe_unit) const {
23+
Priority current_priority = std::numeric_limits<Priority>::max();
24+
std::vector<costmodel::AnalyticalTemplate> templates;
825

9-
std::vector<costmodel::AnalyticalTemplate> AnalyticalTemplatesExtractor::extractTemplates(const RelAlgExecutionUnit &ra_exe_unit) const {
10-
Priority current_priority = std::numeric_limits<Priority>::max();
11-
std::vector<costmodel::AnalyticalTemplate> templates;
12-
13-
for (auto [priority, templ]: priotities_) {
14-
if (priority > current_priority) {
15-
return templates;
16-
}
17-
18-
if (templSuits(ra_exe_unit, templ)) {
19-
current_priority = priority;
20-
templates.push_back(templ);
21-
}
26+
for (auto [priority, templ] : priotities_) {
27+
if (priority > current_priority) {
28+
return templates;
2229
}
2330

24-
return templates;
25-
}
26-
27-
template <>
28-
bool AnalyticalTemplatesExtractor::templSuits<costmodel::AnalyticalTemplate::GroupBy>(const RelAlgExecutionUnit &ra_exe_unit) const {
29-
return !ra_exe_unit.groupby_exprs.empty();
30-
}
31-
32-
template <>
33-
bool AnalyticalTemplatesExtractor::templSuits<costmodel::AnalyticalTemplate::Join>(const RelAlgExecutionUnit &ra_exe_unit) const {
34-
return !ra_exe_unit.join_quals.empty();
35-
}
36-
37-
template <>
38-
bool AnalyticalTemplatesExtractor::templSuits<costmodel::AnalyticalTemplate::Scan>(const RelAlgExecutionUnit &ra_exe_unit) const {
39-
return !ra_exe_unit.quals.empty() || !ra_exe_unit.simple_quals.empty();
40-
}
41-
42-
template <>
43-
bool AnalyticalTemplatesExtractor::templSuits<costmodel::AnalyticalTemplate::Sort>(const RelAlgExecutionUnit &ra_exe_unit) const {
44-
return !ra_exe_unit.sort_info.order_entries.empty();
45-
}
31+
if (templSuits(ra_exe_unit, templ)) {
32+
current_priority = priority;
33+
templates.push_back(templ);
34+
}
35+
}
4636

47-
template <>
48-
bool AnalyticalTemplatesExtractor::templSuits<costmodel::AnalyticalTemplate::Reduce>(const RelAlgExecutionUnit &ra_exe_unit) const {
49-
// TODO(bagrorg): currently we don't even
50-
// use Reduce for cost model
51-
return false;
37+
return templates;
5238
}
5339

54-
bool AnalyticalTemplatesExtractor::templSuits(const RelAlgExecutionUnit &ra_exe_unit, costmodel::AnalyticalTemplate templ) const {
55-
using costmodel::AnalyticalTemplate;
40+
bool AnalyticalTemplatesExtractor::templSuits(const RelAlgExecutionUnit& ra_exe_unit,
41+
costmodel::AnalyticalTemplate templ) const {
42+
using costmodel::AnalyticalTemplate;
5643

57-
switch (templ) {
44+
switch (templ) {
5845
case AnalyticalTemplate::GroupBy:
59-
return templSuits<AnalyticalTemplate::GroupBy>(ra_exe_unit);
46+
return !ra_exe_unit.groupby_exprs.empty();
6047
case AnalyticalTemplate::Join:
61-
return templSuits<AnalyticalTemplate::Join>(ra_exe_unit);
48+
return !ra_exe_unit.join_quals.empty();
6249
case AnalyticalTemplate::Sort:
63-
return templSuits<AnalyticalTemplate::Sort>(ra_exe_unit);
50+
return !ra_exe_unit.sort_info.order_entries.empty();
6451
case AnalyticalTemplate::Reduce:
65-
return templSuits<AnalyticalTemplate::Reduce>(ra_exe_unit);
52+
// TODO(bagrorg): currently we don't even
53+
// use Reduce for cost model
54+
return false;
6655
case AnalyticalTemplate::Scan:
67-
return templSuits<AnalyticalTemplate::Scan>(ra_exe_unit);
56+
return !ra_exe_unit.quals.empty() || !ra_exe_unit.simple_quals.empty();
6857
default:
69-
throw std::runtime_error("Unknown template for check was given");
70-
}
58+
throw std::runtime_error("Unknown template for check was given");
59+
}
7160
}
Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,38 @@
1+
/*
2+
Copyright (c) 2023 Intel Corporation
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
114
#pragma once
215

316
#include "QueryEngine/CostModel/Measurements.h"
417
#include "QueryEngine/RelAlgExecutionUnit.h"
518

619
class AnalyticalTemplatesExtractor {
7-
public:
8-
std::vector<costmodel::AnalyticalTemplate> extractTemplates(const RelAlgExecutionUnit &ra_exe_unit) const;
20+
public:
21+
std::vector<costmodel::AnalyticalTemplate> extractTemplates(
22+
const RelAlgExecutionUnit& ra_exe_unit) const;
923

10-
private:
11-
using Priority = uint8_t;
24+
private:
25+
using Priority = uint8_t;
1226

13-
template <costmodel::AnalyticalTemplate templ>
14-
bool templSuits(const RelAlgExecutionUnit &ra_exe_unit) const;
27+
bool templSuits(const RelAlgExecutionUnit& ra_exe_unit,
28+
costmodel::AnalyticalTemplate templ) const;
1529

16-
bool templSuits(const RelAlgExecutionUnit &ra_exe_unit, costmodel::AnalyticalTemplate templ) const;
17-
18-
// We want to greedy extract templates
19-
std::map<Priority, costmodel::AnalyticalTemplate> priotities_ = {
20-
{0, costmodel::AnalyticalTemplate::GroupBy},
21-
{0, costmodel::AnalyticalTemplate::Join},
22-
{0, costmodel::AnalyticalTemplate::Sort},
23-
{1, costmodel::AnalyticalTemplate::Scan},
24-
{1, costmodel::AnalyticalTemplate::Reduce},
25-
};
30+
// We want to greedy extract templates
31+
const std::map<Priority, costmodel::AnalyticalTemplate> priotities_ = {
32+
{0, costmodel::AnalyticalTemplate::GroupBy},
33+
{0, costmodel::AnalyticalTemplate::Join},
34+
{0, costmodel::AnalyticalTemplate::Sort},
35+
{1, costmodel::AnalyticalTemplate::Scan},
36+
{1, costmodel::AnalyticalTemplate::Reduce},
37+
};
2638
};

omniscidb/QueryEngine/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,12 @@ set(query_engine_source_files
120120
DataRecycler/HashingSchemeRecycler.cpp
121121
Visitors/QueryPlanDagChecker.cpp
122122
WorkUnitBuilder.cpp
123+
AnalyticalTemplatesExtractor.cpp
123124

124125
Codec.h
125126
Execute.h
126127
NvidiaKernel.h
127-
QueryTemplateGenerator.h
128-
129-
AnalyticalTemplatesExtractor.cpp)
128+
QueryTemplateGenerator.h)
130129

131130
set(query_engine_cuda_source_files
132131
TopKSort.cu

omniscidb/QueryEngine/Execute.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "OSDependent/omnisci_path.h"
4444
#include "QueryEngine/AggregateUtils.h"
4545
#include "QueryEngine/AggregatedColRange.h"
46+
#include "QueryEngine/AnalyticalTemplatesExtractor.h"
4647
#include "QueryEngine/CodeGenerator.h"
4748
#include "QueryEngine/ColumnFetcher.h"
4849
#include "QueryEngine/CostModel/Dispatchers/DefaultExecutionPolicy.h"
@@ -78,7 +79,6 @@
7879
#include "Shared/misc.h"
7980
#include "Shared/scope.h"
8081
#include "ThirdParty/robin_hood.h"
81-
#include "QueryEngine/AnalyticalTemplatesExtractor.h"
8282

8383
#include "CostModel/IterativeCostModel.h"
8484

@@ -2127,7 +2127,8 @@ std::unique_ptr<policy::ExecutionPolicy> Executor::getExecutionPolicy(
21272127
CHECK(cfg.enable_heterogeneous_execution);
21282128

21292129
AnalyticalTemplatesExtractor extractor;
2130-
std::vector<costmodel::AnalyticalTemplate> templates = extractor.extractTemplates(ra_exe_unit);
2130+
std::vector<costmodel::AnalyticalTemplate> templates =
2131+
extractor.extractTemplates(ra_exe_unit);
21312132
if (config_->exec.enable_cost_model && ra_exe_unit.cost_model != nullptr &&
21322133
!templates.empty()) {
21332134
size_t bytes = 0;

0 commit comments

Comments
 (0)