Skip to content

Commit cd94439

Browse files
rename execute and execute_update
1 parent 16f58a9 commit cd94439

7 files changed

Lines changed: 45 additions & 42 deletions

File tree

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ from altertable_flightsql import Client
1919
# Connect to Altertable
2020
with Client(username="your_username", password="your_password") as client:
2121
# Execute a query
22-
reader = client.execute("SELECT * FROM users WHERE age > 18")
22+
reader = client.query("SELECT * FROM users WHERE age > 18")
2323

2424
# Process results
2525
for batch in reader:
@@ -46,12 +46,12 @@ client = Client(
4646

4747
```python
4848
# Execute SELECT query
49-
reader = client.execute("SELECT * FROM users")
49+
reader = client.query("SELECT * FROM users")
5050
for batch in reader:
5151
print(batch.to_pandas())
5252

5353
# Execute INSERT/UPDATE/DELETE
54-
rows_affected = client.execute_update("INSERT INTO users (name) VALUES ('Alice')")
54+
rows_affected = client.execute("INSERT INTO users (name) VALUES ('Alice')")
5555
print(f"Affected {rows_affected} rows")
5656
```
5757

@@ -72,8 +72,8 @@ with client.prepare("SELECT * FROM users WHERE id = ?") as stmt:
7272
txn_id = client.begin_transaction()
7373

7474
try:
75-
client.execute_update("INSERT INTO users ...", transaction_id=txn_id)
76-
client.execute_update("UPDATE accounts ...", transaction_id=txn_id)
75+
client.execute("INSERT INTO users ...", transaction_id=txn_id)
76+
client.execute("UPDATE accounts ...", transaction_id=txn_id)
7777
client.commit_transaction(txn_id)
7878
except Exception:
7979
client.rollback_transaction(txn_id)

examples/client_usage.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def example_basic_query():
4141
**CONNECTION_SETTINGS,
4242
) as client:
4343
# Execute query
44-
reader = client.execute("SELECT * FROM users WHERE age > 18")
44+
reader = client.query("SELECT * FROM users WHERE age > 18")
4545

4646
# Read results
4747
for batch in reader:
@@ -62,16 +62,19 @@ def example_updates():
6262
password=ALTERTABLE_PASSWORD,
6363
**CONNECTION_SETTINGS,
6464
) as client:
65+
# Create table
66+
client.execute("CREATE TABLE users (id INT, name VARCHAR, age INT)")
67+
6568
# Insert
66-
rows = client.execute_update("INSERT INTO users (name, age) VALUES ('Alice', 25)")
69+
rows = client.execute("INSERT INTO users (name, age) VALUES ('Alice', 25)")
6770
print(f"Inserted {rows} rows")
6871

6972
# Update
70-
rows = client.execute_update("UPDATE users SET age = 26 WHERE name = 'Alice'")
73+
rows = client.execute("UPDATE users SET age = 26 WHERE name = 'Alice'")
7174
print(f"Updated {rows} rows")
7275

7376
# Delete
74-
rows = client.execute_update("DELETE FROM users WHERE name = 'Alice'")
77+
rows = client.execute("DELETE FROM users WHERE name = 'Alice'")
7578
print(f"Deleted {rows} rows")
7679

7780
print()
@@ -114,11 +117,11 @@ def example_transactions():
114117
# Begin transaction
115118
with client.begin_transaction():
116119
# Execute queries in transaction
117-
client.execute_update(
120+
client.execute(
118121
"INSERT INTO users (name, age) VALUES ('Bob', 30)",
119122
)
120123

121-
client.execute_update(
124+
client.execute(
122125
"INSERT INTO users (name, age) VALUES ('Carol', 28)",
123126
)
124127

@@ -163,8 +166,8 @@ def example_metadata():
163166

164167

165168
if __name__ == "__main__":
166-
example_basic_query()
167169
example_updates()
170+
example_basic_query()
168171
example_prepared_statement()
169172
example_transactions()
170173
example_metadata()

src/altertable_flightsql/client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class Client:
7070
7171
Example:
7272
>>> client = Client(username="user", password="pass")
73-
>>> result = client.execute("SELECT * FROM users")
73+
>>> result = client.query("SELECT * FROM users")
7474
>>> for batch in result:
7575
... print(batch.to_pandas())
7676
"""
@@ -162,7 +162,7 @@ def set_catalog(self, catalog: str):
162162
def set_schema(self, schema: str):
163163
self._set_options({"schema": sql_pb2.SessionOptionValue(string_value=schema)})
164164

165-
def execute(
165+
def query(
166166
self,
167167
query: str,
168168
*,
@@ -179,7 +179,7 @@ def execute(
179179
FlightStreamReader for reading query results.
180180
181181
Example:
182-
>>> reader = client.execute("SELECT * FROM users WHERE age > 18")
182+
>>> reader = client.query("SELECT * FROM users WHERE age > 18")
183183
>>> for batch in reader:
184184
... print(batch.to_pandas())
185185
"""
@@ -198,7 +198,7 @@ def execute(
198198

199199
return self._client.do_get(endpoint.ticket)
200200

201-
def execute_update(
201+
def execute(
202202
self,
203203
query: str,
204204
*,
@@ -215,7 +215,7 @@ def execute_update(
215215
Number of rows affected.
216216
217217
Example:
218-
>>> rows = client.execute_update("INSERT INTO users (name) VALUES ('Alice')")
218+
>>> rows = client.execute("INSERT INTO users (name) VALUES ('Alice')")
219219
>>> print(f"Inserted {rows} rows")
220220
"""
221221
# Create SQL update command

tests/conftest.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,13 @@ def test_catalog(altertable_client: Client) -> Generator[str, None, None]:
140140
catalog_name = f"test_catalog_{uuid.uuid4().hex[:8]}"
141141

142142
# Create catalog by attaching a memory database
143-
altertable_client.execute_update(f"ATTACH ':memory:' AS {catalog_name}")
143+
altertable_client.execute(f"ATTACH ':memory:' AS {catalog_name}")
144144

145145
yield catalog_name
146146

147147
# Cleanup: detach the catalog
148148
try:
149-
altertable_client.execute_update(f"DETACH {catalog_name}")
149+
altertable_client.execute(f"DETACH {catalog_name}")
150150
except Exception as e:
151151
# Ignore cleanup errors
152152
print(f"Warning: Failed to detach catalog {catalog_name}: {e}")
@@ -170,7 +170,7 @@ def test_schema(altertable_client: Client, test_catalog: str) -> Generator[Schem
170170
fully_qualified_schema = f"{test_catalog}.{schema_name}"
171171

172172
# Create schema in the test catalog
173-
altertable_client.execute_update(f"CREATE SCHEMA {fully_qualified_schema}")
173+
altertable_client.execute(f"CREATE SCHEMA {fully_qualified_schema}")
174174

175175
schema_info = SchemaInfo(
176176
catalog=test_catalog, schema=schema_name, full_name=fully_qualified_schema
@@ -180,7 +180,7 @@ def test_schema(altertable_client: Client, test_catalog: str) -> Generator[Schem
180180

181181
# Cleanup: drop the schema
182182
try:
183-
altertable_client.execute_update(f"DROP SCHEMA IF EXISTS {fully_qualified_schema} CASCADE")
183+
altertable_client.execute(f"DROP SCHEMA IF EXISTS {fully_qualified_schema} CASCADE")
184184
except Exception as e:
185185
# Ignore cleanup errors
186186
print(f"Warning: Failed to drop schema {fully_qualified_schema}: {e}")
@@ -207,11 +207,11 @@ def test_table(
207207
table_name = f"test_table_{uuid.uuid4().hex[:8]}"
208208
fully_qualified_table = f"{test_schema.full_name}.{table_name}"
209209

210-
altertable_client.execute_update(
210+
altertable_client.execute(
211211
f"CREATE TABLE {fully_qualified_table} (id INT, name VARCHAR, value INT)"
212212
)
213213

214-
altertable_client.execute_update(
214+
altertable_client.execute(
215215
f"INSERT INTO {fully_qualified_table} (id, name, value) VALUES (1, 'Alice', 100), (2, 'Bob', 200), (3, 'Charlie', 300)"
216216
)
217217

@@ -226,7 +226,7 @@ def test_table(
226226

227227
# Cleanup: drop the table
228228
try:
229-
altertable_client.execute_update(f"DROP TABLE IF EXISTS {fully_qualified_table}")
229+
altertable_client.execute(f"DROP TABLE IF EXISTS {fully_qualified_table}")
230230
except Exception as e:
231231
# Ignore cleanup errors
232232
print(f"Warning: Failed to drop table {fully_qualified_table}: {e}")

tests/test_metadata.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,16 @@ def test_set_catalog(self, altertable_client: Client):
128128
query = "SELECT current_catalog() AS current_catalog"
129129

130130
current_catalog = (
131-
altertable_client.execute(query).read_all().to_pandas()["current_catalog"][0]
131+
altertable_client.query(query).read_all().to_pandas()["current_catalog"][0]
132132
)
133133
assert current_catalog != catalog_name
134134

135-
altertable_client.execute_update(f"ATTACH ':memory:' AS {catalog_name}")
135+
altertable_client.execute(f"ATTACH ':memory:' AS {catalog_name}")
136136

137137
altertable_client.set_catalog(catalog_name)
138138

139139
current_catalog = (
140-
altertable_client.execute(query).read_all().to_pandas()["current_catalog"][0]
140+
altertable_client.query(query).read_all().to_pandas()["current_catalog"][0]
141141
)
142142
assert current_catalog == catalog_name
143143

@@ -146,15 +146,15 @@ def test_set_schema(self, altertable_client: Client):
146146
schema_name = f"test_schema_{uuid.uuid4().hex[:8]}"
147147
query = "SELECT current_schema() AS current_schema"
148148

149-
altertable_client.execute_update(f"CREATE SCHEMA {schema_name}")
149+
altertable_client.execute(f"CREATE SCHEMA {schema_name}")
150150

151151
current_schema = (
152-
altertable_client.execute(query).read_all().to_pandas()["current_schema"][0]
152+
altertable_client.query(query).read_all().to_pandas()["current_schema"][0]
153153
)
154154
assert current_schema != schema_name
155155

156156
altertable_client.set_schema(schema_name)
157157
current_schema = (
158-
altertable_client.execute(query).read_all().to_pandas()["current_schema"][0]
158+
altertable_client.query(query).read_all().to_pandas()["current_schema"][0]
159159
)
160160
assert current_schema == schema_name

tests/test_queries.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class TestBasicQueries:
1515

1616
def test_simple_select(self, altertable_client: Client):
1717
"""Test executing a simple SELECT query."""
18-
reader = altertable_client.execute("SELECT 1 AS value")
18+
reader = altertable_client.query("SELECT 1 AS value")
1919

2020
# Check the result
2121
df = reader.read_pandas()
@@ -25,7 +25,7 @@ def test_simple_select(self, altertable_client: Client):
2525
def test_select_multiple_columns(self, altertable_client: Client):
2626
"""Test SELECT with multiple columns."""
2727
query = "SELECT 1 AS col1, 'test' AS col2, 3.14 AS col3"
28-
reader = altertable_client.execute(query)
28+
reader = altertable_client.query(query)
2929

3030
df = reader.read_pandas()
3131
assert df["col1"].iloc[0] == 1
@@ -35,7 +35,7 @@ def test_select_multiple_columns(self, altertable_client: Client):
3535
def test_select_with_filter(self, altertable_client: Client, test_table: TableInfo):
3636
"""Test SELECT with WHERE clause."""
3737
# Query with filter
38-
reader = altertable_client.execute(
38+
reader = altertable_client.query(
3939
f"SELECT * FROM {test_table.full_name} WHERE value >= 200"
4040
)
4141

@@ -46,7 +46,7 @@ def test_select_with_filter(self, altertable_client: Client, test_table: TableIn
4646
def test_empty_result_set(self, altertable_client: Client, test_table: TableInfo):
4747
"""Test query that returns no rows."""
4848
# Query empty table
49-
reader = altertable_client.execute(
49+
reader = altertable_client.query(
5050
f"SELECT * FROM {test_table.full_name} WHERE value > 1000"
5151
)
5252
table = reader.read_all()
@@ -78,20 +78,20 @@ class TestErrorHandling:
7878
def test_invalid_sql_syntax(self, altertable_client: Client):
7979
"""Test handling of invalid SQL syntax."""
8080
with pytest.raises(Exception):
81-
reader = altertable_client.execute("INVALID SQL SYNTAX")
81+
reader = altertable_client.query("INVALID SQL SYNTAX")
8282
list(reader)
8383

8484
def test_nonexistent_table(self, altertable_client: Client):
8585
"""Test querying a non-existent table."""
8686
with pytest.raises(Exception):
87-
reader = altertable_client.execute("SELECT * FROM nonexistent_table_12345")
87+
reader = altertable_client.query("SELECT * FROM nonexistent_table_12345")
8888
list(reader)
8989

9090
def test_invalid_column_name(self, altertable_client: Client, test_table: TableInfo):
9191
"""Test querying with invalid column name."""
9292
# Query with invalid column
9393
with pytest.raises(Exception):
94-
reader = altertable_client.execute(
94+
reader = altertable_client.query(
9595
f"SELECT nonexistent_column FROM {test_table.full_name}"
9696
)
9797
list(reader)

tests/test_transactions.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ class TestBasicTransactions:
1414
def test_commit_transaction(self, altertable_client: Client, test_table: TableInfo):
1515
"""Test committing a transaction."""
1616
with altertable_client.begin_transaction():
17-
altertable_client.execute_update(
17+
altertable_client.execute(
1818
f"INSERT INTO {test_table.full_name} (id, name, value) VALUES (999, 'Robert', 600)",
1919
)
2020

2121
# Verify data was committed
22-
reader = altertable_client.execute(
22+
reader = altertable_client.query(
2323
f"SELECT name FROM {test_table.full_name} WHERE id = 999"
2424
)
2525
df = reader.read_pandas()
@@ -29,11 +29,11 @@ def test_commit_transaction(self, altertable_client: Client, test_table: TableIn
2929
def test_rollback_transaction(self, altertable_client: Client, test_table: TableInfo):
3030
"""Test rolling back a transaction."""
3131
with altertable_client.begin_transaction() as txn:
32-
altertable_client.execute_update(
32+
altertable_client.execute(
3333
f"INSERT INTO {test_table.full_name} (id, name, value) VALUES (999, 'Robert', 600)",
3434
)
3535

36-
reader = altertable_client.execute(
36+
reader = altertable_client.query(
3737
f"SELECT name FROM {test_table.full_name} WHERE id = 999"
3838
)
3939
df = reader.read_pandas()
@@ -43,6 +43,6 @@ def test_rollback_transaction(self, altertable_client: Client, test_table: Table
4343
txn.rollback()
4444

4545
# Verify data was not committed
46-
reader = altertable_client.execute(f"SELECT * FROM {test_table.full_name} WHERE id = 999")
46+
reader = altertable_client.query(f"SELECT * FROM {test_table.full_name} WHERE id = 999")
4747
df = reader.read_pandas()
4848
assert len(df) == 0

0 commit comments

Comments
 (0)