| 138 | } |
| 139 | |
| 140 | std::tuple<std::vector<int>, std::vector<std::string>, std::vector<AggregateKind>,std::vector<std::string>> |
| 141 | parseGroupByExpression(const std::string & queryString, std::size_t num_cols){ |
| 142 | std::vector<AggregateKind> aggregation_types; |
| 143 | std::vector<std::string> aggregation_input_expressions; |
| 144 | std::vector<int> group_column_indices; |
| 145 | |
| 146 | // Get aggregations |
| 147 | std::vector<std::string> aggregation_expressions; |
| 148 | std::vector<std::string> aggregation_column_assigned_aliases; |
| 149 | |
| 150 | auto rangeStart = queryString.find("("); |
| 151 | auto rangeEnd = queryString.rfind(")") - rangeStart; |
| 152 | std::string combined_expression = queryString.substr(rangeStart + 1, rangeEnd - 1); |
| 153 | |
| 154 | // in case UNION exists, |
| 155 | if (combined_expression == "group=[{*}]") { |
| 156 | StringUtil::findAndReplaceAll(combined_expression, "*", StringUtil::makeCommaDelimitedSequence(num_cols)); |
| 157 | } |
| 158 | |
| 159 | group_column_indices = get_group_columns(combined_expression); |
| 160 | std::vector<std::string> expressions = get_expressions_from_expression_list(combined_expression); |
| 161 | for(std::string expr : expressions) { |
| 162 | std::string expression = std::regex_replace(expr, std::regex("^ +| +$|( ) +"), "$1"); |
| 163 | if(expression.find("group=") == std::string::npos) { |
| 164 | aggregation_expressions.push_back(expression); |
| 165 | |
| 166 | // if the aggregation has an alias, lets capture it here, otherwise we'll figure out what to call the |
| 167 | // aggregation based on its input |
| 168 | if(expression.find("EXPR$") == 0) |
| 169 | aggregation_column_assigned_aliases.push_back(""); |
| 170 | else |
| 171 | aggregation_column_assigned_aliases.push_back(expression.substr(0, expression.find("=["))); |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | for(std::string expression : aggregation_expressions) { |
| 176 | aggregation_types.push_back(get_aggregation_operation(expression)); |
| 177 | aggregation_input_expressions.push_back(get_string_between_outer_parentheses(expression)); |
| 178 | } |
| 179 | return std::make_tuple(std::move(group_column_indices), std::move(aggregation_input_expressions), |
| 180 | std::move(aggregation_types), std::move(aggregation_column_assigned_aliases)); |
| 181 | } |
| 182 | |
| 183 | std::tuple<std::vector<int>, std::vector<std::string>, std::vector<AggregateKind>, std::vector<std::string>> |
| 184 | modGroupByParametersPostComputeAggregations(const std::vector<int> & group_column_indices, |
no test coverage detected