21
21
namespace peloton {
22
22
namespace planner {
23
23
24
- InsertPlan::InsertPlan (storage::DataTable *table,
25
- const std::vector<std::string> *columns,
24
+ InsertPlan::InsertPlan (
25
+ storage::DataTable *table, const std::vector<std::string> *columns,
26
26
const std::vector<std::vector<
27
27
std::unique_ptr<expression::AbstractExpression>>> *insert_values)
28
28
: target_table_(table), bulk_insert_count_(insert_values->size ()) {
@@ -31,8 +31,8 @@ InsertPlan::InsertPlan(storage::DataTable *table,
31
31
32
32
// We assume we are not processing a prepared statement insert.
33
33
// Only after we have finished processing, do we know if it is a
34
- // PS or not a PS.
35
- bool is_prepared_stmt = false ;
34
+ // PS or not a PS.
35
+ bool is_prepared_stmt = false ;
36
36
auto *schema = target_table_->GetSchema ();
37
37
auto schema_col_count = schema->GetColumnCount ();
38
38
insert_to_schema_.resize (columns->size ());
@@ -46,7 +46,7 @@ InsertPlan::InsertPlan(storage::DataTable *table,
46
46
// remember the column types
47
47
schema_to_insert_[idx].type = schema->GetType (idx);
48
48
}
49
-
49
+
50
50
if (columns->empty ()) {
51
51
// INSERT INTO table_name VALUES (val1, val2, ...), (val1, val2, ...)
52
52
for (uint32_t tuple_idx = 0 ; tuple_idx < insert_values->size ();
@@ -55,7 +55,6 @@ InsertPlan::InsertPlan(storage::DataTable *table,
55
55
PELOTON_ASSERT (values.size () <= schema_col_count);
56
56
// uint32_t param_idx = 0;
57
57
for (uint32_t column_id = 0 ; column_id < values.size (); column_id++) {
58
-
59
58
auto &exp = values[column_id];
60
59
auto exp_ptr = exp.get ();
61
60
auto ret_bool = ProcessValueExpr (exp_ptr, column_id);
@@ -78,7 +77,7 @@ InsertPlan::InsertPlan(storage::DataTable *table,
78
77
tuple_idx++) {
79
78
auto &values = (*insert_values)[tuple_idx];
80
79
PELOTON_ASSERT (values.size () <= schema_col_count);
81
-
80
+
82
81
for (uint32_t idx = 0 ; idx < schema_col_count; idx++) {
83
82
if (schema_to_insert_[idx].in_insert_cols ) {
84
83
// this schema column is present in the insert columns spec.
@@ -105,7 +104,7 @@ InsertPlan::InsertPlan(storage::DataTable *table,
105
104
// Adjust the mapping from schema cols -> values vector to exclude
106
105
// the constant columns. If there are no constants, this is a no-op.
107
106
uint32_t adjust = 0 ;
108
- for (uint32_t idx= 0 ; idx < columns->size (); idx++) {
107
+ for (uint32_t idx = 0 ; idx < columns->size (); idx++) {
109
108
uint32_t stov_idx = insert_to_schema_[idx];
110
109
if (schema_to_insert_[stov_idx].set_value ) {
111
110
// constant, not present in PS values
@@ -126,9 +125,9 @@ InsertPlan::InsertPlan(storage::DataTable *table,
126
125
}
127
126
}
128
127
129
- bool InsertPlan::FindSchemaColIndex (std::string col_name,
130
- const std::vector<catalog::Column> &tbl_columns,
131
- uint32_t &index) {
128
+ bool InsertPlan::FindSchemaColIndex (
129
+ std::string col_name, const std::vector<catalog::Column> &tbl_columns,
130
+ uint32_t &index) {
132
131
for (auto tcol = tbl_columns.begin (); tcol != tbl_columns.end (); tcol++) {
133
132
if (tcol->GetName () == col_name) {
134
133
index = std::distance (tbl_columns.begin (), tcol);
@@ -141,13 +140,13 @@ bool InsertPlan::FindSchemaColIndex(std::string col_name,
141
140
void InsertPlan::ProcessColumnSpec (const std::vector<std::string> *columns) {
142
141
auto *schema = target_table_->GetSchema ();
143
142
auto &table_columns = schema->GetColumns ();
144
- auto usr_col_count = columns->size ();
145
-
143
+ auto usr_col_count = columns->size ();
144
+
146
145
// iterate over supplied columns
147
146
for (size_t usr_col_id = 0 ; usr_col_id < usr_col_count; usr_col_id++) {
148
- uint32_t idx;
147
+ uint32_t idx;
149
148
auto col_name = columns->at (usr_col_id);
150
-
149
+
151
150
// determine index of column in schema
152
151
bool found_col = FindSchemaColIndex (col_name, table_columns, idx);
153
152
if (not found_col) {
@@ -164,22 +163,21 @@ void InsertPlan::ProcessColumnSpec(const std::vector<std::string> *columns) {
164
163
}
165
164
166
165
bool InsertPlan::ProcessValueExpr (expression::AbstractExpression *expr,
167
- uint32_t schema_idx) {
166
+ uint32_t schema_idx) {
168
167
auto type = schema_to_insert_[schema_idx].type ;
169
-
168
+
170
169
if (expr == nullptr ) {
171
170
SetDefaultValue (schema_idx);
172
171
} else if (expr->GetExpressionType () == ExpressionType::VALUE_CONSTANT) {
173
-
174
172
auto *const_expr =
175
- dynamic_cast <expression::ConstantValueExpression *>(expr);
173
+ dynamic_cast <expression::ConstantValueExpression *>(expr);
176
174
type::Value value = const_expr->GetValue ().CastAs (type);
177
-
175
+
178
176
schema_to_insert_[schema_idx].set_value = true ;
179
177
schema_to_insert_[schema_idx].value = value;
180
178
// save it, in case this is not a PS
181
179
values_.push_back (value);
182
-
180
+
183
181
return false ;
184
182
} else {
185
183
PELOTON_ASSERT (expr->GetExpressionType () ==
@@ -190,21 +188,20 @@ bool InsertPlan::ProcessValueExpr(expression::AbstractExpression *expr,
190
188
}
191
189
192
190
void InsertPlan::SetDefaultValue (uint32_t idx) {
193
- auto *schema = target_table_->GetSchema ();
191
+ auto *schema = target_table_->GetSchema ();
194
192
type::Value *v = schema->GetDefaultValue (idx);
195
193
type::TypeId type = schema_to_insert_[idx].type ;
196
-
194
+
197
195
if (v == nullptr )
198
196
// null default value
199
197
values_.push_back (type::ValueFactory::GetNullValueByType (type));
200
198
else
201
199
// non-null default value
202
200
values_.push_back (*v);
203
- }
201
+ }
204
202
205
203
type::AbstractPool *InsertPlan::GetPlanPool () {
206
- if (pool_.get () == nullptr )
207
- pool_.reset (new type::EphemeralPool ());
204
+ if (pool_.get () == nullptr ) pool_.reset (new type::EphemeralPool ());
208
205
return pool_.get ();
209
206
}
210
207
@@ -221,7 +218,7 @@ void InsertPlan::SetParameterValues(std::vector<type::Value> *values) {
221
218
// get index into values
222
219
auto val_idx = schema_to_insert_[idx].val_idx ;
223
220
auto type = schema_to_insert_[idx].type ;
224
- type::Value value = values->at (val_idx).CastAs (type);
221
+ type::Value value = values->at (val_idx).CastAs (type);
225
222
values_.push_back (value);
226
223
} else {
227
224
// not in insert cols, set default value
@@ -259,23 +256,19 @@ hash_t InsertPlan::Hash() const {
259
256
}
260
257
261
258
bool InsertPlan::operator ==(const AbstractPlan &rhs) const {
262
- if (GetPlanNodeType () != rhs.GetPlanNodeType ())
263
- return false ;
259
+ if (GetPlanNodeType () != rhs.GetPlanNodeType ()) return false ;
264
260
265
261
auto &other = static_cast <const planner::InsertPlan &>(rhs);
266
262
267
263
auto *table = GetTable ();
268
264
auto *other_table = other.GetTable ();
269
265
PELOTON_ASSERT (table && other_table);
270
- if (*table != *other_table)
271
- return false ;
266
+ if (*table != *other_table) return false ;
272
267
273
268
if (GetChildren ().size () == 0 ) {
274
- if (other.GetChildren ().size () != 0 )
275
- return false ;
269
+ if (other.GetChildren ().size () != 0 ) return false ;
276
270
277
- if (GetBulkInsertCount () != other.GetBulkInsertCount ())
278
- return false ;
271
+ if (GetBulkInsertCount () != other.GetBulkInsertCount ()) return false ;
279
272
}
280
273
281
274
return AbstractPlan::operator ==(rhs);
@@ -291,8 +284,9 @@ void InsertPlan::VisitParameters(
291
284
for (uint32_t i = 0 ; i < values_.size (); i++) {
292
285
auto value = values_[i];
293
286
auto column_id = i % columns_num;
294
- map.Insert (expression::Parameter::CreateConstParameter (value.GetTypeId (),
295
- schema->AllowNull (column_id)), nullptr );
287
+ map.Insert (expression::Parameter::CreateConstParameter (
288
+ value.GetTypeId (), schema->AllowNull (column_id)),
289
+ nullptr );
296
290
values.push_back (value);
297
291
}
298
292
} else {
0 commit comments