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

Commit 5e64279

Browse files
authored
Merge pull request #1237 from pervazea/insert
Insert plan changes
2 parents 39fa518 + 71b3d2a commit 5e64279

File tree

3 files changed

+294
-102
lines changed

3 files changed

+294
-102
lines changed

script/testing/jdbc/README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
## Simple JDBC test for Peloton
22

3-
The java program here provides simple JDBC operation tests for Peloton database. To run the test, simply type:
3+
The java program here provides simple JDBC operation tests for Peloton
4+
database.
45

5-
test_jdbc.sh <type>
6+
To run the test:
7+
1. Start peloton. Typically, locally, so hostname would be localhost
8+
and if default port would be 15721
69

7-
Where 'type' is either 'basic', 'stats', or 'copy'
10+
2. Compile and run the test:
11+
test_jdbc.sh <type> <hostname> <port>
12+
13+
e.g. test_jdbc.sh PelotonBasicTest localhost 15721
14+
15+
Where 'type' is one of:
16+
PelotonBasicTest
17+
PelotonErrorTest
18+
PelotonTypeTest
19+
StocklevelTest
20+
SSLTest
821

922
The program performs the following tests:
1023

src/include/planner/insert_plan.h

Lines changed: 99 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
// Identification: src/include/planner/insert_plan.h
88
//
9-
// Copyright (c) 2015-17, Carnegie Mellon University Database Group
9+
// Copyright (c) 2015-2018, Carnegie Mellon University Database Group
1010
//
1111
//===----------------------------------------------------------------------===//
1212

@@ -29,11 +29,12 @@ class InsertStatement;
2929
}
3030

