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

Commit 082ec5b

Browse files
author
GustavoAngulo
committed
merged to upstream
2 parents 76dcf62 + d6510a1 commit 082ec5b

File tree

15 files changed

+124
-52
lines changed

15 files changed

+124
-52
lines changed

script/installation/packages.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
## * OSX
1818
## =================================================================
1919

20+
set -o errexit
2021

2122
# Determine OS platform
2223
UNAME=$(uname | tr "[:upper:]" "[:lower:]")
@@ -104,14 +105,12 @@ if [ "$DISTRO" = "UBUNTU" ]; then
104105
echo -e "\n# Added by Peloton 'packages.sh' script on $(date)\ndeb $LLVM_PKG_URL $LLVM_PKG_TARGET" | sudo tee -a /etc/apt/sources.list > /dev/null
105106
fi
106107
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 15CF4D18AF4F7421
107-
sudo apt-get update -qq
108108
CMAKE_NAME="cmake3"
109-
FORCE_Y="--force-yes"
110109
else
111110
CMAKE_NAME="cmake"
112-
FORCE_Y=""
113111
fi
114112

113+
sudo apt-get update
115114
FORCE_Y=""
116115
PKG_CMAKE="cmake"
117116
PKG_LLVM="llvm-3.7"
@@ -134,7 +133,7 @@ if [ "$DISTRO" = "UBUNTU" ]; then
134133
fi
135134
TFCApiFile="libtensorflow-${TF_TYPE}-linux-x86_64-${TF_VERSION}.tar.gz"
136135
LinkerConfigCmd="sudo ldconfig"
137-
sudo apt-get -qq $FORCE_Y --ignore-missing -y install \
136+
sudo apt-get -q $FORCE_Y --ignore-missing -y install \
138137
$PKG_CMAKE \
139138
$PKG_LLVM \
140139
$PKG_CLANG \
@@ -171,7 +170,7 @@ if [ "$DISTRO" = "UBUNTU" ]; then
171170
## DEBIAN
172171
## ------------------------------------------------
173172
elif [ "$DISTRO" = "DEBIAN OS" ]; then
174-
sudo apt-get -qq --ignore-missing -y install \
173+
sudo apt-get -q --ignore-missing -y install \
175174
git \
176175
g++ \
177176
clang \
@@ -312,6 +311,7 @@ elif [[ "$DISTRO" == *"REDHAT"* ]] && [[ "${DISTRO_VER%.*}" == "7" ]]; then
312311
## DARWIN (OSX)
313312
## ------------------------------------------------
314313
elif [ "$DISTRO" = "DARWIN" ]; then
314+
set +o errexit
315315
if test ! $(which brew); then
316316
echo "Installing homebrew..."
317317
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

