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

Commit 8958960

Browse files
committed
Review comments. Privatize functions, move body to cpp
1 parent f08dd62 commit 8958960

File tree

2 files changed

+81
-71
lines changed

2 files changed

+81
-71
lines changed

src/include/planner/insert_plan.h

Lines changed: 5 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
#pragma once
1414

15-
#include "expression/constant_value_expression.h"
16-
#include "storage/data_table.h"
1715
#include "planner/abstract_plan.h"
1816
#include "planner/abstract_scan_plan.h"
1917
#include "planner/project_info.h"
@@ -202,15 +200,7 @@ class InsertPlan : public AbstractPlan {
202200
*/
203201
bool FindSchemaColIndex(std::string col_name,
204202
const std::vector<catalog::Column> &tbl_columns,
205-
uint32_t &index) {
206-
for (auto tcol = tbl_columns.begin(); tcol != tbl_columns.end(); tcol++) {
207-
if (tcol->GetName() == col_name) {
208-
index = std::distance(tbl_columns.begin(), tcol);
209-
return true;
210-
}
211-
}
212-
return false;
213-
}
203+
uint32_t &index);
214204

215205
/**
216206
* Process column specification supplied in the insert statement.
@@ -220,30 +210,7 @@ class InsertPlan : public AbstractPlan {
220210
*
221211
* @param[in] columns Column specification
222212
*/
223-
void ProcessColumnSpec(const std::vector<std::string> *columns) {
224-
auto *schema = target_table_->GetSchema();
225-
auto &table_columns = schema->GetColumns();
226-
auto usr_col_count = columns->size();
227-
228-
// iterate over supplied columns
229-
for (size_t usr_col_id = 0; usr_col_id < usr_col_count; usr_col_id++) {
230-
uint32_t idx;
231-
auto col_name = columns->at(usr_col_id);
232-
233-
// determine index of column in schema
234-
bool found_col = FindSchemaColIndex(col_name, table_columns, idx);
235-
if (not found_col) {
236-
throw Exception("column " + col_name + " not in table " +
237-
target_table_->GetName() + " columns");
238-
}
239-
// we have values for this column
240-
schema_to_insert_[idx].in_insert_cols = true;
241-
// remember how to map schema col -> value for col in tuple
242-
schema_to_insert_[idx].val_idx = usr_col_id;
243-
// and the reverse
244-
insert_to_schema_[usr_col_id] = idx;
245-
}
246-
}
213+
void ProcessColumnSpec(const std::vector<std::string> *columns);
247214

248215
/**
249216
* Process a single expression to be inserted.
@@ -256,48 +223,15 @@ class InsertPlan : public AbstractPlan {
256223
* out the insert being a prepared statement.
257224
*/
258225
bool ProcessValueExpr(expression::AbstractExpression *expr,
259-
uint32_t schema_idx) {
260-
auto type = schema_to_insert_[schema_idx].type;
261-
262-
if (expr == nullptr) {
263-
SetDefaultValue(schema_idx);
264-
} else if (expr->GetExpressionType() == ExpressionType::VALUE_CONSTANT) {
265-
266-
auto *const_expr =
267-
dynamic_cast<expression::ConstantValueExpression *>(expr);
268-
type::Value value = const_expr->GetValue().CastAs(type);
269-
270-
schema_to_insert_[schema_idx].set_value = true;
271-
schema_to_insert_[schema_idx].value = value;
272-
// save it, in case this is not a PS
273-
values_.push_back(value);
274-
275-
return false;
276-
} else {
277-
PELOTON_ASSERT(expr->GetExpressionType() ==
278-
ExpressionType::VALUE_PARAMETER);
279-
return true;
280-
}
281-
return false;
282-
}
226+
uint32_t schema_idx);
283227

