Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit 9ec13a7

Browse files
committed
Extracted implementation into CPP file for plan node
1 parent cfd17e3 commit 9ec13a7

File tree

4 files changed

+179
-133
lines changed

4 files changed

+179
-133
lines changed

src/include/planner/csv_scan_plan.h

Lines changed: 7 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,21 @@
1212

1313
#pragma once
1414

15+
#include <memory>
1516
#include <numeric>
17+
#include <string>
18+
#include <vector>
1619

17-
#include "codegen/type/type.h"
1820
#include "planner/abstract_scan_plan.h"
1921
#include "planner/attribute_info.h"
22+
#include "type/type_id.h"
2023

2124
namespace peloton {
2225
namespace planner {
2326

27+
/**
28+
* This is the plan node when scanning a CSV file.
29+
*/
2430
class CSVScanPlan : public AbstractScan {
2531
public:
2632
struct ColumnInfo {
@@ -87,82 +93,5 @@ class CSVScanPlan : public AbstractScan {
8793
std::vector<planner::AttributeInfo> attributes_;
8894
};
8995

90-
////////////////////////////////////////////////////////////////////////////////
91-
///
92-
/// Implementation below
93-
///
94-
////////////////////////////////////////////////////////////////////////////////
95-
96-
inline CSVScanPlan::CSVScanPlan(std::string file_name,
97-
std::vector<CSVScanPlan::ColumnInfo> &&cols,
98-
char delimiter, char quote, char escape,
99-
std::string null)
100-
: file_name_(std::move(file_name)),
101-
delimiter_(delimiter),
102-
quote_(quote),
103-
escape_(escape),
104-
null_(null) {
105-
attributes_.resize(cols.size());
106-
for (uint32_t i = 0; i < cols.size(); i++) {
107-
const auto &col_info = cols[i];
108-
attributes_[i].type = codegen::type::Type{col_info.type, true};
109-
attributes_[i].attribute_id = i;
110-
attributes_[i].name = col_info.name;
111-
}
112-
}
113-
114-
inline PlanNodeType CSVScanPlan::GetPlanNodeType() const {
115-
return PlanNodeType::CSVSCAN;
116-
}
117-
118-
inline std::unique_ptr<AbstractPlan> CSVScanPlan::Copy() const {
119-
std::vector<CSVScanPlan::ColumnInfo> new_cols;
120-
for (const auto &attribute : attributes_) {
121-
new_cols.push_back(CSVScanPlan::ColumnInfo{.name = attribute.name,
122-
.type = attribute.type.type_id});
123-
}
124-
return std::unique_ptr<AbstractPlan>(
125-
new CSVScanPlan(file_name_, std::move(new_cols)));
126-
}
127-
128-
inline void CSVScanPlan::PerformBinding(BindingContext &binding_context) {
129-
for (uint32_t i = 0; i < attributes_.size(); i++) {
130-
binding_context.BindNew(i, &attributes_[i]);
131-
}
132-
}
133-
134-
inline void CSVScanPlan::GetOutputColumns(std::vector<oid_t> &columns) const {
135-
columns.clear();
136-
columns.resize(attributes_.size());
137-
std::iota(columns.begin(), columns.end(), 0);
138-
}
139-
140-
inline hash_t CSVScanPlan::Hash() const {
141-
hash_t hash = HashUtil::HashBytes(file_name_.data(), file_name_.length());
142-
hash = HashUtil::CombineHashes(hash, HashUtil::Hash(&delimiter_));
143-
hash = HashUtil::CombineHashes(hash, HashUtil::Hash(&quote_));
144-
hash = HashUtil::CombineHashes(hash, HashUtil::Hash(&escape_));
145-
hash = HashUtil::CombineHashes(
146-
hash, HashUtil::HashBytes(null_.c_str(), null_.length()));
147-
return hash;
148-
}
149-
150-
inline bool CSVScanPlan::operator==(const AbstractPlan &rhs) const {
151-
if (rhs.GetPlanNodeType() != PlanNodeType::CSVSCAN) return false;
152-
const auto &other = static_cast<const CSVScanPlan &>(rhs);
153-
return (
154-
(StringUtil::Upper(file_name_) == StringUtil::Upper(other.file_name_)) &&
155-
delimiter_ == other.delimiter_ && quote_ == other.quote_ &&
156-
escape_ == other.escape_);
157-
}
158-
159-
inline void CSVScanPlan::GetAttributes(
160-
std::vector<const AttributeInfo *> &ais) const {
161-
ais.clear();
162-
for (const auto &ai : attributes_) {
163-
ais.push_back(&ai);
164-
}
165-
}
166-
16796
} // namespace planner
16897
} // namespace peloton

src/include/planner/export_external_file_plan.h

Lines changed: 9 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,20 @@
1212

1313
#pragma once
1414

15-
#include "concurrency/transaction_context.h"
15+
#include <memory>
16+
#include <vector>
17+
#include <string>
18+
1619
#include "planner/abstract_plan.h"
1720

1821
namespace peloton {
1922
namespace planner {
2023

24+
/**
25+
* This is the plan node when exporting data from the database into an external
26+
* file. It is configured with the name of the file to write content into, and
27+
* the delimiter, quote, and escape characters to use when writing content.
28+
*/
2129
class ExportExternalFilePlan : public AbstractPlan {
2230
public:
2331
ExportExternalFilePlan(std::string file_name, char delimiter = ',',
@@ -61,59 +69,5 @@ class ExportExternalFilePlan : public AbstractPlan {
6169
char escape_;
6270
};
6371

64-
////////////////////////////////////////////////////////////////////////////////
65-
///
66-
/// Implementation below
67-
///
68-
////////////////////////////////////////////////////////////////////////////////
69-
70-
inline ExportExternalFilePlan::ExportExternalFilePlan(std::string file_name,
71-
char delimiter,
72-
char quote, char escape)
73-
: file_name_(file_name),
74-
delimiter_(delimiter),
75-
quote_(quote),
76-
escape_(escape) {}
77-
78-
inline PlanNodeType ExportExternalFilePlan::GetPlanNodeType() const {
79-
return PlanNodeType::EXPORT_EXTERNAL_FILE;
80-
}
81-
82-
inline hash_t ExportExternalFilePlan::Hash() const {
83-
hash_t hash = HashUtil::HashBytes(file_name_.data(), file_name_.length());
84-
hash = HashUtil::CombineHashes(hash, HashUtil::Hash(&delimiter_));
85-
hash = HashUtil::CombineHashes(hash, HashUtil::Hash(&quote_));
86-
hash = HashUtil::CombineHashes(hash, HashUtil::Hash(&escape_));
87-
return hash;
88-
}
89-
90-
inline bool ExportExternalFilePlan::operator==(const AbstractPlan &rhs) const {
91-
if (rhs.GetPlanNodeType() != PlanNodeType::EXPORT_EXTERNAL_FILE) return false;
92-
const auto &other = static_cast<const ExportExternalFilePlan &>(rhs);
93-
return (
94-
(StringUtil::Upper(file_name_) == StringUtil::Upper(other.file_name_)) &&
95-
delimiter_ == other.delimiter_ && quote_ == other.quote_ &&
96-
escape_ == other.escape_);
97-
}
98-
99-
inline std::unique_ptr<AbstractPlan> ExportExternalFilePlan::Copy() const {
100-
return std::unique_ptr<AbstractPlan>{
101-
new ExportExternalFilePlan(file_name_, delimiter_, quote_, escape_)};
102-
}
103-
104-
inline void ExportExternalFilePlan::PerformBinding(
105-
BindingContext &binding_context) {
106-
PELOTON_ASSERT(GetChildrenSize() == 1);
107-
auto &child = *GetChild(0);
108-
109-
std::vector<oid_t> child_output_cols;
110-
child.GetOutputColumns(child_output_cols);
111-
112-
output_attributes_.clear();
113-
for (const auto &col_id : child_output_cols) {
114-
output_attributes_.push_back(binding_context.Find(col_id));
115-
}
116-
}
117-
11872
} // namespace planner
11973
} // namespace peloton

src/planner/csv_scan_plan.cpp

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Peloton
4+
//
5+
// csv_scan_plan.cpp
6+
//
7+
// Identification: src/planner/csv_scan_plan.cpp
8+
//
9+
// Copyright (c) 2015-2018, Carnegie Mellon University Database Group
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "planner/csv_scan_plan.h"
14+
15+
#include <numeric>
16+
17+
#include "codegen/type/type.h"
18+
19+
namespace peloton {
20+
namespace planner {
21+
22+
CSVScanPlan::CSVScanPlan(std::string file_name,
23+
std::vector<CSVScanPlan::ColumnInfo> &&cols,
24+
char delimiter, char quote, char escape,
25+
std::string null)
26+
: file_name_(std::move(file_name)),
27+
delimiter_(delimiter),
28+
quote_(quote),
29+
escape_(escape),
30+
null_(null) {
31+
attributes_.resize(cols.size());
32+
for (uint32_t i = 0; i < cols.size(); i++) {
33+
const auto &col_info = cols[i];
34+
attributes_[i].type = codegen::type::Type{col_info.type, true};
35+
attributes_[i].attribute_id = i;
36+
attributes_[i].name = col_info.name;
37+
}
38+
}
39+
40+
PlanNodeType CSVScanPlan::GetPlanNodeType() const {
41+
return PlanNodeType::CSVSCAN;
42+
}
43+
44+
std::unique_ptr<AbstractPlan> CSVScanPlan::Copy() const {
45+
std::vector<CSVScanPlan::ColumnInfo> new_cols;
46+
for (const auto &attribute : attributes_) {
47+
new_cols.push_back(CSVScanPlan::ColumnInfo{.name = attribute.name,
48+
.type = attribute.type.type_id});
49+
}
50+
return std::unique_ptr<AbstractPlan>(
51+
new CSVScanPlan(file_name_, std::move(new_cols)));
52+
}
53+
54+
void CSVScanPlan::PerformBinding(BindingContext &binding_context) {
55+
for (uint32_t i = 0; i < attributes_.size(); i++) {
56+
binding_context.BindNew(i, &attributes_[i]);
57+
}
58+
}
59+
60+
void CSVScanPlan::GetOutputColumns(std::vector<oid_t> &columns) const {
61+
columns.clear();
62+
columns.resize(attributes_.size());
63+
std::iota(columns.begin(), columns.end(), 0);
64+
}
65+
66+
hash_t CSVScanPlan::Hash() const {
67+
hash_t hash = HashUtil::HashBytes(file_name_.data(), file_name_.length());
68+
hash = HashUtil::CombineHashes(hash, HashUtil::Hash(&delimiter_));
69+
hash = HashUtil::CombineHashes(hash, HashUtil::Hash(&quote_));
70+
hash = HashUtil::CombineHashes(hash, HashUtil::Hash(&escape_));
71+
hash = HashUtil::CombineHashes(
72+
hash, HashUtil::HashBytes(null_.c_str(), null_.length()));
73+
return hash;
74+
}
75+
76+
bool CSVScanPlan::operator==(const AbstractPlan &rhs) const {
77+
if (rhs.GetPlanNodeType() != PlanNodeType::CSVSCAN) return false;
78+
const auto &other = static_cast<const CSVScanPlan &>(rhs);
79+
return (
80+
(StringUtil::Upper(file_name_) == StringUtil::Upper(other.file_name_)) &&
81+
delimiter_ == other.delimiter_ && quote_ == other.quote_ &&
82+
escape_ == other.escape_);
83+
}
84+
85+
void CSVScanPlan::GetAttributes(std::vector<const AttributeInfo *> &ais) const {
86+
ais.clear();
87+
for (const auto &ai : attributes_) {
88+
ais.push_back(&ai);
89+
}
90+
}
91+
92+
} // namespace planner
93+
} // namespace peloton
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Peloton
4+
//
5+
// export_external_file_plan.cpp
6+
//
7+
// Identification: src/planner/export_external_file_plan.cpp
8+
//
9+
// Copyright (c) 2015-2018, Carnegie Mellon University Database Group
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "planner/export_external_file_plan.h"
14+
15+
#include "common/macros.h"
16+
#include "util/hash_util.h"
17+
#include "util/string_util.h"
18+
19+
namespace peloton {
20+
namespace planner {
21+
22+
ExportExternalFilePlan::ExportExternalFilePlan(std::string file_name,
23+
char delimiter, char quote,
24+
char escape)
25+
: file_name_(file_name),
26+
delimiter_(delimiter),
27+
quote_(quote),
28+
escape_(escape) {}
29+
30+
PlanNodeType ExportExternalFilePlan::GetPlanNodeType() const {
31+
return PlanNodeType::EXPORT_EXTERNAL_FILE;
32+
}
33+
34+
hash_t ExportExternalFilePlan::Hash() const {
35+
hash_t hash = HashUtil::HashBytes(file_name_.data(), file_name_.length());
36+
hash = HashUtil::CombineHashes(hash, HashUtil::Hash(&delimiter_));
37+
hash = HashUtil::CombineHashes(hash, HashUtil::Hash(&quote_));
38+
hash = HashUtil::CombineHashes(hash, HashUtil::Hash(&escape_));
39+
return hash;
40+
}
41+
42+
bool ExportExternalFilePlan::operator==(const AbstractPlan &rhs) const {
43+
if (rhs.GetPlanNodeType() != PlanNodeType::EXPORT_EXTERNAL_FILE) return false;
44+
const auto &other = static_cast<const ExportExternalFilePlan &>(rhs);
45+
return (
46+
(StringUtil::Upper(file_name_) == StringUtil::Upper(other.file_name_)) &&
47+
delimiter_ == other.delimiter_ && quote_ == other.quote_ &&
48+
escape_ == other.escape_);
49+
}
50+
51+
std::unique_ptr<AbstractPlan> ExportExternalFilePlan::Copy() const {
52+
return std::unique_ptr<AbstractPlan>{
53+
new ExportExternalFilePlan(file_name_, delimiter_, quote_, escape_)};
54+
}
55+
56+
void ExportExternalFilePlan::PerformBinding(BindingContext &binding_context) {
57+
PELOTON_ASSERT(GetChildrenSize() == 1);
58+
auto &child = *GetChild(0);
59+
60+
std::vector<oid_t> child_output_cols;
61+
child.GetOutputColumns(child_output_cols);
62+
63+
output_attributes_.clear();
64+
for (const auto &col_id : child_output_cols) {
65+
output_attributes_.push_back(binding_context.Find(col_id));
66+
}
67+
}
68+
69+
} // namespace planner
70+
} // namespace peloton

0 commit comments

Comments
 (0)