forked from galsalomon66/s3select
-
Notifications
You must be signed in to change notification settings - Fork 22
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
S3select: replacing a "naked loop" with std::copy_n #42
Open
ronen-fr
wants to merge
3
commits into
ceph:master
Choose a base branch
from
ronen-fr:wip-ronenf-s3-sug
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+293
−307
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
#include <iostream> | ||
#include <string> | ||
#include <list> | ||
#include <vector> | ||
#include "s3select_oper.h" | ||
#include "s3select_functions.h" | ||
#include "s3select_csv_parser.h" | ||
|
@@ -30,17 +31,17 @@ class s3select_projections | |
std::vector<base_statement*> m_projections; | ||
|
||
public: | ||
bool is_aggregate() | ||
bool is_aggregate() const | ||
{ | ||
//TODO iterate on projections , and search for aggregate | ||
//for(auto p : m_projections){} | ||
|
||
return false; | ||
} | ||
|
||
bool semantic() | ||
bool semantic() const | ||
{ | ||
//TODO check aggragtion function are not nested | ||
//TODO check aggragation function are not nested | ||
return false; | ||
} | ||
|
||
|
@@ -56,8 +57,9 @@ static s3select_reserved_word g_s3select_reserve_word;//read-only | |
struct actionQ | ||
{ | ||
// upon parser is accepting a token (lets say some number), | ||
// it push it into dedicated queue, later those tokens are poped out to build some "higher" contruct (lets say 1 + 2) | ||
// those containers are used only for parsing phase and not for runtime. | ||
// it pushes it into a dedicated queue. These tokens are later popped out to | ||
// build some "higher" construct (1 + 2 for example). | ||
// The containers below are only used during the parsing phase, not for runtime. | ||
|
||
std::vector<mulldiv_operation::muldiv_t> muldivQ; | ||
std::vector<addsub_operation::addsub_op_t> addsubQ; | ||
|
@@ -71,7 +73,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; | ||
|
@@ -385,11 +386,11 @@ struct s3select : public bsc::grammar<s3select> | |
{ | ||
for (const auto& e : get_projections_list()) | ||
{ | ||
base_statement* aggr; | ||
const base_statement* aggr; | ||
|
||
if ((aggr = e->get_aggregate()) != nullptr) | ||
{ | ||
if (aggr->is_nested_aggregate(aggr)) | ||
if (aggr->is_nested_aggregate()) | ||
{ | ||
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); | ||
|
@@ -399,7 +400,7 @@ struct s3select : public bsc::grammar<s3select> | |
} | ||
} | ||
|
||
if (aggr_flow == true) | ||
if (aggr_flow) | ||
for (const auto& e : get_projections_list()) | ||
{ | ||
auto skip_expr = e->get_aggregate(); | ||
|
@@ -416,7 +417,7 @@ struct s3select : public bsc::grammar<s3select> | |
|
||
int parse_query(const char* input_query) | ||
{ | ||
if(get_projections_list().empty() == false) | ||
if(!get_projections_list().empty()) | ||
{ | ||
return 0; //already parsed | ||
} | ||
|
@@ -762,13 +763,11 @@ void push_mulop::builder(s3select* self, const char* a, const char* b) const | |
} | ||
} | ||
|
||
void push_addsub_binop::builder(s3select* self, [[maybe_unused]] const char* a,[[maybe_unused]] const char* b) const | ||
void push_addsub_binop::builder(s3select* self, [[maybe_unused]] const char* a, [[maybe_unused]] const char* b) const | ||
{ | ||
base_statement* l = nullptr, *r = nullptr; | ||
|
||
r = self->getAction()->exprQ.back(); | ||
base_statement* r = self->getAction()->exprQ.back(); | ||
self->getAction()->exprQ.pop_back(); | ||
l = self->getAction()->exprQ.back(); | ||
base_statement* l = self->getAction()->exprQ.back(); | ||
self->getAction()->exprQ.pop_back(); | ||
addsub_operation::addsub_op_t o = self->getAction()->addsubQ.back(); | ||
self->getAction()->addsubQ.pop_back(); | ||
|
@@ -778,11 +777,9 @@ void push_addsub_binop::builder(s3select* self, [[maybe_unused]] const char* a,[ | |
|
||
void push_mulldiv_binop::builder(s3select* self, [[maybe_unused]] const char* a, [[maybe_unused]] const char* b) const | ||
{ | ||
base_statement* vl = nullptr, *vr = nullptr; | ||
|
||
vr = self->getAction()->exprQ.back(); | ||
base_statement* vr = self->getAction()->exprQ.back(); | ||
self->getAction()->exprQ.pop_back(); | ||
vl = self->getAction()->exprQ.back(); | ||
base_statement* vl = self->getAction()->exprQ.back(); | ||
self->getAction()->exprQ.pop_back(); | ||
mulldiv_operation::muldiv_t o = self->getAction()->muldivQ.back(); | ||
self->getAction()->muldivQ.pop_back(); | ||
|
@@ -832,7 +829,7 @@ void push_function_expr::builder(s3select* self, const char* a, const char* b) c | |
void push_compare_operator::builder(s3select* self, const char* a, const char* b) const | ||
{ | ||
std::string token(a, b); | ||
arithmetic_operand::cmp_t c = arithmetic_operand::cmp_t::NA; | ||
arithmetic_operand::cmp_t c; | ||
|
||
if (token == "==") | ||
{ | ||
|
@@ -865,7 +862,7 @@ void push_compare_operator::builder(s3select* self, const char* a, const char* b | |
void push_logical_operator::builder(s3select* self, const char* a, const char* b) const | ||
{ | ||
std::string token(a, b); | ||
logical_operand::oplog_t l = logical_operand::oplog_t::NA; | ||
logical_operand::oplog_t l; | ||
|
||
if (token == "and") | ||
{ | ||
|
@@ -899,17 +896,18 @@ void push_arithmetic_predicate::builder(s3select* self, const char* a, const cha | |
void push_logical_predicate::builder(s3select* self, const char* a, const char* b) const | ||
{ | ||
std::string token(a, b); | ||
base_statement* tl = nullptr; | ||
base_statement* tr = nullptr; | ||
|
||
base_statement* tl = nullptr, *tr = nullptr; | ||
logical_operand::oplog_t oplog = self->getAction()->logical_compareQ.back(); | ||
self->getAction()->logical_compareQ.pop_back(); | ||
|
||
if (self->getAction()->condQ.empty() == false) | ||
if (!self->getAction()->condQ.empty()) | ||
{ | ||
tr = self->getAction()->condQ.back(); | ||
self->getAction()->condQ.pop_back(); | ||
} | ||
if (self->getAction()->condQ.empty() == false) | ||
if (!self->getAction()->condQ.empty()) | ||
{ | ||
tl = self->getAction()->condQ.back(); | ||
self->getAction()->condQ.pop_back(); | ||
|
@@ -923,9 +921,9 @@ void push_logical_predicate::builder(s3select* self, const char* a, const char* | |
void push_negation::builder(s3select* self, const char* a, const char* b) const | ||
{ | ||
std::string token(a, b); | ||
base_statement* pred = nullptr; | ||
base_statement* pred{nullptr}; | ||
|
||
if (self->getAction()->condQ.empty() == false) | ||
if (!self->getAction()->condQ.empty()) | ||
{ | ||
pred = self->getAction()->condQ.back(); | ||
self->getAction()->condQ.pop_back(); | ||
|
@@ -985,7 +983,7 @@ void push_alias_projection::builder(s3select* self, const char* a, const char* b | |
|
||
//mapping alias name to base-statement | ||
bool res = self->getAction()->alias_map.insert_new_entry(alias_name, bs); | ||
if (res == false) | ||
if (!res) | ||
{ | ||
throw base_s3select_exception(std::string("alias <") + alias_name + std::string("> is already been used in query"), base_s3select_exception::s3select_exp_en_t::FATAL); | ||
} | ||
|
@@ -1181,16 +1179,16 @@ void push_data_type::builder(s3select* self, const char* a, const char* b) const | |
|
||
if(cast_operator("int")) | ||
{ | ||
self->getAction()->dataTypeQ.push_back("int"); | ||
self->getAction()->dataTypeQ.emplace_back("int"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, it performs better. |
||
}else if(cast_operator("float")) | ||
{ | ||
self->getAction()->dataTypeQ.push_back("float"); | ||
self->getAction()->dataTypeQ.emplace_back("float"); | ||
}else if(cast_operator("string")) | ||
{ | ||
self->getAction()->dataTypeQ.push_back("string"); | ||
self->getAction()->dataTypeQ.emplace_back("string"); | ||
}else if(cast_operator("timestamp")) | ||
{ | ||
self->getAction()->dataTypeQ.push_back("timestamp"); | ||
self->getAction()->dataTypeQ.emplace_back("timestamp"); | ||
} | ||
} | ||
|
||
|
@@ -1311,7 +1309,6 @@ class base_s3object | |
|
||
protected: | ||
scratch_area* m_sa; | ||
std::string m_obj_name; | ||
|
||
public: | ||
explicit base_s3object(scratch_area* m) : m_sa(m){} | ||
|
@@ -1468,10 +1465,10 @@ class csv_object : public base_s3object | |
|
||
int getMatchRow( std::string& result) //TODO virtual ? getResult | ||
{ | ||
int number_of_tokens = 0; | ||
int number_of_tokens; | ||
|
||
|
||
if (m_aggr_flow == true) | ||
if (m_aggr_flow) | ||
{ | ||
do | ||
{ | ||
|
@@ -1503,7 +1500,7 @@ class csv_object : public base_s3object | |
} | ||
|
||
if (!m_where_clause || m_where_clause->eval().i64() == true) | ||
for (auto i : m_projections) | ||
for (auto& i : m_projections) | ||
{ | ||
i->eval(); | ||
} | ||
|
@@ -1546,15 +1543,15 @@ class csv_object : public base_s3object | |
int extract_csv_header_info() | ||
{ | ||
|
||
if (m_csv_defintion.ignore_header_info == true) | ||
if (m_csv_defintion.ignore_header_info) | ||
{ | ||
while(*m_stream && (*m_stream != m_csv_defintion.row_delimiter )) | ||
{ | ||
m_stream++; | ||
} | ||
m_stream++; | ||
} | ||
else if(m_csv_defintion.use_header_info == true) | ||
else if(m_csv_defintion.use_header_info) | ||
{ | ||
size_t num_of_tokens = getNextRow();//TODO validate number of tokens | ||
|
||
|
@@ -1632,11 +1629,10 @@ class csv_object : public base_s3object | |
p_obj_chunk--; //scan until end-of previous line in chunk | ||
} | ||
|
||
u_int32_t skip_last_bytes = (&(csv_stream[stream_length - 1]) - p_obj_chunk); | ||
int32_t skip_last_bytes = (&(csv_stream[stream_length - 1]) - p_obj_chunk); | ||
m_last_line.assign(p_obj_chunk + 1, p_obj_chunk + 1 + skip_last_bytes); //save it for next chunk | ||
|
||
m_previous_line = true;//it means to skip last line | ||
|
||
} | ||
|
||
return run_s3select_on_object(result, csv_stream, stream_length, m_skip_first_line, m_previous_line, (m_processed_bytes >= obj_size)); | ||
|
@@ -1646,14 +1642,12 @@ class csv_object : public base_s3object | |
public: | ||
int run_s3select_on_object(std::string& result, const char* csv_stream, size_t stream_length, bool skip_first_line, bool skip_last_line, bool do_aggregate) | ||
{ | ||
|
||
|
||
m_stream = (char*)csv_stream; | ||
m_end_stream = (char*)csv_stream + stream_length; | ||
m_is_to_aggregate = do_aggregate; | ||
m_skip_last_line = skip_last_line; | ||
|
||
if(m_extract_csv_header_info == false) | ||
if(!m_extract_csv_header_info) | ||
{ | ||
extract_csv_header_info(); | ||
} | ||
|
@@ -1698,6 +1692,6 @@ class csv_object : public base_s3object | |
} | ||
}; | ||
|
||
};//namespace | ||
} //namespace | ||
|
||
#endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
== true/false is style issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'== true' is a bit over the line dividing 'style' and 'irregular and strange'...
And, BTW - the 'if' statement semantics is 'if the expression in parens evaluates to 'true' then do ...'.
No new semantic meaning is conveyed by the '== true'. It just adds to the reader's burden.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed.
there is nothing logical or practical about /x == true/
i probably wanted to remind myself its a boolean and not some number
will change that.
this style appears in our code-base.
[ find ./src -name '.cc' -o -name '.h' | xargs egrep '== false|== true' | grep -v s3select | wc ] ;