From d01e52e740d3372d3dd8b0a343ffaf8a9bbf946d Mon Sep 17 00:00:00 2001 From: Yibo-Chen13 Date: Mon, 4 Nov 2024 18:18:32 +0800 Subject: [PATCH] Update DataFrame expamle --- 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: