Skip to content

Commit 27fbc94

Browse files
authored
chore: simplify python examples (#1)
1 parent a00c584 commit 27fbc94

File tree

2 files changed

+2
-37
lines changed

2 files changed

+2
-37
lines changed

python/client.py

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
from collections import OrderedDict
22
from typing import Optional
33

4-
import flightsql.flightsql_pb2 as flightsql_pb
54
import pandas
65
import pyarrow as pa
76
import pyarrow.flight as flight
87
from flightsql import FlightSQLClient
98
from flightsql.client import PreparedStatement
10-
from google.protobuf import any_pb2
119

1210

1311
class ClientConfig:
@@ -118,37 +116,7 @@ def execute_prepared(
118116
Binds the `binding` record batch with the prepared statement and requests the server to execute the statement.
119117
"""
120118

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)
152120
ticket = flight_info.endpoints[0].ticket
153121
reader = self.inner.do_get(ticket)
154122
df = reader.read_pandas()

python/requirements.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# This file is generated by pipreqs.
2-
# Note, the flightsql-dbapi cannot be resolved by pipreqs and it's added manually.
3-
flightsql-dbapi==0.2.1
1+
flightsql-dbapi==0.2.2
42
pandas==2.2.3
5-
protobuf==5.28.2
63
pyarrow==17.0.0

0 commit comments

Comments
 (0)