Skip to content

Commit

Permalink
The semantic analysis for nested-calls of non-aggregate functions wit… (
Browse files Browse the repository at this point in the history
#46)

* The semantic analysis for nested-calls of non-aggregate functions with aggregate function was wrong, this PR fix several issues. first it rejects illegal queries, second it executes correctly these use-cases.

Signed-off-by: gal salomon <gal.salomon@gmail.com>

* semantic analysis rejects illegal aggregation queries; it identifying wrong combinations of aggregation projection and non-aggregation projection

Signed-off-by: gal salomon <gal.salomon@gmail.com>

* marking subtree as runnable; changes to execution flow to support correct execution of nested&complex aggregation queries

Signed-off-by: gal salomon <gal.salomon@gmail.com>

* adding const qualifier to methods/variables; as part of this effort the /reolve_name/ of functions is now done upon semantic phase before execution; semantic phase should be more the name-resolving(will be on later phase);  [ #42 ]

Signed-off-by: gal salomon <gal.salomon@gmail.com>
  • Loading branch information
galsalomon66 committed Jan 1, 2021
1 parent d723f3f commit 1ea37ae
Show file tree
Hide file tree
Showing 4 changed files with 335 additions and 250 deletions.
69 changes: 32 additions & 37 deletions include/s3select.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,6 @@ class s3select_projections
std::vector<base_statement*> m_projections;

public:
bool is_aggregate()
{
//TODO iterate on projections , and search for aggregate
//for(auto p : m_projections){}

return false;
}

bool semantic()
{
//TODO check aggragtion function are not nested
return false;
}

std::vector<base_statement*>* get()
{
Expand Down Expand Up @@ -71,7 +58,6 @@ struct actionQ
std::vector<std::string> trimTypeQ;
projection_alias alias_map;
std::string from_clause;
std::vector<std::string> schema_columns;
s3select_projections projections;

uint64_t in_set_count;
Expand All @@ -80,28 +66,28 @@ struct actionQ

actionQ():in_set_count(0), when_than_count(0){}

std::map<void*,std::vector<char*> *> x_map;
std::map<const void*,std::vector<const char*> *> x_map;

~actionQ()
{
for(auto m : x_map)
delete m.second;
}

bool is_already_scanned(void *th,char *a)
bool is_already_scanned(const void *th,const char *a)
{
//purpose: caller get indication in the case a specific builder is scan more than once the same text(pointer)
auto t = x_map.find(th);

if(t == x_map.end())
{
auto v = new std::vector<char*>;//TODO delete
x_map.insert(std::pair<void*,std::vector<char*> *>(th,v));
auto v = new std::vector<const char*>;//TODO delete
x_map.insert(std::pair<const void*,std::vector<const char*> *>(th,v));
v->push_back(a);
}
else
{
for( auto c : *(t->second) )
for(auto& c : *(t->second))
{
if( strcmp(c,a) == 0)
return true;
Expand Down Expand Up @@ -383,34 +369,42 @@ struct s3select : public bsc::grammar<s3select>

int semantic()
{
for (const auto& e : get_projections_list())
for (const auto &e : get_projections_list())
{
base_statement* aggr;

if ((aggr = e->get_aggregate()) != nullptr)
e->resolve_node();
//upon validate there is no aggregation-function nested calls, it validates legit aggregation call.
if (e->is_nested_aggregate(aggr_flow))
{
if (aggr->is_nested_aggregate(aggr))
{
error_description = "nested aggregation function is illegal i.e. sum(...sum ...)";
throw base_s3select_exception(error_description, base_s3select_exception::s3select_exp_en_t::FATAL);
}

aggr_flow = true;
error_description = "nested aggregation function is illegal i.e. sum(...sum ...)";
throw base_s3select_exception(error_description, base_s3select_exception::s3select_exp_en_t::FATAL);
}
}

if (aggr_flow == true)
for (const auto& e : get_projections_list())
{// atleast one projection column contain aggregation function
for (const auto &e : get_projections_list())
{
auto skip_expr = e->get_aggregate();
auto aggregate_expr = e->get_aggregate();

if (e->is_binop_aggregate_and_column(skip_expr))
if (aggregate_expr)
{
error_description = "illegal expression. /select sum(c1) + c1 ..../ is not allow type of query";
throw base_s3select_exception(error_description, base_s3select_exception::s3select_exp_en_t::FATAL);
//per each column, subtree is mark to skip except for the aggregation function subtree.
//for an example: substring( ... , sum() , count() ) :: the substring is mark to skip execution, while sum and count not.
e->set_skip_non_aggregate(true);
e->mark_aggreagtion_subtree_to_execute();
}
else
{
//in case projection column is not aggregate, the projection column must *not* contain reference to columns.
if(e->is_column_reference())
{
error_description = "illegal query; projection contains aggregation function is not allowed with projection contains column reference";
throw base_s3select_exception(error_description, base_s3select_exception::s3select_exp_en_t::FATAL);
}
}

}

}
return 0;
}

Expand Down Expand Up @@ -1447,7 +1441,7 @@ class csv_object : public base_s3object
m_where_clause->traverse_and_apply(m_sa, m_s3_select->get_aliases());
}

for (auto p : m_projections)
for (auto& p : m_projections)
{
p->traverse_and_apply(m_sa, m_s3_select->get_aliases());
}
Expand Down Expand Up @@ -1483,6 +1477,7 @@ class csv_object : public base_s3object
for (auto& i : m_projections)
{
i->set_last_call();
i->set_skip_non_aggregate(false);//projection column is set to be runnable
result.append( i->eval().to_string() );
result.append(",");
}
Expand Down

0 comments on commit 1ea37ae

Please sign in to comment.