def execute_python(src_table_path, rb_script_path, encoding, input_delim, input_policy, out_delim, out_policy, dst_table_path): query = codecs.open(rb_script_path, encoding=encoding).read() warnings = [] try: rbql.query_csv(query, src_table_path, input_delim, input_policy, dst_table_path, out_delim, out_policy, encoding, warnings) warning_report = '\n'.join(warnings) vim_interface.set_vim_variable('psv_warning_report', warning_report) vim_interface.set_vim_variable('psv_query_status', 'OK') except Exception as e: error_type, error_msg = rbql.exception_to_error_info(e) vim_interface.report_error_to_vim(error_type, error_msg)
def main(): parser = argparse.ArgumentParser() parser.add_argument('query', help='Query string') parser.add_argument('input_table_path', metavar='FILE', help='input path') parser.add_argument('delim', help='Delimiter') parser.add_argument('policy', help='csv split policy') parser.add_argument('output_table_path', metavar='FILE', help='output path') parser.add_argument('output_delim', help='Out Delimiter') parser.add_argument('output_policy', help='Out csv policy') parser.add_argument('encoding', help='encoding') parser.add_argument('--skip_headers', action='store_true', help='skip headers') args = parser.parse_args() delim = args.delim policy = args.policy output_delim = args.output_delim output_policy = args.output_policy query = base64.standard_b64decode(args.query).decode("utf-8") input_path = args.input_table_path csv_encoding = args.encoding output_path = args.output_table_path skip_headers = args.skip_headers try: warnings = [] rbql.query_csv(query, input_path, delim, policy, output_path, output_delim, output_policy, csv_encoding, warnings, skip_headers) sys.stdout.write(json.dumps({'warnings': warnings})) except Exception as e: error_type, error_msg = rbql.exception_to_error_info(e) sys.stdout.write( json.dumps({ 'error_type': error_type, 'error_msg': error_msg }))
import rbql user_query = 'SELECT a1, int(a2) % 1000 WHERE a3 != "USA" LIMIT 5' warnings = [] rbql.query_csv(user_query, 'input.csv', ',', 'quoted', 'output.csv', ',', 'quoted', 'utf-8', warnings) print(open('output.csv').read())