src/binder/binder_context.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@ void BinderContext::AddRegularTable(const std::string db_name,
3737
const std::string table_alias,
3838
concurrency::TransactionContext *txn) {
3939
// using catalog object to retrieve meta-data
40-
// PL_ASSERT(txn->catalog_cache.GetDatabaseObject(db_name) != nullptr);
4140
auto table_object =
4241
catalog::Catalog::GetInstance()->GetTableObject(db_name, table_name, txn);
43-
// txn->catalog_cache.GetDatabaseObject(db_name)->GetTableObject(table_name, true);
4442

4543
if (regular_table_alias_map_.find(table_alias) !=
4644
regular_table_alias_map_.end() ||

src/include/optimizer/cost_calculator.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class Memo;
2121
// Derive cost for a physical group expressionh
2222
class CostCalculator : public OperatorVisitor {
2323
public:
24-
double CalculateCost(GroupExpression *gexpr, Memo *memo);
24+
double CalculateCost(GroupExpression *gexpr, Memo *memo,
25+
concurrency::TransactionContext *txn);
2526

2627
void Visit(const DummyScan *) override;
2728
void Visit(const PhysicalSeqScan *) override;
@@ -53,6 +54,7 @@ class CostCalculator : public OperatorVisitor {
5354

5455
GroupExpression *gexpr_;
5556
Memo *memo_;
57+
concurrency::TransactionContext *txn_;
5658
double output_cost_ = 0;
5759
};
5860

src/include/optimizer/optimizer_metadata.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class OptimizerMetadata {
2929
Memo memo;
3030
RuleSet rule_set;
3131
OptimizerTaskPool *task_pool;
32-
catalog::CatalogCache* catalog_cache;
32+
concurrency::TransactionContext* txn;
3333

3434
void SetTaskPool(OptimizerTaskPool *task_pool) {
3535
this->task_pool = task_pool;

src/include/optimizer/stats/stats_storage.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,21 @@ class StatsStorage {
6262
oid_t table_id,
6363
oid_t column_id);
6464

65-
std::shared_ptr<TableStats> GetTableStats(oid_t database_id, oid_t table_id);
65+
std::shared_ptr<TableStats> GetTableStats(
66+
oid_t database_id, oid_t table_id, concurrency::TransactionContext *txn);
6667

67-
std::shared_ptr<TableStats> GetTableStats(oid_t database_id, oid_t table_id,
68-
std::vector<oid_t> column_ids);
68+
std::shared_ptr<TableStats> GetTableStats(
69+
oid_t database_id, oid_t table_id, std::vector<oid_t> column_ids,
70+
concurrency::TransactionContext *txn);
6971

7072
/* Functions for triggerring stats collection */
7173

72-
ResultType AnalyzeStatsForAllTables(concurrency::TransactionContext *txn = nullptr);
74+
ResultType AnalyzeStatsForAllTables(
75+
concurrency::TransactionContext *txn = nullptr);
7376

74-
ResultType AnalyzeStatsForTable(storage::DataTable *table,
75-
concurrency::TransactionContext *txn = nullptr);
77+
ResultType AnalyzeStatsForTable(
78+
storage::DataTable *table,
79+
concurrency::TransactionContext *txn = nullptr);
7680

7781
ResultType AnalayzeStatsForColumns(storage::DataTable *table,
7882
std::vector<std::string> column_names);

src/include/optimizer/stats_calculator.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class TableStats;
2727
class StatsCalculator : public OperatorVisitor {
2828
public:
2929
void CalculateStats(GroupExpression *gexpr, ExprSet required_cols,
30-
Memo *memo);
30+
Memo *memo, concurrency::TransactionContext* txn);
3131

3232
void Visit(const LogicalGet *) override;
3333
void Visit(const LogicalQueryDerivedGet *) override;
@@ -75,6 +75,7 @@ class StatsCalculator : public OperatorVisitor {
7575
GroupExpression *gexpr_;
7676
ExprSet required_cols_;
7777
Memo *memo_;
78+
concurrency::TransactionContext* txn_;
7879
};
7980

8081
} // namespace optimizer

src/include/type/value_factory.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,12 @@ class ValueFactory {
214214
std::string str = value.ToString();
215215
int64_t bigint = 0;
216216
try {
217-
bigint = std::stoll(str);
217+
bigint = stoll(str);
218218
} catch (std::out_of_range &e) {
219219
throw Exception(ExceptionType::OUT_OF_RANGE,
220220
"Numeric value out of range.");
221+
} catch(std::invalid_argument &e) {
222+
throw Exception("Invalid input syntax for bigint: \'" + str + "\'");
221223
}
222224
if (bigint > PELOTON_INT64_MAX || bigint < PELOTON_INT64_MIN)
223225
throw Exception(ExceptionType::OUT_OF_RANGE,
@@ -262,11 +264,14 @@ class ValueFactory {
262264
std::string str = value.ToString();
263265
int32_t integer = 0;
264266
try {
265-
integer = std::stoi(str);
267+
integer = stoi(str);
266268
} catch (std::out_of_range &e) {
267269
throw Exception(ExceptionType::OUT_OF_RANGE,
268270
"Numeric value out of range.");
271+
} catch (std::invalid_argument &e) {
272+
throw Exception("Invalid input syntax for integer: \'" + str + "\'");
269273
}
274+
270275
if (integer > PELOTON_INT32_MAX || integer < PELOTON_INT32_MIN)
271276
throw Exception(ExceptionType::OUT_OF_RANGE,
272277
"Numeric value out of range.");
@@ -317,10 +322,12 @@ class ValueFactory {
317322
std::string str = value.ToString();
318323
int16_t smallint = 0;
319324
try {
320-
smallint = std::stoi(str);
325+
smallint = stoi(str);
321326
} catch (std::out_of_range &e) {
322327
throw Exception(ExceptionType::OUT_OF_RANGE,
323328
"Numeric value out of range.");
329+
} catch(std::invalid_argument &e) {
330+
throw Exception("Invalid input syntax for smallint: \'" + str + "\'");
324331
}
325332
if (smallint < PELOTON_INT16_MIN)
326333
throw Exception(ExceptionType::OUT_OF_RANGE,
@@ -375,10 +382,12 @@ class ValueFactory {
375382
std::string str = value.ToString();
376383
int8_t tinyint = 0;
377384
try {
378-
tinyint = std::stoi(str);
385+
tinyint = stoi(str);
379386
} catch (std::out_of_range &e) {
380387
throw Exception(ExceptionType::OUT_OF_RANGE,
381388
"Numeric value out of range.");
389+
} catch(std::invalid_argument &e) {
390+
throw Exception("Invalid input syntax for tinyint: \'" + str + "\'");
382391
}
383392
if (tinyint < PELOTON_INT8_MIN)
384393
throw Exception(ExceptionType::OUT_OF_RANGE,
@@ -413,10 +422,12 @@ class ValueFactory {
413422
std::string str = value.ToString();
414423
double res = 0;
415424
try {
416-
res = std::stod(str);
425+
res = stod(str);
417426
} catch (std::out_of_range &e) {
418427
throw Exception(ExceptionType::OUT_OF_RANGE,
419428
"Numeric value out of range.");
429+
} catch(std::invalid_argument &e) {
430+
throw Exception("Invalid input syntax for decimal: \'" + str + "\'");
420431
}
421432
if (res > PELOTON_DECIMAL_MAX || res < PELOTON_DECIMAL_MIN)
422433
throw Exception(ExceptionType::OUT_OF_RANGE,

src/optimizer/cost_calculator.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
namespace peloton {
2525
namespace optimizer {
2626

27-
double CostCalculator::CalculateCost(GroupExpression *gexpr, Memo *memo) {
27+
double CostCalculator::CalculateCost(GroupExpression *gexpr, Memo *memo,
28+
concurrency::TransactionContext *txn) {
2829
gexpr_ = gexpr;
2930
memo_ = memo;
31+
txn_ = txn;
3032
gexpr_->Op().Accept(this);
3133
return output_cost_;
3234
}
@@ -36,8 +38,8 @@ void CostCalculator::Visit(UNUSED_ATTRIBUTE const DummyScan *op) {
3638
}
3739
void CostCalculator::Visit(const PhysicalSeqScan *op) {
3840
auto table_stats = std::dynamic_pointer_cast<TableStats>(
39-
StatsStorage::GetInstance()->GetTableStats(op->table_->GetDatabaseOid(),
40-
op->table_->GetTableOid()));
41+
StatsStorage::GetInstance()->GetTableStats(
42+
op->table_->GetDatabaseOid(), op->table_->GetTableOid(), txn_));
4143
if (table_stats->GetColumnCount() == 0) {
4244
output_cost_ = 1.f;
4345
return;
@@ -46,8 +48,8 @@ void CostCalculator::Visit(const PhysicalSeqScan *op) {
4648
}
4749
void CostCalculator::Visit(UNUSED_ATTRIBUTE const PhysicalIndexScan *op) {
4850
auto table_stats = std::dynamic_pointer_cast<TableStats>(
49-
StatsStorage::GetInstance()->GetTableStats(op->table_->GetDatabaseOid(),
50-
op->table_->GetTableOid()));
51+
StatsStorage::GetInstance()->GetTableStats(
52+
op->table_->GetDatabaseOid(), op->table_->GetTableOid(), txn_));
5153
if (table_stats->GetColumnCount() == 0 || table_stats->num_rows == 0) {
5254
output_cost_ = 0.f;
5355
return;

src/optimizer/optimizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,14 @@ shared_ptr<planner::AbstractPlan> Optimizer::BuildPelotonPlanTree(
110110
make_shared<binder::BindNodeVisitor>(txn, default_database_name);
111111
bind_node_visitor->BindNameToNode(parse_tree);
112112

113-
metadata_.catalog_cache = &txn->catalog_cache;
114113
// Handle ddl statement
115114
bool is_ddl_stmt;
116115
auto ddl_plan = HandleDDLStatement(parse_tree, is_ddl_stmt, txn);
117116
if (is_ddl_stmt) {
118117
return move(ddl_plan);
119118
}
120119

120+
metadata_.txn = txn;
121121
// Generate initial operator tree from query tree
122122
shared_ptr<GroupExpression> gexpr = InsertQueryTree(parse_tree, txn);
123123
GroupID root_id = gexpr->GetGroupID();

src/optimizer/optimizer_task.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ void DeriveStats::execute() {
249249
}
250250

251251
StatsCalculator calculator;
252-
calculator.CalculateStats(gexpr_, required_cols_, &context_->metadata->memo);
252+
calculator.CalculateStats(gexpr_, required_cols_, &context_->metadata->memo,
253+
context_->metadata->txn);
253254
gexpr_->SetDerivedStats();
254255
}
255256
//===--------------------------------------------------------------------===//
@@ -291,8 +292,8 @@ void OptimizeInputs::execute() {
291292
// 1. Collect stats needed and cache them in the group
292293
// 2. Calculate cost based on children's stats
293294
CostCalculator cost_calculator;
294-
cur_total_cost_ +=
295-
cost_calculator.CalculateCost(group_expr_, &context_->metadata->memo);
295+
cur_total_cost_ += cost_calculator.CalculateCost(
296+
group_expr_, &context_->metadata->memo, context_->metadata->txn);
296297
}
297298

298299
for (; cur_child_idx_ < (int)group_expr_->GetChildrenGroupsSize();
@@ -367,7 +368,8 @@ void OptimizeInputs::execute() {
367368
std::make_shared<PropertySet>(extended_output_properties);
368369
CostCalculator cost_calculator;
369370
cur_total_cost_ += cost_calculator.CalculateCost(
370-
memo_enforced_expr, &context_->metadata->memo);
371+
memo_enforced_expr, &context_->metadata->memo,
372+
context_->metadata->txn);
371373

372374
// Update hash tables for group and group expression
373375
memo_enforced_expr->SetLocalHashTable(

0 commit comments

Comments
 (0)