Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Projection #161

Open
wants to merge 30 commits into
base: for_auto_test
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3afe25c
Update README.md
fzhedu Sep 8, 2016
4a9d6ab
Update README.md
fzhedu Sep 14, 2016
988423b
Update README.md
fzhedu Sep 14, 2016
bd45545
Update README.md
fzhedu Sep 14, 2016
cabd050
commit
neko940709 Sep 19, 2016
ec267c7
commit
neko940709 Sep 19, 2016
54b4adb
commit
neko940709 Sep 19, 2016
c12e930
Merge pull request #148 from neko940709/master
fzhedu Sep 20, 2016
a2018ba
commit
neko940709 Sep 20, 2016
15575b8
commit
neko940709 Sep 21, 2016
e27807e
commit
neko940709 Sep 21, 2016
9ff773c
commit
neko940709 Sep 21, 2016
d7a4404
Merge pull request #150 from neko940709/master
Jackson1992 Sep 21, 2016
a4b2530
Update README.md
wangli1426 Sep 22, 2016
d786451
Update README.md
wangli1426 Sep 22, 2016
2bf800c
Update README.md
fzhedu Oct 3, 2016
caafa65
Update README.md
fzhedu Oct 3, 2016
39fe7e9
Update README.md
fzhedu Oct 3, 2016
5d7f067
Update README.md
fzhedu Oct 3, 2016
4e82d54
Update README.md
fzhedu Oct 3, 2016
4eab654
projection step1 finish
zhejiangxiaomai Feb 28, 2017
1786ce7
add prune column except for out join
fzhedu Mar 1, 2017
2e000fb
finish projection
zhejiangxiaomai Mar 2, 2017
8fb5c9b
Merge HEAD, branches 'for_auto_test' and 'for_auto_test' of github.co…
zhejiangxiaomai Mar 2, 2017
368dbf5
finish outer join
zhejiangxiaomai Mar 9, 2017
1108aae
finish fix logical scan
zhejiangxiaomai Mar 9, 2017
51bbb09
logical scan fix and gtest finish
zhejiangxiaomai Mar 14, 2017
6402bc7
finish projection scan ready to merge
zhejiangxiaomai Mar 17, 2017
d5edd7e
Merge branch 'projection_fzh' into projection
zhejiangxiaomai Mar 17, 2017
5e8fdba
fix project memory leak
zhejiangxiaomai Mar 24, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
finish projection scan ready to merge
  • Loading branch information
zhejiangxiaomai committed Mar 17, 2017
commit 6402bc74abc11cb2d63689481ba2a491aaca2aae
119 changes: 44 additions & 75 deletions logical_operator/logical_scan.cpp
Original file line number Diff line number Diff line change
@@ -53,19 +53,6 @@ LogicalScan::LogicalScan(std::vector<Attribute> attribute_list)
scan_attribute_list_(attribute_list),
target_projection_(NULL),
plan_context_(NULL) {}
LogicalScan::LogicalScan(set<string> columns,
string table_name,
string table_alias,
bool is_all)
:LogicalOperator(kLogicalScan),
columns_(columns),
table_name_(table_name),
table_alias_(table_alias),
is_all_(is_all),
target_projection_(NULL),
plan_context_(NULL) {
scan_attribute_list_ = {};
}

