Skip to content

Commit

Permalink
[?] Rename internal GenQuery2 data type.
Browse files Browse the repository at this point in the history
  • Loading branch information
korydraughn committed Jun 7, 2024
1 parent 65f6b6e commit cc7c757
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
12 changes: 6 additions & 6 deletions server/genquery2/dsl/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ rules only.
%type <gq2_detail::range> range;
%type <gq2_detail::selection> selection;
%type <gq2_detail::column> column;
%type <gq2_detail::select_function> select_function;
%type <gq2_detail::function> function;
%type <gq2_detail::condition> condition;
%type <gq2_detail::condition_expression> condition_expression;
%type <std::vector<std::string>> list_of_string_literals;
Expand Down Expand Up @@ -191,16 +191,16 @@ selections:

selection:
column { $$ = std::move($1); }
| select_function { $$ = std::move($1); }
| function { $$ = std::move($1); }

column:
IDENTIFIER { $$ = gq2_detail::column{std::move($1)}; }
| CAST PAREN_OPEN IDENTIFIER AS IDENTIFIER PAREN_CLOSE { $$ = gq2_detail::column{$3, $5}; }
| CAST PAREN_OPEN IDENTIFIER AS IDENTIFIER PAREN_OPEN POSITIVE_INTEGER PAREN_CLOSE PAREN_CLOSE { $$ = gq2_detail::column{$3, fmt::format("{}({})", $5, $7)}; }

select_function:
IDENTIFIER PAREN_OPEN column PAREN_CLOSE { $$ = gq2_detail::select_function{std::move($1), gq2_detail::column{std::move($3)}}; }
/*IDENTIFIER PAREN_OPEN IDENTIFIER PAREN_CLOSE { $$ = gq2_detail::select_function{std::move($1), gq2_detail::column{std::move($3)}}; }*/
function:
IDENTIFIER PAREN_OPEN column PAREN_CLOSE { $$ = gq2_detail::function{std::move($1), gq2_detail::column{std::move($3)}}; }
/*IDENTIFIER PAREN_OPEN IDENTIFIER PAREN_CLOSE { $$ = gq2_detail::function{std::move($1), gq2_detail::column{std::move($3)}}; }*/

conditions:
condition { $$ = gq2_detail::conditions{std::move($1)}; }
Expand All @@ -211,7 +211,7 @@ conditions:

condition:
column condition_expression { $$ = gq2_detail::condition(std::move($1), std::move($2)); }
| select_function condition_expression { $$ = gq2_detail::condition(std::move($1), std::move($2)); }
| function condition_expression { $$ = gq2_detail::condition(std::move($1), std::move($2)); }

condition_expression:
LIKE STRING_LITERAL { $$ = gq2_detail::condition_like(std::move($2)); }
Expand Down
10 changes: 5 additions & 5 deletions server/genquery2/include/irods/private/genquery2_ast_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ namespace irods::experimental::genquery2
std::string type_name;
}; // struct column

struct select_function
struct function
{
select_function() = default;
function() = default;

select_function(std::string name, column column)
function(std::string name, column column)
: name{std::move(name)}
, column{std::move(column)}
{
}

std::string name;
column column;
}; // struct select_function
}; // struct function

struct condition_like
{
Expand Down Expand Up @@ -220,7 +220,7 @@ namespace irods::experimental::genquery2
using condition_type = boost::variant<logical_and, logical_or, logical_not, logical_grouping, condition>;

// clang-format off
using selection = boost::variant<select_function, column>;
using selection = boost::variant<function, column>;
using selections = std::vector<selection>;
using conditions = std::vector<condition_type>;
// clang-format on
Expand Down
18 changes: 9 additions & 9 deletions server/genquery2/src/genquery2_sql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -863,32 +863,32 @@ namespace irods::experimental::genquery2
return fmt::format("cast({}.{} as {})", alias, iter->second.name, _column.type_name);
} // to_sql

auto to_sql(gq_state& _state, const select_function& _select_function) -> std::string
auto to_sql(gq_state& _state, const function& _function) -> std::string
{
const auto iter = column_name_mappings.find(_select_function.column.name);
const auto iter = column_name_mappings.find(_function.column.name);

if (iter == std::end(column_name_mappings)) {
throw std::invalid_argument{fmt::format("unknown column: {}", _select_function.column.name)};
throw std::invalid_argument{fmt::format("unknown column: {}", _function.column.name)};
}

// Capture all column objects as some parts of the implementation need to access them later in
// order to generate the proper SQL.
_state.ast_column_ptrs.push_back(&_select_function.column);
_state.ast_column_ptrs.push_back(&_function.column);

auto [is_special_column, table_alias] =
setup_column_for_post_processing(_state, _select_function.column, iter->second);
setup_column_for_post_processing(_state, _function.column, iter->second);
const std::string_view alias =
is_special_column ? table_alias : _state.table_aliases.at(std::string{iter->second.table});

if (_select_function.column.type_name.empty()) {
return fmt::format("{}({}.{})", _select_function.name, alias, iter->second.name);
if (_function.column.type_name.empty()) {
return fmt::format("{}({}.{})", _function.name, alias, iter->second.name);
}

return fmt::format("{}(cast({}.{} as {}))",
_select_function.name,
_function.name,
alias,
iter->second.name,
_select_function.column.type_name);
_function.column.type_name);
} // to_sql

auto to_sql(gq_state& _state, const selections& _selections) -> std::string
Expand Down

0 comments on commit cc7c757

Please sign in to comment.