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

Commit b23a8ad

Browse files
authored
Merge branch 'master' into settings_gh
2 parents 88987ee + 5e64279 commit b23a8ad

File tree

13 files changed

+409
-107
lines changed

13 files changed

+409
-107
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/common/internal_types.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,9 @@ std::string StatementTypeToString(StatementType type) {
471471
case StatementType::VARIABLE_SET: {
472472
return "SET";
473473
}
474+
case StatementType::EXPLAIN: {
475+
return "EXPLAIN";
476+
}
474477
default: {
475478
throw ConversionException(StringUtil::Format(
476479
"No string conversion for StatementType value '%d'",
@@ -572,6 +575,8 @@ std::string QueryTypeToString(QueryType query_type) {
572575
return "EXECUTE";
573576
case QueryType::QUERY_SELECT:
574577
return "SELECT";
578+
case QueryType::QUERY_EXPLAIN:
579+
return "EXPLAIN";
575580
case QueryType::QUERY_OTHER:
576581
default:
577582
return "OTHER";
@@ -630,6 +635,7 @@ QueryType StatementTypeToQueryType(StatementType stmt_type,
630635
{StatementType::DROP, QueryType::QUERY_DROP},
631636
{StatementType::SELECT, QueryType::QUERY_SELECT},
632637
{StatementType::VARIABLE_SET, QueryType::QUERY_SET},
638+
{StatementType::EXPLAIN, QueryType::QUERY_EXPLAIN}
633639
};
634640
QueryType query_type = QueryType::QUERY_OTHER;
635641
std::unordered_map<StatementType, QueryType,

src/include/common/internal_types.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,7 @@ enum class StatementType {
671671
ANALYZE = 15, // analyze type
672672
VARIABLE_SET = 16, // variable set statement type
673673
CREATE_FUNC = 17, // create func statement type
674+
EXPLAIN = 18 // explain statement type
674675
};
675676
std::string StatementTypeToString(StatementType type);
676677
StatementType StringToStatementType(const std::string &str);
@@ -704,7 +705,8 @@ enum class QueryType {
704705
QUERY_INVALID = 20,
705706
QUERY_CREATE_TRIGGER = 21,
706707
QUERY_CREATE_SCHEMA = 22,
707-
QUERY_CREATE_VIEW = 23
708+
QUERY_CREATE_VIEW = 23,
709+
QUERY_EXPLAIN = 24
708710
};
709711
std::string QueryTypeToString(QueryType query_type);
710712
QueryType StringToQueryType(std::string str);
@@ -1416,4 +1418,4 @@ enum class SSLLevel {
14161418
SSL_VERIIFY = 2,
14171419
};
14181420

1419-
} // namespace peloton
1421+
} // namespace peloton

src/include/common/sql_node_visitor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class CreateFunctionStatement;
2121
class InsertStatement;
2222
class DeleteStatement;
2323
class DropStatement;
24+
class ExplainStatement;
2425
class PrepareStatement;
2526
class ExecuteStatement;
2627
class TransactionStatement;
@@ -80,6 +81,7 @@ class SqlNodeVisitor {
8081
virtual void Visit(parser::UpdateStatement *) {}
8182
virtual void Visit(parser::CopyStatement *) {}
8283
virtual void Visit(parser::AnalyzeStatement *){};
84+
virtual void Visit(parser::ExplainStatement *){};
8385

8486
virtual void Visit(expression::ComparisonExpression *expr);
8587
virtual void Visit(expression::AggregateExpression *expr);
@@ -93,8 +95,6 @@ class SqlNodeVisitor {
9395
virtual void Visit(expression::StarExpression *expr);
9496
virtual void Visit(expression::TupleValueExpression *expr);
9597
virtual void Visit(expression::SubqueryExpression *expr);
96-
97-
9898
};
9999

100100
} // namespace peloton

src/include/network/postgres_protocol_handler.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131

3232
namespace peloton {
3333

34+
namespace parser {
35+
class ExplainStatement;
36+
} // namespace parser
37+
3438
namespace network {
3539

3640
typedef std::vector<std::unique_ptr<OutputPacket>> ResponseBuffer;
@@ -161,6 +165,10 @@ class PostgresProtocolHandler : public ProtocolHandler {
161165
/* Execute a Simple query protocol message */
162166
ProcessResult ExecQueryMessage(InputPacket *pkt, const size_t thread_id);
163167

168+
/* Execute a EXPLAIN query message */
169+
ResultType ExecQueryExplain(const std::string &query,
170+
parser::ExplainStatement &explain_stmt);
171+
164172
/* Process the PARSE message of the extended query protocol */
165173
void ExecParseMessage(InputPacket *pkt);
166174

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Peloton
4+
//
5+
// explain_statement.h
6+
//
7+
// Identification: src/include/parser/explain_statement.h
8+
//
9+
// Copyright (c) 2015-2018, Carnegie Mellon University Database Group
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#pragma once
14+
15+
#include "parser/sql_statement.h"
16+
17+
namespace peloton {
18+
namespace parser {
19+
20+
/**
21+
* @class ExplainStatement
22+
* @brief Represents "EXPLAIN <query>"
23+
*/
24+
class ExplainStatement : public SQLStatement {
25+
public:
26+
ExplainStatement() : SQLStatement(StatementType::EXPLAIN) {}
27+
virtual ~ExplainStatement() {}
28+
29+
void Accept(SqlNodeVisitor *v) override { v->Visit(this); }
30+
31+
std::unique_ptr<parser::SQLStatement> real_sql_stmt;
32+
};
33+
34+
} // namespace parser
35+
} // namespace peloton

src/include/parser/parsenodes.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,19 @@ typedef struct SelectStmt {
326326
/* Eventually add fields for CORRESPONDING spec here */
327327
} SelectStmt;
328328

329+
/*
330+
* Explain Statement
331+
*
332+
* The "query" field is initially a raw parse tree, and is converted to a
333+
* Query node during parse analysis. Note that rewriting and planning
334+
* of the query are always postponed until execution.
335+
*/
336+
typedef struct ExplainStmt {
337+
NodeTag type;
338+
Node *query; /* the query (see comments above) */
339+
List *options; /* list of DefElem nodes */
340+
} ExplainStmt;
341+
329342
typedef struct TypeName {
330343
NodeTag type;
331344
List *names; /* qualified name (list of Value strings) */

src/include/parser/postgresparser.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ class PostgresParser {
217217
// transform helper for select statements
218218
static parser::SelectStatement *SelectTransform(SelectStmt *root);
219219

220+
// transform helper for explain statements
221+
static parser::SQLStatement *ExplainTransform(ExplainStmt *root);
222+
220223
// transform helper for delete statements
221224
static parser::SQLStatement *DeleteTransform(DeleteStmt *root);
222225

src/include/parser/statements.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "delete_statement.h"
2222
#include "drop_statement.h"
2323
#include "execute_statement.h"
24+
#include "explain_statement.h"
2425
#include "insert_statement.h"
2526
#include "prepare_statement.h"
2627
#include "select_statement.h"

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)