3131
namespace planner {
32+
3233
class InsertPlan : public AbstractPlan {
3334
public:
3435
// Construct when SELECT comes in with it
3536
InsertPlan(storage::DataTable *table, oid_t bulk_insert_count = 1)
36-
: target_table_(table), bulk_insert_count_(bulk_insert_count) {
37+
: target_table_(table), bulk_insert_count_(bulk_insert_count) {
3738
LOG_TRACE("Creating an Insert Plan with SELECT as a child");
3839
}
3940

@@ -42,35 +43,50 @@ class InsertPlan : public AbstractPlan {
4243
InsertPlan(storage::DataTable *table,
4344
std::unique_ptr<const planner::ProjectInfo> &&project_info,
4445
oid_t bulk_insert_count = 1)
45-
: target_table_(table), project_info_(std::move(project_info)),
46-
bulk_insert_count_(bulk_insert_count) {
46+
: target_table_(table),
47+
project_info_(std::move(project_info)),
48+
bulk_insert_count_(bulk_insert_count) {
4749
LOG_TRACE("Creating an Insert Plan with a projection");
4850
}
4951

5052
// Construct with a tuple
5153
// This can only be handled by the interpreted exeuctor
52-
InsertPlan(storage::DataTable *table,
53-
std::unique_ptr<storage::Tuple> &&tuple,
54+
InsertPlan(storage::DataTable *table, std::unique_ptr<storage::Tuple> &&tuple,
5455
oid_t bulk_insert_count = 1)
55-
: target_table_(table), bulk_insert_count_(bulk_insert_count) {
56+
: target_table_(table), bulk_insert_count_(bulk_insert_count) {
5657
LOG_TRACE("Creating an Insert Plan for one tuple");
5758
tuples_.push_back(std::move(tuple));
5859
}
5960

60-
// Construct with specific values
61+
/**
62+
* @brief Create an insert plan with specific values
63+
*
64+
* @param[in] table Table to insert into
65+
* @param[in] columns Columns to insert into
66+
* @param[in] insert_values Values
67+
*/
6168
InsertPlan(storage::DataTable *table, const std::vector<std::string> *columns,
62-
const std::vector<std::vector<std::unique_ptr<
63-
expression::AbstractExpression>>> *insert_values);
69+
const std::vector<
70+
std::vector<std::unique_ptr<expression::AbstractExpression>>> *
71+
insert_values);
6472

6573
// Get a varlen pool - will construct the pool only if needed
6674
type::AbstractPool *GetPlanPool();
6775

68-
PlanNodeType GetPlanNodeType() const override { return PlanNodeType::INSERT; }
76+
PlanNodeType GetPlanNodeType() const override {
77+
return PlanNodeType::INSERT;
78+
};
6979

80+
/**
81+
* @brief Save values for jdbc prepared statement insert.
82+
* Only a single tuple is presented to this function.
83+
*
84+
* @param[in] values Values for insertion
85+
*/
7086
void SetParameterValues(std::vector<type::Value> *values) override;
7187

72-
/*
73-
* Clear the parameter values of the current insert. The plan may be
88+
/*
89+
* Clear the parameter values of the current insert. The plan may be
7490
* cached in the statement / plan cache and may be reused.
7591
*/
7692
void ClearParameterValues() override { values_.clear(); }
@@ -115,17 +131,86 @@ class InsertPlan : public AbstractPlan {
115131
return !(*this == rhs);
116132
}
117133

118-
virtual void VisitParameters(codegen::QueryParametersMap &map,
134+
virtual void VisitParameters(
135+
codegen::QueryParametersMap &map,
119136
std::vector<peloton::type::Value> &values,
120137
const std::vector<peloton::type::Value> &values_from_user) override;
121138

122139
private:
140+
/**
141+
* Lookup a column name in the schema columns
142+
*
143+
* @param[in] col_name column name, from insert statement
144+
* @param[in] tbl_columns table columns from the schema
145+
* @param[out] index index into schema columns, only if found
146+
*
147+
* @return true if column was found, false otherwise
148+
*/
149+
bool FindSchemaColIndex(std::string col_name,
150+
const std::vector<catalog::Column> &tbl_columns,
151+
uint32_t &index);
152+
153+
/**
154+
* Process column specification supplied in the insert statement.
155+
* Construct a map from insert columns to schema columns. Once
156+
* we know which columns will receive constant inserts, further
157+
* adjustment of the map will be needed.
158+
*
159+
* @param[in] columns Column specification
160+
*/
161+
void ProcessColumnSpec(const std::vector<std::string> *columns);
162+
163+
/**
164+
* Process a single expression to be inserted.
165+
*
166+
* @param[in] expr insert expression
167+
* @param[in] schema_idx index into schema columns, where the expr
168+
* will be inserted.
169+
* @return true if values imply a prepared statement
170+
* false if all values are constants. This does not rule
171+
* out the insert being a prepared statement.
172+
*/
173+
bool ProcessValueExpr(expression::AbstractExpression *expr,
174+
uint32_t schema_idx);
175+
176+
/**
177+
* Set default value into a schema column
178+
*
179+
* @param[in] idx schema column index
180+
*/
181+
void SetDefaultValue(uint32_t idx);
182+
183+
private:
184+
// mapping from schema columns to insert columns
185+
struct SchemaColsToInsertCols {
186+
// this schema column is present in the insert columns
187+
bool in_insert_cols;
188+
189+
// For a PS, insert saved value (from constant in insert values list), no
190+
// param value.
191+
bool set_value;
192+
193+
// index of this column in insert columns values
194+
int val_idx;
195+
196+
// schema column type
197+
type::TypeId type;
198+
199+
// set_value refers to this saved value
200+
type::Value value;
201+
};
202+
123203
// Target table
124204
storage::DataTable *target_table_ = nullptr;
125205

126206
// Values
127207
std::vector<type::Value> values_;
128208

209+
// mapping from schema columns to vector of insert columns
210+
std::vector<SchemaColsToInsertCols> schema_to_insert_;
211+
// mapping from insert columns to schema columns
212+
std::vector<uint32_t> insert_to_schema_;
213+
129214
// Projection Info
130215
std::unique_ptr<const planner::ProjectInfo> project_info_;
131216

@@ -148,9 +233,7 @@ class InsertPlan : public AbstractPlan {
148233
// Pool for variable length types
149234
std::unique_ptr<type::AbstractPool> pool_;
150235

151-
private:
152236
DISALLOW_COPY_AND_MOVE(InsertPlan);
153237
};
154-
155238
} // namespace planner
156239
} // namespace peloton

0 commit comments

Comments
 (0)