21
21
namespace peloton {
22
22
namespace planner {
23
23
24
- /* *
25
- * @brief Create an insert plan
26
- *
27
- * @param[in] table Table to insert into
28
- * @param[in] columns Columns to insert into
29
- * @param[in] insert_values Values
30
- */
31
24
InsertPlan::InsertPlan (storage::DataTable *table,
32
25
const std::vector<std::string> *columns,
33
26
const std::vector<std::vector<
@@ -42,16 +35,16 @@ InsertPlan::InsertPlan(storage::DataTable *table,
42
35
bool is_prepared_stmt = false ;
43
36
auto *schema = target_table_->GetSchema ();
44
37
auto schema_col_count = schema->GetColumnCount ();
45
- vtos_ .resize (columns->size ());
38
+ insert_to_schema_ .resize (columns->size ());
46
39
// initialize mapping from schema cols to insert values vector.
47
40
// will be updated later based on insert columns and values
48
- stov_ .resize (schema_col_count);
41
+ schema_to_insert_ .resize (schema_col_count);
49
42
for (uint32_t idx = 0 ; idx < schema_col_count; idx++) {
50
- stov_ [idx].in_insert_cols = false ;
51
- stov_ [idx].set_value = false ;
52
- stov_ [idx].val_idx = 0 ;
43
+ schema_to_insert_ [idx].in_insert_cols = false ;
44
+ schema_to_insert_ [idx].set_value = false ;
45
+ schema_to_insert_ [idx].val_idx = 0 ;
53
46
// remember the column types
54
- stov_ [idx].type = schema->GetType (idx);
47
+ schema_to_insert_ [idx].type = schema->GetType (idx);
55
48
}
56
49
57
50
if (columns->empty ()) {
@@ -68,8 +61,8 @@ InsertPlan::InsertPlan(storage::DataTable *table,
68
61
auto ret_bool = ProcessValueExpr (exp_ptr, column_id);
69
62
// there is no column specification, so we have a
70
63
// direct mapping between schema cols and the value vector
71
- stov_ [column_id].in_insert_cols = true ;
72
- stov_ [column_id].val_idx = column_id;
64
+ schema_to_insert_ [column_id].in_insert_cols = true ;
65
+ schema_to_insert_ [column_id].val_idx = column_id;
73
66
if (ret_bool == true ) {
74
67
is_prepared_stmt = true ;
75
68
}
@@ -87,10 +80,10 @@ InsertPlan::InsertPlan(storage::DataTable *table,
87
80
PL_ASSERT (values.size () <= schema_col_count);
88
81
89
82
for (uint32_t idx = 0 ; idx < schema_col_count; idx++) {
90
- if (stov_ [idx].in_insert_cols ) {
83
+ if (schema_to_insert_ [idx].in_insert_cols ) {
91
84
// this schema column is present in the insert columns spec.
92
85
// get index into values
93
- auto val_idx = stov_ [idx].val_idx ;
86
+ auto val_idx = schema_to_insert_ [idx].val_idx ;
94
87
auto &exp = values[val_idx];
95
88
auto exp_ptr = exp.get ();
96
89
bool ret_bool = ProcessValueExpr (exp_ptr, idx);
@@ -114,13 +107,13 @@ InsertPlan::InsertPlan(storage::DataTable *table,
114
107
// the constant columns. If there are no constants, this is a no-op.
115
108
uint32_t adjust = 0 ;
116
109
for (uint32_t idx=0 ; idx < columns->size (); idx++) {
117
- uint32_t stov_idx = vtos_ [idx];
118
- if (stov_ [stov_idx].set_value ) {
110
+ uint32_t stov_idx = insert_to_schema_ [idx];
111
+ if (schema_to_insert_ [stov_idx].set_value ) {
119
112
// constant, not present in PS values
120
113
adjust++;
121
114
} else {
122
115
// adjust the index
123
- stov_ [stov_idx].val_idx -= adjust;
116
+ schema_to_insert_ [stov_idx].val_idx -= adjust;
124
117
}
125
118
}
126
119
}
@@ -133,15 +126,7 @@ InsertPlan::InsertPlan(storage::DataTable *table,
133
126
ClearParameterValues ();
134
127
}
135
128
}
136
-
137
- /* *
138
- * Process column specification supplied in the insert statement.
139
- * Construct a map from insert columns to schema columns. Once
140
- * we know which columns will receive constant inserts, further
141
- * adjustment of the map will be needed.
142
- *
143
- * @param[in] columns Column specification
144
- */
129
+
145
130
void InsertPlan::ProcessColumnSpec (const std::vector<std::string> *columns) {
146
131
auto *schema = target_table_->GetSchema ();
147
132
auto &table_columns = schema->GetColumns ();
@@ -159,27 +144,17 @@ void InsertPlan::ProcessColumnSpec(const std::vector<std::string> *columns) {
159
144
target_table_->GetName () + " columns" );
160
145
}
161
146
// we have values for this column
162
- stov_ [idx].in_insert_cols = true ;
147
+ schema_to_insert_ [idx].in_insert_cols = true ;
163
148
// remember how to map schema col -> value for col in tuple
164
- stov_ [idx].val_idx = usr_col_id;
149
+ schema_to_insert_ [idx].val_idx = usr_col_id;
165
150
// and the reverse
166
- vtos_ [usr_col_id] = idx;
151
+ insert_to_schema_ [usr_col_id] = idx;
167
152
}
168
153
}
169
154
170
- /* *
171
- * Process a single expression to be inserted.
172
- *
173
- * @param[in] expr insert expression
174
- * @param[in] schema_idx index into schema columns, where the expr
175
- * will be inserted.
176
- * @return true if values imply a prepared statement
177
- * false if all values are constants. This does not rule
178
- * out the insert being a prepared statement.
179
- */
180
155
bool InsertPlan::ProcessValueExpr (expression::AbstractExpression *expr,
181
156
uint32_t schema_idx) {
182
- auto type = stov_ [schema_idx].type ;
157
+ auto type = schema_to_insert_ [schema_idx].type ;
183
158
184
159
if (expr == nullptr ) {
185
160
SetDefaultValue (schema_idx);
@@ -189,8 +164,8 @@ bool InsertPlan::ProcessValueExpr(expression::AbstractExpression *expr,
189
164
dynamic_cast <expression::ConstantValueExpression *>(expr);
190
165
type::Value value = const_expr->GetValue ().CastAs (type);
191
166
192
- stov_ [schema_idx].set_value = true ;
193
- stov_ [schema_idx].value = value;
167
+ schema_to_insert_ [schema_idx].set_value = true ;
168
+ schema_to_insert_ [schema_idx].value = value;
194
169
// save it, in case this is not a PS
195
170
values_.push_back (value);
196
171
@@ -202,15 +177,10 @@ bool InsertPlan::ProcessValueExpr(expression::AbstractExpression *expr,
202
177
return false ;
203
178
}
204
179
205
- /* *
206
- * Set default value into a schema column
207
- *
208
- * @param[in] idx schema column index
209
- */
210
180
void InsertPlan::SetDefaultValue (uint32_t idx) {
211
181
auto *schema = target_table_->GetSchema ();
212
182
type::Value *v = schema->GetDefaultValue (idx);
213
- type::TypeId type = stov_ [idx].type ;
183
+ type::TypeId type = schema_to_insert_ [idx].type ;
214
184
215
185
if (v == nullptr )
216
186
// null default value
@@ -220,15 +190,6 @@ void InsertPlan::SetDefaultValue(uint32_t idx) {
220
190
values_.push_back (*v);
221
191
}
222
192
223
- /* *
224
- * Lookup a column name in the schema columns
225
- *
226
- * @param[in] col_name column name, from insert statement
227
- * @param[in] tbl_columns table columns from the schema
228
- * @param[out] index index into schema columns, only if found
229
- *
230
- * @return true if column was found, false otherwise
231
- */
232
193
bool InsertPlan::FindSchemaColIndex (std::string col_name,
233
194
const std::vector<catalog::Column> &tbl_columns,
234
195
uint32_t &index) {
@@ -247,25 +208,19 @@ type::AbstractPool *InsertPlan::GetPlanPool() {
247
208
return pool_.get ();
248
209
}
249
210
250
- /* *
251
- * @brief Save values for jdbc prepared statement insert.
252
- * Only a single tuple is presented to this function.
253
- *
254
- * @param[in] values Values for insertion
255
- */
256
211
void InsertPlan::SetParameterValues (std::vector<type::Value> *values) {
257
212
LOG_TRACE (" Set Parameter Values in Insert" );
258
213
auto *schema = target_table_->GetSchema ();
259
214
auto schema_col_count = schema->GetColumnCount ();
260
215
261
216
PL_ASSERT (values->size () <= schema_col_count);
262
217
for (uint32_t idx = 0 ; idx < schema_col_count; idx++) {
263
- if (stov_ [idx].set_value ) {
264
- values_.push_back (stov_ [idx].value );
265
- } else if (stov_ [idx].in_insert_cols ) {
218
+ if (schema_to_insert_ [idx].set_value ) {
219
+ values_.push_back (schema_to_insert_ [idx].value );
220
+ } else if (schema_to_insert_ [idx].in_insert_cols ) {
266
221
// get index into values
267
- auto val_idx = stov_ [idx].val_idx ;
268
- auto type = stov_ [idx].type ;
222
+ auto val_idx = schema_to_insert_ [idx].val_idx ;
223
+ auto type = schema_to_insert_ [idx].type ;
269
224
type::Value value = values->at (val_idx).CastAs (type);
270
225
values_.push_back (value);
271
226
} else {
0 commit comments