Skip to content

Commit

Permalink
merge from RBQL v0.16.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mechatroner committed Apr 11, 2020
1 parent 638e306 commit fa7331f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 37 deletions.
10 changes: 6 additions & 4 deletions rbql-js/rbql.js
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ module.exports.rb_transform = rb_transform;
// TODO replace prototypes with classes: this improves readability


const version = '0.16.0';
const version = '0.16.1';

const GROUP_BY = 'GROUP BY';
const UPDATE = 'UPDATE';
Expand Down Expand Up @@ -1358,16 +1358,18 @@ function cleanup_query(query_text) {
}


function remove_redundant_keyword_from(query_text) {
return str_strip(query_text.replace(/ +from +a(?: +|$)/gi, ' '));
function remove_redundant_table_name(query_text) {
query_text = str_strip(query_text.replace(/ +from +a(?: +|$)/gi, ' '));
query_text = str_strip(query_text.replace(/^ *update +a +set /gi, 'update '));
return query_text;
}


async function parse_to_js(query_text, js_template_text, input_iterator, join_tables_registry, user_init_code) {
user_init_code = indent_user_init_code(user_init_code);
query_text = cleanup_query(query_text);
var [format_expression, string_literals] = separate_string_literals_js(query_text);
format_expression = remove_redundant_keyword_from(format_expression);
format_expression = remove_redundant_table_name(format_expression);
var input_variables_map = await input_iterator.get_variables_map(query_text);

var rb_actions = separate_actions(format_expression);
Expand Down
1 change: 1 addition & 0 deletions rbql-js/rbql_csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -652,3 +652,4 @@ module.exports.read_user_init_code = read_user_init_code;
module.exports.query_csv = query_csv;
module.exports.set_debug_mode = set_debug_mode;
module.exports.RecordQueue = RecordQueue;
module.exports.exception_to_error_info = rbql.exception_to_error_info;
2 changes: 1 addition & 1 deletion rbql/_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Explanation of this file purpose: https://stackoverflow.com/a/16084844/2898283
__version__ = '0.16.0'
__version__ = '0.16.1'

68 changes: 36 additions & 32 deletions rbql/rbql_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,39 +768,41 @@ def select_unnested(sort_key, folded_fields):
stop_flag = True
'''


# We need dummy_wrapper_for_exec function in MAIN_LOOP_BODY because otherwise "import" statements won't work as expected, see: https://github.com/mechatroner/sublime_rainbow_csv/issues/22
MAIN_LOOP_BODY = '''
try:
pass
__USER_INIT_CODE__
except Exception as e:
raise RuntimeError('Exception while executing user-provided init code: {}'.format(e))
NR = 0
NU = 0
stop_flag = False
while not stop_flag:
record_a = query_context.input_iterator.get_record()
if record_a is None:
break
NR += 1
NF = len(record_a)
query_context.unnest_list = None # TODO optimize, don't need to set this every iteration
def dummy_wrapper_for_exec():
try:
__CODE__
except InternalBadKeyError as e:
raise RbqlRuntimeError('No "{}" field at record {}'.format(e.bad_key, NR)) # UT JSON
except InternalBadFieldError as e:
raise RbqlRuntimeError('No "a{}" field at record {}'.format(e.bad_idx + 1, NR)) # UT JSON
except RbqlParsingError:
raise
pass
__USER_INIT_CODE__
except Exception as e:
if debug_mode:
raise RuntimeError('Exception while executing user-provided init code: {}'.format(e))
NR = 0
NU = 0
stop_flag = False
while not stop_flag:
record_a = query_context.input_iterator.get_record()
if record_a is None:
break
NR += 1
NF = len(record_a)
query_context.unnest_list = None # TODO optimize, don't need to set this every iteration
try:
__CODE__
except InternalBadKeyError as e:
raise RbqlRuntimeError('No "{}" field at record {}'.format(e.bad_key, NR)) # UT JSON
except InternalBadFieldError as e:
raise RbqlRuntimeError('No "a{}" field at record {}'.format(e.bad_idx + 1, NR)) # UT JSON
except RbqlParsingError:
raise
if str(e).find('RBQLAggregationToken') != -1:
raise RbqlParsingError(wrong_aggregation_usage_error) # UT JSON
raise RbqlRuntimeError('At record ' + str(NR) + ', Details: ' + str(e)) # UT JSON
except Exception as e:
if debug_mode:
raise
if str(e).find('RBQLAggregationToken') != -1:
raise RbqlParsingError(wrong_aggregation_usage_error) # UT JSON
raise RbqlRuntimeError('At record ' + str(NR) + ', Details: ' + str(e)) # UT JSON
dummy_wrapper_for_exec()
'''


Expand Down Expand Up @@ -1316,14 +1318,16 @@ def cleanup_query(query_text):
return ' '.join(rbql_lines)


def remove_redundant_keyword_from(query_text):
return re.sub(' +from +a(?: +|$)', ' ', query_text, flags=re.IGNORECASE).strip()
def remove_redundant_input_table_name(query_text):
query_text = re.sub(' +from +a(?: +|$)', ' ', query_text, flags=re.IGNORECASE).strip()
query_text = re.sub('^ *update +a +set ', 'update ', query_text, flags=re.IGNORECASE).strip()
return query_text


def parse_to_py(query_text, input_iterator, join_tables_registry):
query_text = cleanup_query(query_text)
format_expression, string_literals = separate_string_literals_py(query_text)
format_expression = remove_redundant_keyword_from(format_expression)
format_expression = remove_redundant_input_table_name(format_expression)
input_variables_map = input_iterator.get_variables_map(query_text)

rb_actions = separate_actions(format_expression)
Expand Down

0 comments on commit fa7331f

Please sign in to comment.