LogicalScan::LogicalScan(const TableID& table_id)
: LogicalOperator(kLogicalScan),
@@ -85,15 +72,19 @@ LogicalScan::LogicalScan(ProjectionDescriptor* projection,
scan_attribute_list_ = projection->getAttributeList();
target_projection_ = projection;
}
LogicalScan::LogicalScan(ProjectionDescriptor* const projection,
string table_alias, const float sample_rate)
: LogicalOperator(kLogicalScan),
LogicalScan::LogicalScan(string table_alias, set<string> columns,
string table_name, bool is_all,
const float sample_rate)
: columns_(columns),
table_name_(table_name),
LogicalOperator(kLogicalScan),
table_alias_(table_alias),
is_all_(is_all),
sample_rate_(sample_rate),
plan_context_(NULL) {
scan_attribute_list_ = projection->getAttributeList();
ChangeAliasAttr();
target_projection_ = projection;
// scan_attribute_list_ = projection->getAttributeList();
// ChangeAliasAttr();
// target_projection_ = projection;
}
LogicalScan::LogicalScan(
const TableID& table_id,
@@ -139,8 +130,8 @@ void LogicalScan::ChangeAliasAttr() {
PlanContext LogicalScan::GetPlanContext() {
lock_->acquire();
if (NULL != plan_context_) {
lock_->release();
return *plan_context_;
delete plan_context_;
plan_context_ = NULL;
}
plan_context_ = new PlanContext();
TableDescriptor* table = Catalog::getInstance()->getTable(table_name_);
@@ -151,77 +142,55 @@ PlanContext LogicalScan::GetPlanContext() {
// if is all, select tableA.* from tableA, give largest projection;
target_projection_off = get_Max_projection(table);
} else {
for (ProjectionOffset projection_off = 0;
projection_off < table->getNumberOfProjection(); projection_off++) {
ProjectionDescriptor* projection = table->getProjectoin(projection_off);
bool fail = false;
for (set<string>::const_iterator it = columns_.begin();
it != columns_.end(); it++) {
if (!projection->isExist1(table_name_+"."+*it)) {
/*the attribute *it is not in the projection*/
fail = true;
break;
for (ProjectionOffset projection_off = 0;
projection_off < table->getNumberOfProjection();
projection_off++) {
ProjectionDescriptor* projection =
table->getProjectoin(projection_off);
bool fail = false;
for (set<string>::const_iterator it = columns_.begin();
it != columns_.end(); it++) {
if (!projection->isExist1(table_name_+"."+*it)) {
/*the attribute *it is not in the projection*/
fail = true;
break;
}
}
if (fail == true) {
continue;
}
unsigned int projection_cost = projection->getProjectionCost();
if ( projection_off == 0 ) {
min_projection_cost = projection_cost;
target_projection_off = 0;
}
if (min_projection_cost > projection_cost) {
target_projection_off = projection_off;
min_projection_cost = projection_cost;
}
}
if (target_projection_off != -1) {
target_projection_ = table->getProjectoin(target_projection_off);
}
}
if (fail == true) {
continue;
}
unsigned int projection_cost = projection->getProjectionCost();
if ( projection_off == 0 ) {
min_projection_cost = projection_cost;
target_projection_off = 0;
}
// get the projection with minimum cost
if (min_projection_cost > projection_cost) {
target_projection_off = projection_off;
min_projection_cost = projection_cost;
}
}
if (target_projection_off == -1) {
// fail to find a projection that contains all the scan attribute
LOG(ERROR) << "The current implementation does not support the scanning "
"that involves more than one projection." << std::endl;
assert(false);
}
target_projection_ = table->getProjectoin(target_projection_off);
}
} else {
// if is all, select * from tableA, give largest projection;
target_projection_off = get_Max_projection(table);
target_projection_ = table->getProjectoin(target_projection_off);
}
if (target_projection_off == -1) {
// fail to find a projection that contains all the scan attribute
LOG(ERROR) << "fail to find a projection that contains "
<< "all the scan attribute" <<std::endl;
assert(false);
}
target_projection_ = table->getProjectoin(target_projection_off);
if (!target_projection_->AllPartitionBound()) {
Catalog::getInstance()->getBindingModele()->BindingEntireProjection(
target_projection_->getPartitioner(), DESIRIABLE_STORAGE_LEVEL);
}

for (set<string>::const_iterator it = columns_.begin();
it != columns_.end(); it++ ) {
cout << (*it) << endl;
}

/**
* @brief build the PlanContext
*/
if (is_all_ || columns_.find("*") != columns_.end()) {
plan_context_->attribute_list_ = table->getAttributes();
} else {
plan_context_->attribute_list_ = target_projection_->getAttributeList();
}

plan_context_->attribute_list_ = target_projection_->getAttributeList();
for (auto &it : plan_context_->attribute_list_) {
it.attrName = table_alias_ + it.attrName.substr(it.attrName.find('.'));
}
Partitioner* par = target_projection_->getPartitioner();
plan_context_->plan_partitioner_ = PlanPartitioner(*par);
plan_context_->plan_partitioner_.UpdateTableNameOfPartitionKey(table_alias_);
plan_context_->commu_cost_ = 0;

lock_->release();
return *plan_context_;
}
6 changes: 2 additions & 4 deletions logical_operator/logical_scan.h
Original file line number Diff line number Diff line change
@@ -53,12 +53,10 @@ namespace logical_operator {
class LogicalScan : public LogicalOperator {
public:
LogicalScan(std::vector<Attribute> attribute_list);
LogicalScan(set<string> columns, string table_name,
string table_alias, bool is_all);
LogicalScan(const TableID&);
LogicalScan(ProjectionDescriptor* projection, const float sample_rate_ = 1);
LogicalScan(ProjectionDescriptor* const projection, string table_alias,
const float sample_rate_ = 1);
LogicalScan(string table_alias, set<string> columns, string table_name,
bool is_all, const float sample_rate_ = 1);

LogicalScan(const TableID&,
const std::vector<unsigned>& selected_attribute_index_list);
4 changes: 2 additions & 2 deletions sql_parser/ast_node/ast_node.cpp
Original file line number Diff line number Diff line change
@@ -57,7 +57,7 @@ void AstNode::Print(int level) const {
<< "This is an AST_NODE!" << endl;
}

RetCode AstNode::SetScanAttrList(const SemanticContext &sem_cnxt) {
RetCode AstNode::SetScanAttrList(SemanticContext* sem_cnxt) {
return rSuccess;
}
RetCode AstNode::SemanticAnalisys(SemanticContext* sem_cnxt) {
@@ -193,7 +193,7 @@ void AstStmtList::Print(int level) const {
}
}

RetCode AstStmtList::SetScanAttrList(const SemanticContext &sem_cnxt) {
RetCode AstStmtList::SetScanAttrList(SemanticContext *sem_cnxt) {
if (stmt_ != NULL) {
stmt_->SetScanAttrList(sem_cnxt);
}
4 changes: 2 additions & 2 deletions sql_parser/ast_node/ast_node.h
Original file line number Diff line number Diff line change
@@ -294,7 +294,7 @@ class AstNode {
return rSuccess;
}
AstNode* GetAndExpr(const set<AstNode*>& expression);
virtual RetCode SetScanAttrList(const SemanticContext &sem_cnxt);
virtual RetCode SetScanAttrList(SemanticContext *sem_cnxt);
AstNodeType ast_node_type_;
string expr_str_;
};
@@ -316,7 +316,7 @@ class AstStmtList : public AstNode {
AstStmtList(AstNodeType ast_node_type, AstNode* stmt, AstNode* next);
~AstStmtList();
void Print(int level = 0) const;
RetCode SetScanAttrList(const SemanticContext &sem_cnxt);
RetCode SetScanAttrList(SemanticContext *sem_cnxt);
RetCode SemanticAnalisys(SemanticContext* sem_cnxt);
RetCode PushDownCondition(PushDownConditionContext& pdccnxt);
RetCode GetLogicalPlan(LogicalOperator*& logic_plan);
Loading