Skip to content

Commit 2e6331e

Browse files
authored
Update DataFrame expamle (#59)
1 parent c19c0e0 commit 2e6331e

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

example/pandas/dataframe.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,32 @@
3838
print(df)
3939
print(df.describe())
4040

41+
# Also you can use proton settings in DataFrame API like using `execute` function. # noqa
42+
# Here's an example with idempotent id.
43+
44+
# Reset stream
45+
c.execute('drop stream if exists test')
46+
c.execute(
47+
"""create stream test (
48+
year int16,
49+
first_name string
50+
)"""
51+
)
52+
settings = dict(use_numpy=True, idempotent_id='batch')
53+
54+
# Execute multiple insert operations.
55+
for _ in range(5):
56+
c.insert_dataframe(
57+
'INSERT INTO "test" (year, first_name) VALUES',
58+
df,
59+
settings=settings,
60+
)
61+
time.sleep(3)
62+
63+
rv = c.execute('SELECT COUNT(*) FROM table(test)')
64+
# Only the first times insert into the historical storage.
65+
print(rv) # (4,)
66+
4167
# Converting query results to a variety of formats with dbapi
4268
with connect('proton://localhost') as conn:
4369
with conn.cursor() as cur:

0 commit comments

Comments
 (0)