12
12
13
13
#pragma once
14
14
15
- #include " expression/constant_value_expression.h"
16
- #include " storage/data_table.h"
17
15
#include " planner/abstract_plan.h"
18
16
#include " planner/abstract_scan_plan.h"
19
17
#include " planner/project_info.h"
@@ -202,15 +200,7 @@ class InsertPlan : public AbstractPlan {
202
200
*/
203
201
bool FindSchemaColIndex (std::string col_name,
204
202
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);
214
204
215
205
/* *
216
206
* Process column specification supplied in the insert statement.
@@ -220,30 +210,7 @@ class InsertPlan : public AbstractPlan {
220
210
*
221
211
* @param[in] columns Column specification
222
212
*/
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);
247
214
248
215
/* *
249
216
* Process a single expression to be inserted.
@@ -256,48 +223,15 @@ class InsertPlan : public AbstractPlan {
256
223
* out the insert being a prepared statement.
257
224
*/
258
225
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);
283
227
284
228
/* *
285
229
* Set default value into a schema column
286
230
*
287
231
* @param[in] idx schema column index
288
232
*/
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
+
301
235
};
302
236
} // namespace planner
303
237
} // namespace peloton
0 commit comments