Repository navigation
Add Appender API - #661
Merged
Merged
Add Appender API#661
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add an appender to the Python client
Python has had no appender. This uses the same pieces as the stable C++ API's
Appender: a buffer of rows and one statement that reads it.There are two ways to create one. The table form writes the statement for you:
The query form runs your own INSERT, UPDATE, DELETE or MERGE INTO. An optional source query can reshape the rows first:
Both forms also exist as module-level functions that take
connection=.How it behaves:
memory_limitand spills to the temp directory. Appending runs no statement and never takes the connection, so it works while a result is open.WITH appender_buffer AS (...), appender_data AS (<source>) <dml>, over the rows appended since the last flush. It commits on its own or joins the transaction you opened. An empty flush runs nothing.ResourceWarning. Awithblock flushes on a normal exit and clears on an exception. There is noclose().executemanyparameters do, so JSON is validated and timestamps follow the session time zone.test_appender_values.pychecks this againstexecutemanyfor about 100 Python values into 48 column types, errors included.sourceordmlare looked up once, at creation, and reused at every flush. Tables resolve at each flush, as in any statement.preserve_insertion_orderand still runs in parallel. Upserts don't keep append order, because the engine runs them as a MERGE.A few engine quirks are handled here so users don't see them:
INSERT OR REPLACEinto a table calledexcludedfails to bind, so the target table is aliased.What it doesn't do:
con.append(df)andINSERT ... SELECT * FROM dfalready cover that without a copy.con.append(df)stays the faster path.tests/fast/api/test_appender.pyhas one class per area: the table form, the actions, the query form, statement kinds, checks at creation, rows, flushes, flush failures, the buffer, garbage collection, thewithblock, threads, and closed connections. ASan, UBSan and LSan runs are clean.