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;")
| 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 | '''Rewrite the input sql query |
| 137 | ''' |
| 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 |
nothing calls this directly
no outgoing calls
no test coverage detected