def _convert_template_query_info_with_gsi(self, file_path, gsi_index_file_path=None, table_map={}, table_name="simple_table", define_gsi_index=True, gen_expected_result=False): helper = RQGQueryHelper() f = open(gsi_index_file_path, 'w') n1ql_queries = self._read_from_file(file_path) for n1ql_query in n1ql_queries: check = True if not helper._check_deeper_query_condition(n1ql_query): if "SUBQUERY" in n1ql_query: map = helper._convert_sql_template_to_value_with_subqueries(n1ql_query, table_map=table_map, define_gsi_index=define_gsi_index) else: map=helper._convert_sql_template_to_value_for_secondary_indexes(n1ql_query, table_map=table_map, table_name=table_name, define_gsi_index=define_gsi_index) else: map=helper._convert_sql_template_to_value_for_secondary_indexes_sub_queries(n1ql_query, table_map=table_map, table_name=table_name, define_gsi_index=define_gsi_index) if gen_expected_result: query = map["sql"] try: sql_result = self._query_and_convert_to_json(query) map["expected_result"] = sql_result except Exception, ex: print ex check = False if check: f.write(json.dumps(map)+"\n")
def _gen_data_simple_table(self, number_of_rows=1000): helper = RQGQueryHelper() map = self._get_pkey_map_for_tables_wit_primary_key_column() for table_name in map.keys(): for x in range(0, number_of_rows): statement = helper._generate_insert_statement(table_name, map[table_name], "\"" + str(x + 1) + "\"") self._insert_execute_query(statement)
def _convert_delete_template_query_info_with_merge(self, source_table="copy_simple_table", target_table="simple_table" ,n1ql_queries=[], table_map={}): helper = RQGQueryHelper() query_input_list = [] for n1ql_query in n1ql_queries: query_input_list.append(helper._delete_sql_template_to_values_with_merge(source_table=source_table, target_table=target_table, sql=n1ql_query, table_map=table_map)) return query_input_list
def _gen_queries_from_template(self, query_path="./queries.txt", table_name=None): helper = RQGQueryHelper() map = self._get_values_with_type_for_fields_in_table() table_map = map[table_name] with open(query_path) as f: content = f.readlines() for query in content: helper._convert_sql_template_to_value(sql=query, table_map=table_map, table_name=table_name)
def _convert_delete_template_query_info(self, n1ql_queries=[], table_map={}): helper = RQGQueryHelper() query_input_list = [] for n1ql_query in n1ql_queries: query_input_list.append( helper._delete_sql_template_to_values(sql=n1ql_query, table_map=table_map)) return query_input_list
def _convert_template_query_info(self, n1ql_queries=[], table_map={}, define_gsi_index=True, gen_expected_result=False, ansi_joins=False, aggregate_pushdown=False, partitioned_indexes=False, with_let=False): helper = RQGQueryHelper() query_input_list = [] for n1ql_query in n1ql_queries: # check if ["UNION ALL", "INTERSECT ALL", "EXCEPT ALL", "UNION", "INTERSECT", "EXCEPT"] not in query if not helper._check_deeper_query_condition(n1ql_query): if "SUBTABLE" in n1ql_query: sql_n1ql_index_map = helper._convert_sql_template_to_value_with_subqueryenhancements( n1ql_query, table_map=table_map, define_gsi_index=define_gsi_index) elif "SUBQUERY" in n1ql_query: sql_n1ql_index_map = helper._convert_sql_template_to_value_with_subqueries( n1ql_query, table_map=table_map, define_gsi_index=define_gsi_index) else: # takes in sql and n1ql queries and create indexes for them sql_n1ql_index_map = helper._convert_sql_template_to_value_for_secondary_indexes( n1ql_query, table_map=table_map, define_gsi_index=define_gsi_index, ansi_joins=ansi_joins, aggregate_pushdown=aggregate_pushdown, partitioned_indexes=partitioned_indexes, with_let=with_let) else: sql_n1ql_index_map = helper._convert_sql_template_to_value_for_secondary_indexes_sub_queries( n1ql_query, table_map=table_map, define_gsi_index=define_gsi_index, partitioned_indexes=partitioned_indexes) if gen_expected_result: sql_query = sql_n1ql_index_map["sql"] try: sql_result = self._query_and_convert_to_json(sql_query) sql_n1ql_index_map["expected_result"] = sql_result except Exception as ex: print(ex) sql_n1ql_index_map = self._translate_function_names( sql_n1ql_index_map) query_input_list.append(sql_n1ql_index_map) return query_input_list