MCPcopy Create free account
hub / github.com/PaddlePaddle/Research / sql2query

Function sql2query

NLP/Text2SQL-BASELINE/tools/evaluation/utils.py:187–210  ·  view source on GitHub ↗

transform sql json to sql query, this is only for NL2SQL, eg. select a, b where a op val1

(sql, cols)

Source from the content-addressed store, hash-verified

185 return tokens
186
187def sql2query(sql, cols):
188 """
189 transform sql json to sql query, this is only for NL2SQL, eg. select a, b where a op val1
190 """
191
192 sels = sql['sel']
193 aggs = sql['agg']
194 op = sql["cond_conn_op"]
195 conds = sql["conds"]
196
197 condstrs = [f'{cols[cond[0]]} {op_sql_dict[cond[1]]} "{cond[2]}"'
198 for cond in conds]
199 cond_str = f" {conn_sql_dict[op]} ".join(condstrs)
200
201 def agg_col(agg, col):
202 if agg == 0:
203 return cols[col]
204 else:
205 return f"{agg_sql_dict[agg]} ( {cols[col]} )"
206
207 selstrs = [agg_col(i,j) for i,j in zip(aggs, sels)]
208 sel_str = ' , '.join(selstrs)
209
210 return f"SELECT {sel_str} WHERE {cond_str}"
211
212def query2sql(query, cols, single_equal=False, with_value=True):
213

Callers

nothing calls this directly

Calls 1

agg_colFunction · 0.85

Tested by

no test coverage detected