|
1 | 1 | from collections import OrderedDict |
2 | 2 | from typing import Optional |
3 | 3 |
|
4 | | -import flightsql.flightsql_pb2 as flightsql_pb |
5 | 4 | import pandas |
6 | 5 | import pyarrow as pa |
7 | 6 | import pyarrow.flight as flight |
8 | 7 | from flightsql import FlightSQLClient |
9 | 8 | from flightsql.client import PreparedStatement |
10 | | -from google.protobuf import any_pb2 |
11 | 9 |
|
12 | 10 |
|
13 | 11 | class ClientConfig: |
@@ -118,37 +116,7 @@ def execute_prepared( |
118 | 116 | Binds the `binding` record batch with the prepared statement and requests the server to execute the statement. |
119 | 117 | """ |
120 | 118 |
|
121 | | - #! Since the flightsql-dbapi library misses setting options for do_put, we have to manually pass in the options. |
122 | | - #! We have filed a pull request to fix this issue. When the PR is merged and a new release of the flightsql-dbapi library is published, |
123 | | - #! the codes could be simplified to: |
124 | | - #! |
125 | | - #! ``` Python |
126 | | - #! flight_info = prepared_stmt.execute(binding) |
127 | | - #! ticket = flight_info.endpoints[0].ticket |
128 | | - #! reader = self.inner.do_get(ticket) |
129 | | - #! df = reader.read_pandas() |
130 | | - #! return df |
131 | | - #! ``` |
132 | | - |
133 | | - # Creates a flight descriptor from the command. |
134 | | - cmd = flightsql_pb.CommandPreparedStatementQuery( |
135 | | - prepared_statement_handle=prepared_stmt.handle |
136 | | - ) |
137 | | - any = any_pb2.Any() |
138 | | - any.Pack(cmd) |
139 | | - desc = flight.FlightDescriptor.for_command(any.SerializeToString()) |
140 | | - |
141 | | - # Writes the binding to the Datalayers server through the do_put interface. |
142 | | - if binding is not None and binding.num_rows > 0: |
143 | | - writer, reader = self.inner.client.do_put( |
144 | | - desc, binding.schema, prepared_stmt.options |
145 | | - ) |
146 | | - writer.write(binding) |
147 | | - writer.done_writing() |
148 | | - reader.read() |
149 | | - |
150 | | - # Executes the prepared statement and retrieves the execution result. |
151 | | - flight_info = self.inner.client.get_flight_info(desc, prepared_stmt.options) |
| 119 | + flight_info = prepared_stmt.execute(binding) |
152 | 120 | ticket = flight_info.endpoints[0].ticket |
153 | 121 | reader = self.inner.do_get(ticket) |
154 | 122 | df = reader.read_pandas() |
|
0 commit comments