Reference documentation and code samples for the BigQuery Client class LoadJobConfiguration.
Represents a configuration for a load job. For more information on the available settings please see the Jobs configuration API documentation.
Example:
use Google\Cloud\BigQuery\BigQueryClient;
$bigQuery = new BigQueryClient();
$table = $bigQuery->dataset('my_dataset')
->table('my_table');
$loadJobConfig = $table->load(fopen('/path/to/my/data.csv', 'r'));
Methods
__construct
Parameters | |
---|---|
Name | Description |
projectId |
string
The project's ID. |
config |
array
A set of configuration options for a job. |
location |
string|null
The geographic location in which the job is executed. |
allowJaggedRows
Sets whether to accept rows that are missing trailing optional columns.
The missing values are treated as nulls. If false, records with missing trailing columns are treated as bad records, and if there are too many bad records, an invalid error is returned in the job result. Only applicable to CSV, ignored for other formats.
Example:
$loadJobConfig->allowJaggedRows(true);
Parameter | |
---|---|
Name | Description |
allowJaggedRows |
bool
Whether or not to allow jagged rows.
Defaults to |
Returns | |
---|---|
Type | Description |
Google\Cloud\BigQuery\LoadJobConfiguration |
allowQuotedNewlines
Sets whether quoted data sections that contain newline characters in a CSV file are allowed.
Example:
$loadJobConfig->allowQuotedNewlines(true);
Parameter | |
---|---|
Name | Description |
allowQuotedNewlines |
bool
Whether or not to allow quoted new
lines. Defaults to |
Returns | |
---|---|
Type | Description |
Google\Cloud\BigQuery\LoadJobConfiguration |
autodetect
Sets whether we should automatically infer the options and schema for CSV and JSON sources.
Example:
$loadJobConfig->autodetect(true);
Parameter | |
---|---|
Name | Description |
autodetect |
bool
Whether or not to autodetect options and schema. |
Returns | |
---|---|
Type | Description |
Google\Cloud\BigQuery\LoadJobConfiguration |
clustering
Set the clustering specification for the table.
Refer to BigQuery documentation for a guide to clustered tables and constraints imposed by the service.
Example:
$loadJobConfig->clustering([
'fields' => [
'col1',
'col2'
]
]);
Parameter | |
---|---|
Name | Description |
clustering |
array
Clustering specification for the table. |
Returns | |
---|---|
Type | Description |
Google\Cloud\BigQuery\LoadJobConfiguration |
createDisposition
Set whether the job is allowed to create new tables. Creation, truncation and append actions occur as one atomic update upon job completion.
Example:
$loadJobConfig->createDisposition('CREATE_NEVER');
Parameter | |
---|---|
Name | Description |
createDisposition |
string
The create disposition. Acceptable
values include |
Returns | |
---|---|
Type | Description |
Google\Cloud\BigQuery\LoadJobConfiguration |
destinationEncryptionConfiguration
Sets the custom encryption configuration (e.g., Cloud KMS keys).
Example:
$loadJobConfig->destinationEncryptionConfiguration([
'kmsKeyName' => 'my_key'
]);
Parameter | |
---|---|
Name | Description |
configuration |
array
Custom encryption configuration. |
Returns | |
---|---|
Type | Description |
Google\Cloud\BigQuery\LoadJobConfiguration |
data
The data to be loaded into the table.
Example:
$loadJobConfig->data(fopen('/path/to/my/data.csv', 'r'));
Parameter | |
---|---|
Name | Description |
data |
string|resource|Psr\Http\Message\StreamInterface
The data to be loaded into the table. |
Returns | |
---|---|
Type | Description |
Google\Cloud\BigQuery\LoadJobConfiguration |
destinationTable
Sets the destination table to load the data into.
Example:
$table = $bigQuery->dataset('my_dataset')
->table('my_table');
$loadJobConfig->destinationTable($table);
Parameter | |
---|---|
Name | Description |
destinationTable |
Google\Cloud\BigQuery\Table
The destination table. |
Returns | |
---|---|
Type | Description |
Google\Cloud\BigQuery\LoadJobConfiguration |
encoding
Sets the character encoding of the data. BigQuery decodes the data after the raw, binary data has been split using the values of the quote and fieldDelimiter properties.
Example:
$loadJobConfig->encoding('UTF-8');
Parameter | |
---|---|
Name | Description |
encoding |
string
The encoding type. Acceptable values include
|
Returns | |
---|---|
Type | Description |
Google\Cloud\BigQuery\LoadJobConfiguration |
fieldDelimiter
Sets the separator for fields in a CSV file. The separator can be any ISO-8859-1 single-byte character. To use a character in the range 128-255, you must encode the character as UTF8. BigQuery converts the string to ISO-8859-1 encoding, and then uses the first byte of the encoded string to split the data in its raw, binary state. BigQuery also supports the escape sequence "\t" to specify a tab separator.
Example:
$loadJobConfig->fieldDelimiter('\t');
Parameter | |
---|---|
Name | Description |
fieldDelimiter |
string
The field delimiter. Defaults to |
Returns | |
---|---|
Type | Description |
Google\Cloud\BigQuery\LoadJobConfiguration |
ignoreUnknownValues
Sets whether values that are not represented in the table schema should be allowed. If true, the extra values are ignored. If false, records with extra columns are treated as bad records, and if there are too many bad records, an invalid error is returned in the job result.
The sourceFormat property determines what BigQuery treats as an extra value:
- CSV: Trailing columns.
- JSON: Named values that don't match any column names.
Example:
$loadJobConfig->ignoreUnknownValues(true);
Parameter | |
---|---|
Name | Description |
ignoreUnknownValues |
bool
Whether or not to ignore unknown values.
Defaults to |
Returns | |
---|---|
Type | Description |
Google\Cloud\BigQuery\LoadJobConfiguration |
maxBadRecords
Sets the maximum number of bad records that BigQuery can ignore when running the job. If the number of bad records exceeds this value, an invalid error is returned in the job result.
Example:
$loadJobConfig->maxBadRecords(10);
Parameter | |
---|---|
Name | Description |
maxBadRecords |
int
The maximum number of bad records.
Defaults to |
Returns | |
---|---|
Type | Description |
Google\Cloud\BigQuery\LoadJobConfiguration |
nullMarker
Sets a string that represents a null value in a CSV file. For example, if you specify "\N", BigQuery interprets "\N" as a null value when loading a CSV file. The default value is the empty string. If you set this property to a custom value, BigQuery throws an error if an empty string is present for all data types except for STRING and BYTE. For STRING and BYTE columns, BigQuery interprets the empty string as an empty value.
Example:
$loadJobConfig->nullMarker('\N');
Parameter | |
---|---|
Name | Description |
nullMarker |
string
The null marker. |
Returns | |
---|---|
Type | Description |
Google\Cloud\BigQuery\LoadJobConfiguration |
projectionFields
Sets a list of projection fields. If sourceFormat is set to "DATASTORE_BACKUP", indicates which entity properties to load into BigQuery from a Cloud Datastore backup. Property names are case sensitive and must be top-level properties. If no properties are specified, BigQuery loads all properties. If any named property isn't found in the Cloud Datastore backup, an invalid error is returned in the job result.
Example:
$loadJobConfig->projectionFields([
'field_name'
]);
Parameter | |
---|---|
Name | Description |
projectionFields |
array
The projection fields. |
Returns | |
---|---|
Type | Description |
Google\Cloud\BigQuery\LoadJobConfiguration |
quote
Sets the value that is used to quote data sections in a CSV file.
BigQuery converts the string to ISO-8859-1 encoding, and then uses the first byte of the encoded string to split the data in its raw, binary state. If your data does not contain quoted sections, set the property value to an empty string. If your data contains quoted newline characters, you must also set the allowQuotedNewlines property to true.
Example:
$loadJobConfig->quote('"');
Parameter | |
---|---|
Name | Description |
quote |
string
The quote value. Defaults to |
Returns | |
---|---|
Type | Description |
Google\Cloud\BigQuery\LoadJobConfiguration |
schema
Sets the schema for the destination table. The schema can be omitted if the destination table already exists, or if you're loading data from Google Cloud Datastore.
Example:
$loadJobConfig->schema([
'fields' => [
[
'name' => 'col1',
'type' => 'STRING',
],
[
'name' => 'col2',
'type' => 'BOOL',
]
]
]);
Parameter | |
---|---|
Name | Description |
schema |
array
The table schema. |
Returns | |
---|---|
Type | Description |
Google\Cloud\BigQuery\LoadJobConfiguration |
schemaUpdateOptions
Sets options to allow the schema of the destination table to be updated
as a side effect of the query job. Schema update options are supported
in two cases: when writeDisposition is "WRITE_APPEND"
; when
writeDisposition is "WRITE_TRUNCATE"
and the destination table is a
partition of a table, specified by partition decorators. For normal
tables, "WRITE_TRUNCATE"
will always overwrite the schema.
Example:
$loadJobConfig->schemaUpdateOptions([
'ALLOW_FIELD_ADDITION'
]);
Parameter | |
---|---|
Name | Description |
schemaUpdateOptions |
array
Schema update options. Acceptable
values include |
Returns | |
---|---|
Type | Description |
Google\Cloud\BigQuery\LoadJobConfiguration |
skipLeadingRows
Sets the number of rows at the top of a CSV file that BigQuery will skip when loading the data. This property is useful if you have header rows in the file that should be skipped.
Example:
$loadJobConfig->skipLeadingRows(10);
Parameter | |
---|---|
Name | Description |
skipLeadingRows |
int
The number of rows to skip.
Defaults to |
Returns | |
---|---|
Type | Description |
Google\Cloud\BigQuery\LoadJobConfiguration |
sourceFormat
Sets the format of the data files.
Example:
$loadJobConfig->sourceFormat('NEWLINE_DELIMITED_JSON');
Parameter | |
---|---|
Name | Description |
sourceFormat |
string
The source format. Acceptable values include
|
Returns | |
---|---|
Type | Description |
Google\Cloud\BigQuery\LoadJobConfiguration |
sourceUris
Sets the fully-qualified URIs that point to your data in Google Cloud.
- For Google Cloud Storage URIs: Each URI can contain one '*' wildcard character and it must come after the 'bucket' name.
- For Google Cloud Bigtable URIs: Exactly one URI can be specified and it has be a fully specified and valid HTTPS URL for a Google Cloud Bigtable table.
- For Google Cloud Datastore backups: Exactly one URI can be specified. Also, the '*' wildcard character is not allowed.
Example:
$loadJobConfig->sourceUris([
'gs://my_bucket/source.csv'
]);
Parameter | |
---|---|
Name | Description |
sourceUris |
array
The source URIs. |
Returns | |
---|---|
Type | Description |
Google\Cloud\BigQuery\LoadJobConfiguration |
timePartitioning
Sets time-based partitioning for the destination table.
Only one of timePartitioning and rangePartitioning should be specified.
Example:
$loadJobConfig->timePartitioning([
'type' => 'DAY'
]);
Parameter | |
---|---|
Name | Description |
timePartitioning |
array
Time-based partitioning configuration. |
Returns | |
---|---|
Type | Description |
Google\Cloud\BigQuery\LoadJobConfiguration |
rangePartitioning
Sets range partitioning specification for the destination table.
Only one of timePartitioning and rangePartitioning should be specified.
Example:
$loadJobConfig->rangePartitioning([
'field' => 'myInt',
'range' => [
'start' => '0',
'end' => '1000',
'interval' => '100'
]
]);
Parameter | |
---|---|
Name | Description |
rangePartitioning |
array
|
Returns | |
---|---|
Type | Description |
Google\Cloud\BigQuery\LoadJobConfiguration |
writeDisposition
Sets the action that occurs if the destination table already exists. Each action is atomic and only occurs if BigQuery is able to complete the job successfully. Creation, truncation and append actions occur as one atomic update upon job completion.
Example:
$loadJobConfig->writeDisposition('WRITE_TRUNCATE');
Parameter | |
---|---|
Name | Description |
writeDisposition |
string
The write disposition. Acceptable values
include |
Returns | |
---|---|
Type | Description |
Google\Cloud\BigQuery\LoadJobConfiguration |
useAvroLogicalTypes
Sets whether to use logical types when loading from AVRO format.
If sourceFormat is set to "AVRO", indicates whether to enable interpreting logical types into their corresponding types (ie. TIMESTAMP), instead of only using their raw types (ie. INTEGER).
Example:
$loadJobConfig->useAvroLogicalTypes(true);
Parameter | |
---|---|
Name | Description |
useAvroLogicalTypes |
bool
|
Returns | |
---|---|
Type | Description |
Google\Cloud\BigQuery\LoadJobConfiguration |
hivePartitioningOptions
Set hive partitioning options.
When set, configures hive partitioning support. Not all storage formats support hive partitioning -- requesting hive partitioning on an unsupported format will lead to an error, as will providing an invalid specification.
Example:
$loadJobConfig->hivePartitioningOptions([
'mode' => 'AUTO',
'sourceUriPrefix' => 'gs://bucket/path_to_table',
'requirePartitionFilter' => false,
]);
Parameter | |
---|---|
Name | Description |
hivePartitioningOptions |
array
|
Returns | |
---|---|
Type | Description |
Google\Cloud\BigQuery\LoadJobConfiguration |