Database Reference
In-Depth Information
Table 6.2 Create and Write Dispositions
Create Disposition
CREATE_IF_NEEDED Creates the table if it does not exist
CREATE_NEVER
Fails if the table does not already exist
Write Disposition
WRITE_EMPTY
Fails if the table is not empty
Replaces any existing contents with the new data
WRITE_TRUNCATE
Adds the new data to the existing data
WRITE_APPEND
You could argue that actually all that is required is WRITE_APPEND because
manually deleting and re-creating the table as required could simulate all
the other modes. However, these properties are useful when there are
concurrent query jobs and load jobs operating on the same table. It allows
for well-defined behavior without additional coordination at the application
level to ensure that a query job is not run while a table is being deleted and
re-created. A simple example is a daily job that creates a table containing
data for the previous day. By using the WRITE_EMPTY write disposition, you
can guarantee that the data will be loaded exactly once, even if for some
reason your daily loading script is invoked twice. Because both instances
of the script will be writing to the same table with the WRITE_EMPTY
disposition, only one of them will be allowed to succeed and actually add
data to the table. If WRITE_APPEND were the only supported mode, it is
possible that the data could be duplicated unless care was taken in the
script to ensure that a second attempt did not run unless it was certain that
the first attempt failed prior to initiating the load job. Because concurrent
updates and queries are common, the API supports these modes to ensure
that table modifications happen in a predictable fashion.
When the job API was described in Chapter 5, you saw that specifying an
ID when inserting a job was optional. If no ID is specified as part of the
job insert, the server assigns a random unique ID. For query jobs that are
not modifying an existing table, it is reasonable to rely on this automatic
assignment. However, when working with load jobs that modify the
contents of a table it is important for the client to select an ID, so we are
going to revisit that discussion.
 
Search WWH ::




Custom Search