MCPcopy Create free account
hub / github.com/OpenBMB/BMTools / rewrite_sql

Function rewrite_sql

bmtools/tools/database/api.py:135–152  ·  view source on GitHub ↗

Rewrite the input sql query

(sql: str="select distinct l_orderkey, sum(l_extendedprice + 3 + (1 - l_discount)) as revenue, o_orderkey, o_shippriority from customer, orders, lineitem where c_mktsegment = 'BUILDING' and c_custkey = o_custkey and l_orderkey = o_orderkey and o_orderdate < date '1995-03-15' and l_shipdate > date '1995-03-15' group by l_orderkey, o_orderkey, o_shippriority order by revenue desc, o_orderkey;")

Source from the content-addressed store, hash-verified

133
134 @tool.get("/rewrite_sql")
135 def rewrite_sql(sql: str="select distinct l_orderkey, sum(l_extendedprice + 3 + (1 - l_discount)) as revenue, o_orderkey, o_shippriority from customer, orders, lineitem where c_mktsegment = 'BUILDING' and c_custkey = o_custkey and l_orderkey = o_orderkey and o_orderdate < date '1995-03-15' and l_shipdate > date '1995-03-15' group by l_orderkey, o_orderkey, o_shippriority order by revenue desc, o_orderkey;"):
136 ''&#x27;Rewrite the input sql query
137 ''&#x27;
138
139 param = {
140 "sql": sql
141 }
142 print("Rewriter param:", param)
143 headers = {'Content-Type': 'application/json'}
144 res_completion = requests.post(URL_REWRITE, data=json.dumps(param), headers=headers)
145
146 #print("============ res_completion", res_completion.text)
147
148 data = json.loads(res_completion.text.strip())
149 data = data.get('data')
150 text_output = f"Rewritten sql is:\n"+data.get('rewritten_sql')
151
152 return text_output
153
154 return tool

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected