diff --git a/example/generate_rand_csv.c b/example/generate_rand_csv.c index 67d52ada..6f279469 100644 --- a/example/generate_rand_csv.c +++ b/example/generate_rand_csv.c @@ -6,12 +6,11 @@ int main(int argc, char** argv) { if (argc<3) { - printf("%s \n", argv[0]); + printf("%s \n", argv[0]); return -1; } srand(1234); - int line_no=0; for(int i=0; i muldivQ; std::vector addsubQ; @@ -410,7 +411,7 @@ struct s3select : public bsc::grammar int parse_query(const char* input_query) { - if(get_projections_list().empty() == false) + if(!get_projections_list().empty()) { return 0; //already parsed } @@ -756,13 +757,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(); @@ -772,11 +771,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(); @@ -826,7 +823,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 == "==") { @@ -859,7 +856,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") { @@ -893,17 +890,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(); @@ -917,9 +915,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(); @@ -979,7 +977,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); } @@ -1175,16 +1173,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"); }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"); } } @@ -1305,7 +1303,6 @@ class base_s3object protected: scratch_area* m_sa; - std::string m_obj_name; public: explicit base_s3object(scratch_area* m) : m_sa(m){} @@ -1462,10 +1459,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 { @@ -1498,7 +1495,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(); } @@ -1541,7 +1538,7 @@ 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 )) { @@ -1549,7 +1546,7 @@ class csv_object : public base_s3object } 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 @@ -1627,11 +1624,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)); @@ -1641,14 +1637,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(); } @@ -1693,6 +1687,6 @@ class csv_object : public base_s3object } }; -};//namespace +} //namespace #endif diff --git a/include/s3select_functions.h b/include/s3select_functions.h index 03880d9e..855dbd93 100644 --- a/include/s3select_functions.h +++ b/include/s3select_functions.h @@ -143,12 +143,12 @@ class __function : public base_statement private: bs_stmt_vec_t arguments; std::string name; - base_function* m_func_impl; + base_function* m_func_impl; // todo: separate the object types used when constructing the __function vs when m_func_impl should be fixed s3select_functions* m_s3select_functions; variable m_result; bool m_is_aggregate_function; - void _resolve_name() + void _resolve_name() // todo: separate the object types used when constructing the __function vs when m_func_impl should be fixed { if (m_func_impl) { @@ -268,7 +268,7 @@ class __function : public base_statement std::string print(int ident) override { - return std::string(0); + return std::string{}; } void push_argument(base_statement* arg) @@ -277,7 +277,7 @@ class __function : public base_statement } - bs_stmt_vec_t& get_arguments() + const bs_stmt_vec_t& get_arguments() const { return arguments; } @@ -300,7 +300,7 @@ class __function : public base_statement } /* - s3-select function defintions + s3-select function definitions */ struct _fn_add : public base_function { @@ -504,7 +504,7 @@ struct _fn_to_int : public base_function throw base_s3select_exception("characters after int!"); return false; } - } + } else if (func_arg.type == value::value_En_t::FLOAT) { i = func_arg.dbl(); @@ -524,42 +524,43 @@ struct _fn_to_int : public base_function struct _fn_to_float : public base_function { - value var_result; - value v_from; bool operator()(bs_stmt_vec_t* args, variable* result) override { - char* perr; - double d=0; value v = (*args->begin())->eval(); - if (v.type == value::value_En_t::STRING) + switch (v.type) { + + case value::value_En_t::STRING: { - errno = 0; - d = strtod(v.str(), &perr) ; //TODO check error before constructor - if ((errno == ERANGE && (d == LONG_MAX || d == LONG_MIN)) || (errno != 0 && d == 0)) { + char* pend; + double d = strtod(v.str(), &pend); + if (errno == ERANGE) { throw base_s3select_exception("converted value would fall out of the range of the result type!"); - return false; - } - - if (*perr != '\0') { - throw base_s3select_exception("characters after float!"); - return false; - } - } - else if (v.type == value::value_En_t::FLOAT) - { - d = v.dbl(); + } + if (pend == v.str()) { + // no number found + throw base_s3select_exception("text cannot be converted to a number"); + } + if (*pend) { + throw base_s3select_exception("extra characters after the number"); + } + + var_result = d; } - else - { - d = v.i64(); + break; + + case value::value_En_t::FLOAT: + var_result = v.dbl(); + break; + + default: + var_result = v.i64(); + break; } - var_result = d; *result = var_result; - return true; } @@ -587,7 +588,7 @@ struct _fn_to_timestamp : public base_function value v_str; - bool datetime_validation() + [[nodiscard]] bool datetime_validation() const { //TODO temporary , should check for leap year @@ -645,7 +646,7 @@ struct _fn_to_timestamp : public base_function bsc::parse_info<> info_dig = bsc::parse(v_str.str(), d_yyyymmdd_dig >> *(separator) >> d_time_dig); - if(datetime_validation()==false or !info_dig.full) + if(!datetime_validation() || !info_dig.full) { throw base_s3select_exception("input date-time is illegal"); } @@ -681,7 +682,7 @@ struct _fn_extact_from_timestamp : public base_function val_date_part = date_part->eval();//TODO could be done once? - if(val_date_part.is_string()== false) + if(!val_date_part.is_string()) { throw base_s3select_exception("first parameter should be string"); } @@ -690,7 +691,7 @@ struct _fn_extact_from_timestamp : public base_function base_statement* ts = *iter; - if(ts->eval().is_timestamp()== false) + if(!ts->eval().is_timestamp()) { throw base_s3select_exception("second parameter is not timestamp"); } @@ -747,7 +748,7 @@ struct _fn_diff_timestamp : public base_function iter++; base_statement* dt1_param = *iter; val_dt1 = dt1_param->eval(); - if (val_dt1.is_timestamp() == false) + if (!val_dt1.is_timestamp()) { throw base_s3select_exception("second parameter should be timestamp"); } @@ -755,7 +756,7 @@ struct _fn_diff_timestamp : public base_function iter++; base_statement* dt2_param = *iter; val_dt2 = dt2_param->eval(); - if (val_dt2.is_timestamp() == false) + if (!val_dt2.is_timestamp()) { throw base_s3select_exception("third parameter should be timestamp"); } @@ -815,7 +816,7 @@ struct _fn_add_to_timestamp : public base_function base_statement* date_part = *iter; val_date_part = date_part->eval();//TODO could be done once? - if(val_date_part.is_string()== false) + if(!val_date_part.is_string()) { throw base_s3select_exception("first parameter should be string"); } @@ -824,7 +825,7 @@ struct _fn_add_to_timestamp : public base_function base_statement* quan = *iter; val_quantity = quan->eval(); - if (val_quantity.is_number() == false) + if (!val_quantity.is_number()) { throw base_s3select_exception("second parameter should be number"); //TODO what about double? } @@ -833,7 +834,7 @@ struct _fn_add_to_timestamp : public base_function base_statement* ts = *iter; val_timestamp = ts->eval(); - if(val_timestamp.is_timestamp() == false) + if(!val_timestamp.is_timestamp()) { throw base_s3select_exception("third parameter should be time-stamp"); } @@ -993,14 +994,14 @@ struct _fn_like : public base_function value res; std::regex compiled_regex; - _fn_like(value s) + explicit _fn_like(value s) { std::string string_value = s.to_string(); transform(string_value); compiled_regex = std::regex(string_value); } - void transform(std::string& s) + static void transform(std::string& s) { std::string::size_type i = 0; while (!s.empty()) @@ -1482,12 +1483,12 @@ struct _fn_trailing : public base_function { base_function* s3select_functions::create(std::string_view fn_name,const bs_stmt_vec_t &arguments) { - const FunctionLibrary::const_iterator iter = m_functions_library.find(fn_name.data()); + const auto iter = m_functions_library.find(fn_name.data()); if (iter == m_functions_library.end()) { std::string msg; - msg = std::string{fn_name} + " " + " function not found"; + msg = std::string{fn_name} + " function not found"s; throw base_s3select_exception(msg, base_s3select_exception::s3select_exp_en_t::FATAL); } @@ -1640,12 +1641,12 @@ const base_statement* base_statement::get_aggregate() const return this; } - if (left() && (res=left()->get_aggregate())!=0) + if (left() && (res=left()->get_aggregate())!=nullptr) { return res; } - if (right() && (res=right()->get_aggregate())!=0) + if (right() && (res=right()->get_aggregate())!=nullptr) { return res; } @@ -1661,7 +1662,7 @@ const base_statement* base_statement::get_aggregate() const } } } - return 0; + return nullptr; } bool base_statement::is_column_reference() const diff --git a/include/s3select_oper.h b/include/s3select_oper.h index 57c077e4..f79778b6 100644 --- a/include/s3select_oper.h +++ b/include/s3select_oper.h @@ -48,7 +48,7 @@ class ChunkAllocator : public std::allocator { // allocate storage for _Count elements of type T - pointer res = (pointer)(buffer_ptr + buffer_capacity); + auto res = (pointer)(buffer_ptr + buffer_capacity); buffer_capacity+= sizeof(T) * num_of_element; @@ -70,7 +70,7 @@ class ChunkAllocator : public std::allocator } //================================== - inline void deallocate(pointer p, size_type n) + inline void deallocate(pointer p, size_type n) // todo remove as both hides non-virtual and unused { } @@ -224,10 +224,10 @@ class scratch_area void set_column_pos(const char* n, int pos)//TODO use std::string { - m_column_name_pos.push_back( std::pair(n, pos)); + m_column_name_pos.emplace_back(std::pair(n, pos)); } - void update(std::vector& tokens, size_t num_of_tokens) + void update(const std::vector& tokens, size_t num_of_tokens) { std::copy_n(tokens.begin(), num_of_tokens, m_columns.begin()); m_upper_bound = num_of_tokens; @@ -237,7 +237,7 @@ class scratch_area { //done only upon building the AST, not on "runtime" - for( auto iter : m_column_name_pos) + for (const auto& iter : m_column_name_pos) { if (!strcmp(iter.first.c_str(), n)) { @@ -258,7 +258,7 @@ class scratch_area return m_columns[column_pos]; } - int get_num_of_columns() + int get_num_of_columns() const { return m_upper_bound; } @@ -271,26 +271,26 @@ class s3select_reserved_word enum class reserve_word_en_t { NA, - S3S_NULL,//TODO check AWS defintions for reserve words, its a long list , what about functions-names? + S3S_NULL,//TODO check AWS definitions for reserve words, its a long list , what about functions-names? S3S_NAN } ; using reserved_words = std::map; - const reserved_words m_reserved_words= + inline static const reserved_words m_reserved_words= { {"null",reserve_word_en_t::S3S_NULL},{"NULL",reserve_word_en_t::S3S_NULL}, {"nan",reserve_word_en_t::S3S_NAN},{"NaN",reserve_word_en_t::S3S_NAN} }; - bool is_reserved_word(std::string & token) + static bool is_reserved_word(std::string & token) { return m_reserved_words.find(token) != m_reserved_words.end() ; } - reserve_word_en_t get_reserved_word(std::string & token) + static reserve_word_en_t get_reserved_word(std::string & token) // todo consider returning std::optional { - if (is_reserved_word(token)==true) + if (is_reserved_word(token)) { return m_reserved_words.find(token)->second; } @@ -321,11 +321,11 @@ class projection_alias { //purpose: only unique alias names. - for(auto alias: alias_map) + for(const auto& alias: alias_map) { - if(alias.first.compare(alias_name) == 0) + if(alias.first == alias_name) { - return false; //alias name already exist + return false; //alias name already exists } } @@ -335,16 +335,17 @@ class projection_alias return true; } - base_statement* search_alias(std::string alias_name) + // todo consider returning std::optional + base_statement* search_alias(const std::string&& alias_name) const { - for(auto alias: alias_map) + for(const auto& alias: alias_map) { - if(alias.first.compare(alias_name) == 0) + if(alias.first == alias_name) { - return alias.second; //refernce to execution node + return alias.second; //reference to execution node } } - return 0; + return nullptr; } }; @@ -413,7 +414,7 @@ class value { public: - typedef union + typedef union // consider std::variant { int64_t num; char* str;//TODO consider string_view @@ -543,11 +544,11 @@ class value m_to_string.assign( __val.str ); } - return std::string( m_to_string.c_str() ); + return std::string( m_to_string ); } - value& operator=(value& o) + value& operator=(const value& o) { if(o.type == value_En_t::STRING) { @@ -605,17 +606,17 @@ class value return *this; } - int64_t i64() + int64_t i64() const { return __val.num; } - const char* str() + const char* str() const { return __val.str; } - double dbl() + double dbl() const { return __val.dbl; } @@ -625,7 +626,7 @@ class value return __val.timestamp; } - bool operator<(const value& v)//basic compare operator , most itensive runtime operation + bool operator<(const value& v) const//basic compare operator , most itensive runtime operation { //TODO NA possible? if (is_string() && v.is_string()) @@ -674,7 +675,7 @@ class value throw base_s3select_exception("operands not of the same type(numeric , string), while comparision"); } - bool operator>(const value& v) //basic compare operator , most itensive runtime operation + bool operator>(const value& v) const //basic compare operator , most itensive runtime operation { //TODO NA possible? if (is_string() && v.is_string()) @@ -723,7 +724,7 @@ class value throw base_s3select_exception("operands not of the same type(numeric , string), while comparision"); } - bool operator==(const value& v) //basic compare operator , most itensive runtime operation + bool operator==(const value& v) const //basic compare operator , most itensive runtime operation { //TODO NA possible? if (is_string() && v.is_string()) @@ -772,31 +773,32 @@ class value throw base_s3select_exception("operands not of the same type(numeric , string), while comparision"); } - bool operator<=(const value& v) + + bool operator<=(const value& v) const { - if ((is_null() || v.is_null()) || (is_nan() || v.is_nan())) { + if (is_null() || v.is_null() || is_nan() || v.is_nan()) { return false; - } else { - return !(*this>v); - } + } + + return !(*this > v); } - bool operator>=(const value& v) + bool operator>=(const value& v) const { - if ((is_null() || v.is_null()) || (is_nan() || v.is_nan())) { + if (is_null() || v.is_null() || is_nan() || v.is_nan()) { return false; - } else { - return !(*this //conversion rules for arithmetical binary operations @@ -845,7 +847,6 @@ class value if ((l.is_null() || r.is_null()) || (l.is_nan() || r.is_nan())) { l.set_nan(); - return l; } return l; @@ -943,11 +944,11 @@ class base_statement virtual base_statement* left() const { - return 0; + return nullptr; } virtual base_statement* right() const { - return 0; + return nullptr; } virtual std::string print(int ident) =0;//TODO complete it, one option to use level parametr in interface , virtual bool semantic() =0;//done once , post syntax , traverse all nodes and validate semantics. @@ -1021,7 +1022,7 @@ class base_statement } } - bool is_set_last_call() + bool is_set_last_call() const { return is_last_call; } @@ -1031,7 +1032,7 @@ class base_statement m_is_cache_result = false; } - bool is_result_cached() + bool is_result_cached() const { return m_is_cache_result == true; } @@ -1128,7 +1129,7 @@ class variable : public base_statement } } - variable(s3select_reserved_word::reserve_word_en_t reserve_word) + explicit variable(s3select_reserved_word::reserve_word_en_t reserve_word) { if (reserve_word == s3select_reserved_word::reserve_word_en_t::S3S_NULL) { @@ -1150,9 +1151,10 @@ class variable : public base_statement } } - void operator=(value& v) + variable& operator=(value& v) { var_value = v; + return *this; } void set_value(const char* s) @@ -1268,7 +1270,7 @@ class variable : public base_statement //not enter this scope again column_pos = column_alias; - if(m_projection_alias == 0) + if(m_projection_alias == nullptr) { throw base_s3select_exception(std::string("alias {")+_name+std::string("} or column not exist in schema"), base_s3select_exception::s3select_exp_en_t::FATAL); } @@ -1283,7 +1285,7 @@ class variable : public base_statement throw base_s3select_exception("number of calls exceed maximum size, probably a cyclic reference to alias", base_s3select_exception::s3select_exp_en_t::FATAL); } - if (m_projection_alias->is_result_cached() == false) + if (!m_projection_alias->is_result_cached()) { var_value = m_projection_alias->eval(); m_projection_alias->set_result_cache(var_value); @@ -1303,14 +1305,14 @@ class variable : public base_statement return var_value; } - virtual std::string print(int ident) + std::string print(int ident) override { //std::string out = std::string(ident,' ') + std::string("var:") + std::to_string(var_value.__val.num); //return out; return std::string("#");//TBD } - virtual bool semantic() + bool semantic() override { return false; } @@ -1334,7 +1336,7 @@ class arithmetic_operand : public base_statement public: - virtual bool semantic() + bool semantic() override { return true; } @@ -1348,7 +1350,7 @@ class arithmetic_operand : public base_statement return r; } - virtual std::string print(int ident) + std::string print(int ident) override { //std::string out = std::string(ident,' ') + "compare:" += std::to_string(_cmp) + "\n" + l->print(ident-5) +r->print(ident+5); //return out; @@ -1392,7 +1394,7 @@ class arithmetic_operand : public base_statement arithmetic_operand(base_statement* _l, cmp_t c, base_statement* _r):l(_l), r(_r), _cmp(c),negation_result(false) {} - arithmetic_operand(base_statement* p)//NOT operator + explicit arithmetic_operand(base_statement* p)//NOT operator { l = dynamic_cast(p)->l; r = dynamic_cast(p)->r; @@ -1401,7 +1403,7 @@ class arithmetic_operand : public base_statement negation_result = ! dynamic_cast(p)->negation_result; } - virtual ~arithmetic_operand() {} + virtual ~arithmetic_operand() = default; }; class logical_operand : public base_statement @@ -1430,14 +1432,14 @@ class logical_operand : public base_statement return r; } - virtual bool semantic() + bool semantic() override { return true; } logical_operand(base_statement* _l, oplog_t _o, base_statement* _r):l(_l), r(_r), _oplog(_o),negation_result(false) {} - logical_operand(base_statement * p)//NOT operator + explicit logical_operand(base_statement * p)//NOT operator { l = dynamic_cast(p)->l; r = dynamic_cast(p)->r; @@ -1448,7 +1450,7 @@ class logical_operand : public base_statement virtual ~logical_operand() {} - virtual std::string print(int ident) + std::string print(int ident) override { //std::string out = std::string(ident, ' ') + "logical_operand:" += std::to_string(_oplog) + "\n" + l->print(ident - 5) + r->print(ident + 5); //return out; @@ -1466,7 +1468,7 @@ class logical_operand : public base_statement { if (a.i64() == false) { - res = false ^ negation_result; + res = negation_result; return var_value = res; } value b = r->eval(); @@ -1480,7 +1482,7 @@ class logical_operand : public base_statement { if (a.i64() == true) { - res = true ^ negation_result; + res = !negation_result; return var_value = res; } value b = r->eval(); @@ -1520,12 +1522,12 @@ class mulldiv_operation : public base_statement return r; } - virtual bool semantic() + bool semantic() override { return true; } - virtual std::string print(int ident) + std::string print(int ident) override { //std::string out = std::string(ident, ' ') + "mulldiv_operation:" += std::to_string(_mulldiv) + "\n" + l->print(ident - 5) + r->print(ident + 5); //return out; @@ -1564,7 +1566,7 @@ class mulldiv_operation : public base_statement mulldiv_operation(base_statement* _l, muldiv_t c, base_statement* _r):l(_l), r(_r), _mulldiv(c) {} - virtual ~mulldiv_operation() {} + virtual ~mulldiv_operation() = default; }; class addsub_operation : public base_statement @@ -1593,16 +1595,16 @@ class addsub_operation : public base_statement return r; } - virtual bool semantic() + bool semantic() override { return true; } addsub_operation(base_statement* _l, addsub_op_t _o, base_statement* _r):l(_l), r(_r), _op(_o) {} - virtual ~addsub_operation() {} + virtual ~addsub_operation() = default; - virtual std::string print(int ident) + std::string print(int ident) override { //std::string out = std::string(ident, ' ') + "addsub_operation:" += std::to_string(_op) + "\n" + l->print(ident - 5) + r->print(ident + 5); return std::string("#");//TBD @@ -1645,14 +1647,14 @@ class negate_function_operation : public base_statement public: - negate_function_operation(base_statement *f):function_to_negate(f){} + explicit negate_function_operation(base_statement *f):function_to_negate(f){} - virtual std::string print(int ident) + std::string print(int ident) override { return std::string("#");//TBD } - virtual bool semantic() + bool semantic() override { return true; } @@ -1696,7 +1698,7 @@ class base_function base_function() : aggregate(false) {} bool is_aggregate() const { - return aggregate == true; + return aggregate; } virtual void get_aggregate_result(variable*) {} @@ -1709,6 +1711,6 @@ class base_function }; -};//namespace +}//namespace #endif diff --git a/test/s3select_test.cpp b/test/s3select_test.cpp index 13497224..84c8f876 100644 --- a/test/s3select_test.cpp +++ b/test/s3select_test.cpp @@ -1,7 +1,6 @@ #include "s3select.h" #include "gtest/gtest.h" #include -#include "boost/date_time/gregorian/gregorian.hpp" #include "boost/date_time/posix_time/posix_time.hpp" using namespace s3selectEngine; @@ -102,7 +101,7 @@ class gen_expr std::string generate() { - std::string exp = ""; + std::string exp; open = 0; for (int i = 0; i < 10; i++) @@ -132,7 +131,7 @@ std::string run_s3select(std::string expression) s3_csv_object.run_s3select_on_object(s3select_result, in.c_str(), in.size(), false, false, true); - s3select_result = s3select_result.substr(0, s3select_result.find_first_of(",")); + s3select_result = s3select_result.substr(0, s3select_result.find_first_of(',')); return s3select_result; } @@ -149,7 +148,7 @@ TEST(TestS3SElect, s3select_vs_C) std::string exp = g.generate(); std::string c_result = run_expression_in_C_prog( exp.c_str() ); - char* err=0; + char* err; double c_dbl_res = strtod(c_result.c_str(), &err); std::string input_query = "select " + exp + " from stdin;" ; @@ -167,7 +166,7 @@ TEST(TestS3SElect, s3select_vs_C) TEST(TestS3SElect, ParseQuery) { //TODO syntax issues ? - //TODO error messeges ? + //TODO error messages ? s3select s3select_syntax;