Skip to content

Commit 07fa52b

Browse files
rename PreparedStatement.execute
1 parent cd94439 commit 07fa52b

4 files changed

Lines changed: 18 additions & 16 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ print(f"Affected {rows_affected} rows")
6060
```python
6161
# Prepare once, execute multiple times
6262
with client.prepare("SELECT * FROM users WHERE id = ?") as stmt:
63-
result = stmt.execute()
63+
result = stmt.query()
6464
for batch in result:
6565
print(batch.to_pandas())
6666
```

examples/client_usage.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
ALTERTABLE_PORT = int(os.getenv("ALTERTABLE_PORT", "443"))
1515
ALTERTABLE_USERNAME = os.getenv("ALTERTABLE_USERNAME")
1616
ALTERTABLE_PASSWORD = os.getenv("ALTERTABLE_PASSWORD")
17-
ALTERTABLE_CATALOG = os.getenv("ALTERTABLE_CATALOG")
18-
ALTERTABLE_SCHEMA = os.getenv("ALTERTABLE_SCHEMA")
17+
ALTERTABLE_CATALOG = os.getenv("ALTERTABLE_CATALOG", "memory")
18+
ALTERTABLE_SCHEMA = os.getenv("ALTERTABLE_SCHEMA", "main")
1919
ALTERTABLE_TLS = os.getenv("ALTERTABLE_TLS", "true").lower() == "true"
2020

2121
CONNECTION_SETTINGS = {
@@ -45,7 +45,7 @@ def example_basic_query():
4545

4646
# Read results
4747
for batch in reader:
48-
df = batch.data().to_pandas()
48+
df = batch.data.to_pandas()
4949
print(df)
5050

5151
print()
@@ -63,7 +63,7 @@ def example_updates():
6363
**CONNECTION_SETTINGS,
6464
) as client:
6565
# Create table
66-
client.execute("CREATE TABLE users (id INT, name VARCHAR, age INT)")
66+
client.execute("CREATE TABLE IF NOT EXISTS users (id INT PRIMARY KEY, name VARCHAR, age INT)")
6767

6868
# Insert
6969
rows = client.execute("INSERT INTO users (name, age) VALUES ('Alice', 25)")
@@ -96,9 +96,9 @@ def example_prepared_statement():
9696
# Execute with different parameters
9797
for user_id in [1, 2, 3]:
9898
print(f"Fetching user {user_id}...")
99-
reader = stmt.execute(parameters={"id": user_id})
99+
reader = stmt.query(parameters={"id": user_id})
100100
for batch in reader:
101-
print(batch.data().to_pandas())
101+
print(batch.data.to_pandas())
102102

103103
print()
104104

@@ -146,21 +146,23 @@ def example_metadata():
146146
print("Catalogs:")
147147
reader = client.get_catalogs()
148148
for batch in reader:
149-
print(batch.to_pandas())
149+
print(batch.data.to_pandas())
150150

151151
# Get schemas
152152
print("\nSchemas:")
153-
reader = client.get_schemas(catalog="altertable")
153+
reader = client.get_schemas(catalog=ALTERTABLE_CATALOG)
154154
for batch in reader:
155-
print(batch.to_pandas())
155+
print(batch.data.to_pandas())
156156

157157
# Get tables
158158
print("\nTables:")
159159
reader = client.get_tables(
160-
catalog="altertable", schema_pattern="main", table_pattern="user%"
160+
catalog=ALTERTABLE_CATALOG,
161+
schema_pattern=ALTERTABLE_SCHEMA,
162+
table_pattern="user%"
161163
)
162164
for batch in reader:
163-
print(batch.to_pandas())
165+
print(batch.data.to_pandas())
164166

165167
print()
166168

src/altertable_flightsql/client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ def prepare(
257257
258258
Example:
259259
>>> stmt = client.prepare("SELECT * FROM users WHERE id = ?")
260-
>>> result = stmt.execute(parameters=[42])
260+
>>> result = stmt.query(parameters={"id": 42})
261261
"""
262262
# Create prepared statement request
263263
request = sql_pb2.ActionCreatePreparedStatementRequest(query=query)
@@ -456,13 +456,13 @@ def __init__(self, client: flight.FlightClient, handle: bytes):
456456
self._client = client
457457
self._handle = handle
458458

459-
def execute(
459+
def query(
460460
self,
461461
*,
462462
parameters: Optional[Mapping[str, Any]] = None,
463463
) -> flight.FlightStreamReader:
464464
"""
465-
Execute the prepared statement.
465+
Execute the prepared statement query.
466466
467467
Args:
468468
parameters: Optional RecordBatch containing parameter values.

tests/test_queries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def test_prepare_and_execute(self, altertable_client: Client, test_table: TableI
6767
f"SELECT * FROM {test_table.full_name} WHERE id = $id"
6868
) as stmt:
6969
# Execute prepared statement
70-
reader = stmt.execute(parameters={"id": 1})
70+
reader = stmt.query(parameters={"id": 1})
7171
table = reader.read_all()
7272
assert table.num_rows > 0
7373

0 commit comments

Comments
 (0)