284228
/**
285229
* Set default value into a schema column
286230
*
287231
* @param[in] idx schema column index
288232
*/
289-
void SetDefaultValue(uint32_t idx) {
290-
auto *schema = target_table_->GetSchema();
291-
type::Value *v = schema->GetDefaultValue(idx);
292-
type::TypeId type = schema_to_insert_[idx].type;
293-
294-
if (v == nullptr)
295-
// null default value
296-
values_.push_back(type::ValueFactory::GetNullValueByType(type));
297-
else
298-
// non-null default value
299-
values_.push_back(*v);
300-
}
233+
void SetDefaultValue(uint32_t idx);
234+
301235
};
302236
} // namespace planner
303237
} // namespace peloton

src/planner/insert_plan.cpp

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,82 @@ InsertPlan::InsertPlan(storage::DataTable *table,
126126
}
127127
}
128128

129+
bool InsertPlan::FindSchemaColIndex(std::string col_name,
130+
const std::vector<catalog::Column> &tbl_columns,
131+
uint32_t &index) {
132+
for (auto tcol = tbl_columns.begin(); tcol != tbl_columns.end(); tcol++) {
133+
if (tcol->GetName() == col_name) {
134+
index = std::distance(tbl_columns.begin(), tcol);
135+
return true;
136+
}
137+
}
138+
return false;
139+
}
140+
141+
void InsertPlan::ProcessColumnSpec(const std::vector<std::string> *columns) {
142+
auto *schema = target_table_->GetSchema();
143+
auto &table_columns = schema->GetColumns();
144+
auto usr_col_count = columns->size();
145+
146+
// iterate over supplied columns
147+
for (size_t usr_col_id = 0; usr_col_id < usr_col_count; usr_col_id++) {
148+
uint32_t idx;
149+
auto col_name = columns->at(usr_col_id);
150+
151+
// determine index of column in schema
152+
bool found_col = FindSchemaColIndex(col_name, table_columns, idx);
153+
if (not found_col) {
154+
throw Exception("column " + col_name + " not in table " +
155+
target_table_->GetName() + " columns");
156+
}
157+
// we have values for this column
158+
schema_to_insert_[idx].in_insert_cols = true;
159+
// remember how to map schema col -> value for col in tuple
160+
schema_to_insert_[idx].val_idx = usr_col_id;
161+
// and the reverse
162+
insert_to_schema_[usr_col_id] = idx;
163+
}
164+
}
165+
166+
bool InsertPlan::ProcessValueExpr(expression::AbstractExpression *expr,
167+
uint32_t schema_idx) {
168+
auto type = schema_to_insert_[schema_idx].type;
169+
170+
if (expr == nullptr) {
171+
SetDefaultValue(schema_idx);
172+
} else if (expr->GetExpressionType() == ExpressionType::VALUE_CONSTANT) {
173+
174+
auto *const_expr =
175+
dynamic_cast<expression::ConstantValueExpression *>(expr);
176+
type::Value value = const_expr->GetValue().CastAs(type);
177+
178+
schema_to_insert_[schema_idx].set_value = true;
179+
schema_to_insert_[schema_idx].value = value;
180+
// save it, in case this is not a PS
181+
values_.push_back(value);
182+
183+
return false;
184+
} else {
185+
PELOTON_ASSERT(expr->GetExpressionType() ==
186+
ExpressionType::VALUE_PARAMETER);
187+
return true;
188+
}
189+
return false;
190+
}
191+
192+
void InsertPlan::SetDefaultValue(uint32_t idx) {
193+
auto *schema = target_table_->GetSchema();
194+
type::Value *v = schema->GetDefaultValue(idx);
195+
type::TypeId type = schema_to_insert_[idx].type;
196+
197+
if (v == nullptr)
198+
// null default value
199+
values_.push_back(type::ValueFactory::GetNullValueByType(type));
200+
else
201+
// non-null default value
202+
values_.push_back(*v);
203+
}
204+
129205
type::AbstractPool *InsertPlan::GetPlanPool() {
130206
if (pool_.get() == nullptr)
131207
pool_.reset(new type::EphemeralPool());

0 commit comments

Comments
 (0)