From 2e6331ede4e8c409eba9e927df143fa3c47803b8 Mon Sep 17 00:00:00 2001 From: Yibo-Chen13 Date: Tue, 5 Nov 2024 09:11:57 +0800 Subject: [PATCH] Update DataFrame expamle (#59) --- example/pandas/dataframe.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/example/pandas/dataframe.py b/example/pandas/dataframe.py index 97d4f2c..61b0649 100644 --- a/example/pandas/dataframe.py +++ b/example/pandas/dataframe.py @@ -38,6 +38,32 @@ print(df) print(df.describe()) + # Also you can use proton settings in DataFrame API like using `execute` function. # noqa + # Here's an example with idempotent id. + + # Reset stream + c.execute('drop stream if exists test') + c.execute( + """create stream test ( + year int16, + first_name string + )""" + ) + settings = dict(use_numpy=True, idempotent_id='batch') + + # Execute multiple insert operations. + for _ in range(5): + c.insert_dataframe( + 'INSERT INTO "test" (year, first_name) VALUES', + df, + settings=settings, + ) + time.sleep(3) + + rv = c.execute('SELECT COUNT(*) FROM table(test)') + # Only the first times insert into the historical storage. + print(rv) # (4,) + # Converting query results to a variety of formats with dbapi with connect('proton://localhost') as conn: with conn.cursor() as cur: