MCPcopy Create free account
hub / github.com/BlazingDB/blazingsql / make_nested_token

Function make_nested_token

engine/src/parser/expression_utils.cpp:1540–1586  ·  view source on GitHub ↗

Used by `nary_to_nestedbinary` to convert an expression string CALL(arg1, arg2, arg3, ...) to CALL(CALL(CALL(arg1, arg2), arg3), ...)

Source from the content-addressed store, hash-verified

1538
1539// Used by `nary_to_nestedbinary` to convert an expression string CALL(arg1, arg2, arg3, ...) to CALL(CALL(CALL(arg1, arg2), arg3), ...)
1540static inline std::string make_nested_token(std::string & subexpression,
1541 const std::string & operator_name) {
1542 static const std::string::value_type arg_separator = ',';
1543 static const std::string::value_type flag_separator = 1;
1544
1545 bool isnt_string = true;
1546 std::size_t bracket_count = 0;
1547 std::string::value_type * data = subexpression.data();
1548 do {
1549 switch (*data) {
1550 case '(': ++bracket_count; break;
1551 case ')': --bracket_count; break;
1552 case '\'': isnt_string = !isnt_string; break;
1553 }
1554 if (isnt_string && !bracket_count && *data == arg_separator) {
1555 *data = flag_separator;
1556 }
1557 } while (*data++);
1558
1559 std::istringstream iss{subexpression};
1560 std::vector<std::string> targs;
1561 std::string targ;
1562 while (std::getline(iss, targ, flag_separator)) {
1563 targs.emplace_back(targ);
1564 }
1565
1566 if (targs.size() < 2) {
1567 throw std::runtime_error(
1568 "CONCAT operator must have at least two children, as CONCAT($0, "
1569 "$1) .");
1570 }
1571
1572 std::ostringstream oss;
1573 std::size_t n_calls = targs.size() - 1;
1574 while (n_calls--) {
1575 oss << operator_name << '(';
1576 }
1577
1578 std::vector<std::string>::const_iterator tbegin = targs.cbegin();
1579 std::vector<std::string>::const_iterator tend = targs.cend();
1580 oss << *tbegin;
1581 while (++tbegin != tend) {
1582 oss << arg_separator << *tbegin << ')';
1583 }
1584
1585 return oss.str();
1586}
1587
1588// Used by `convert_internals_nary_concat_to_nested_binary_concat` to expand an n-ary function calls to multiple binary calls.
1589static inline std::string

Callers 1

nary_to_nestedbinaryFunction · 0.85

Calls 2

sizeMethod · 0.80
dataMethod · 0.45

Tested by

no test coverage detected