primeqa.qg.models.table_qg.sql_sampler.SimpleSqlSampler#

class primeqa.qg.models.table_qg.sql_sampler.SimpleSqlSampler#

Bases: object

A simple sql sampler to sample sqls based on number of where clause conditions and other parameters

Methods

add_column_types

Adds a data type list to the table dict based on values in the cells in that column.

controlled_sample_sql

convert_sql_to_string

Convert sql query in Dict format to string

get_where_clauses

readable_sql

Convert Non-readable SQL to readable SQL dict

sample_sql

This function samples sqls from a given table based on values for the parameters num_sample -> number of sql queries to sample, num_where -> number of where condtioned desired in every sampled sql Query etc.

sql_execution

This function executes the sql on a given table and returns the answer.

static add_column_types(table)#

Adds a data type list to the table dict based on values in the cells in that column. The data type for a column is either real or text. :param table: [The table Dict containing headers and rows] :type table: [dict]

Returns

[Table Dict with key ‘type’ containing list of data type for every column]

Return type

[Dict]

convert_sql_to_string(sql_dict, table=[], tokenizer='T5')#

Convert sql query in Dict format to string

Parameters
  • sql_dict ([Dict]) – [Sql Query to convert to string]

  • table (list, optional) – [Table]. Defaults to [].

  • tokenizer (str, optional) – [description]. Defaults to ‘T5’.

Returns

[Sql query in string format]

Return type

[String]

readable_sql(sql, header, answer)#

Convert Non-readable SQL to readable SQL dict

Parameters
  • sql ([Dict]) – [Sql query]

  • header ([List]) – [Headers in table]

  • answer ([String]) – [Answer]

Returns

[Sql Dict in readable format]

Return type

[Dict]

sample_sql(table, num_sample, num_where, agg_op=0, if_ineq=False)#

This function samples sqls from a given table based on values for the parameters num_sample -> number of sql queries to sample, num_where -> number of where condtioned desired in every sampled sql Query etc. :param table: [Table dictionary with header and rows] :type table: [Dict] :param num_sample: [Number of sqls to sample] :type num_sample: [int] :param num_where: [Number of where clause conditions every sampled sql should have] :type num_where: [int] :param agg_op: [Whether to sample aggregate queries or not]. Defaults to 0. :type agg_op: int, optional :param if_ineq: [description]. Defaults to False. :type if_ineq: bool, optional

Returns

[Sampled sql query list in readable string format and dict format]

Return type

[List,Dict]

sql_execution(where_clause, select_column, agg_op, table)#

This function executes the sql on a given table and returns the answer.

Parameters
  • where_clause ([type]) – [description]

  • select_column ([type]) – [description]

  • agg_op ([type]) – [description]

  • table ([type]) – [description]

Returns

[Answer after executing sql on the given table]

Return type

[String]