Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/google/cloud/bigquery/job/load.py: 56%
376 statements
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-26 06:07 +0000
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-26 06:07 +0000
1# Copyright 2015 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
15"""Classes for load jobs."""
17import typing
18from typing import FrozenSet, List, Iterable, Optional
20from google.cloud.bigquery.encryption_configuration import EncryptionConfiguration
21from google.cloud.bigquery.external_config import HivePartitioningOptions
22from google.cloud.bigquery.format_options import ParquetOptions
23from google.cloud.bigquery import _helpers
24from google.cloud.bigquery.schema import SchemaField
25from google.cloud.bigquery.schema import _to_schema_fields
26from google.cloud.bigquery.table import RangePartitioning
27from google.cloud.bigquery.table import TableReference
28from google.cloud.bigquery.table import TimePartitioning
29from google.cloud.bigquery.job.base import _AsyncJob
30from google.cloud.bigquery.job.base import _JobConfig
31from google.cloud.bigquery.job.base import _JobReference
32from google.cloud.bigquery.query import ConnectionProperty
35class LoadJobConfig(_JobConfig):
36 """Configuration options for load jobs.
38 Set properties on the constructed configuration by using the property name
39 as the name of a keyword argument. Values which are unset or :data:`None`
40 use the BigQuery REST API default values. See the `BigQuery REST API
41 reference documentation
42 <https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad>`_
43 for a list of default values.
45 Required options differ based on the
46 :attr:`~google.cloud.bigquery.job.LoadJobConfig.source_format` value.
47 For example, the BigQuery API's default value for
48 :attr:`~google.cloud.bigquery.job.LoadJobConfig.source_format` is ``"CSV"``.
49 When loading a CSV file, either
50 :attr:`~google.cloud.bigquery.job.LoadJobConfig.schema` must be set or
51 :attr:`~google.cloud.bigquery.job.LoadJobConfig.autodetect` must be set to
52 :data:`True`.
53 """
55 def __init__(self, **kwargs) -> None:
56 super(LoadJobConfig, self).__init__("load", **kwargs)
58 @property
59 def allow_jagged_rows(self):
60 """Optional[bool]: Allow missing trailing optional columns (CSV only).
62 See:
63 https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.allow_jagged_rows
64 """
65 return self._get_sub_prop("allowJaggedRows")
67 @allow_jagged_rows.setter
68 def allow_jagged_rows(self, value):
69 self._set_sub_prop("allowJaggedRows", value)
71 @property
72 def allow_quoted_newlines(self):
73 """Optional[bool]: Allow quoted data containing newline characters (CSV only).
75 See:
76 https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.allow_quoted_newlines
77 """
78 return self._get_sub_prop("allowQuotedNewlines")
80 @allow_quoted_newlines.setter
81 def allow_quoted_newlines(self, value):
82 self._set_sub_prop("allowQuotedNewlines", value)
84 @property
85 def autodetect(self):
86 """Optional[bool]: Automatically infer the schema from a sample of the data.
88 See:
89 https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.autodetect
90 """
91 return self._get_sub_prop("autodetect")
93 @autodetect.setter
94 def autodetect(self, value):
95 self._set_sub_prop("autodetect", value)
97 @property
98 def clustering_fields(self):
99 """Optional[List[str]]: Fields defining clustering for the table
101 (Defaults to :data:`None`).
103 Clustering fields are immutable after table creation.
105 .. note::
107 BigQuery supports clustering for both partitioned and
108 non-partitioned tables.
109 """
110 prop = self._get_sub_prop("clustering")
111 if prop is not None:
112 return list(prop.get("fields", ()))
114 @clustering_fields.setter
115 def clustering_fields(self, value):
116 """Optional[List[str]]: Fields defining clustering for the table
118 (Defaults to :data:`None`).
119 """
120 if value is not None:
121 self._set_sub_prop("clustering", {"fields": value})
122 else:
123 self._del_sub_prop("clustering")
125 @property
126 def connection_properties(self) -> List[ConnectionProperty]:
127 """Connection properties.
129 See
130 https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.connection_properties
132 .. versionadded:: 3.7.0
133 """
134 resource = self._get_sub_prop("connectionProperties", [])
135 return [ConnectionProperty.from_api_repr(prop) for prop in resource]
137 @connection_properties.setter
138 def connection_properties(self, value: Iterable[ConnectionProperty]):
139 self._set_sub_prop(
140 "connectionProperties",
141 [prop.to_api_repr() for prop in value],
142 )
144 @property
145 def create_disposition(self):
146 """Optional[google.cloud.bigquery.job.CreateDisposition]: Specifies behavior
147 for creating tables.
149 See:
150 https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.create_disposition
151 """
152 return self._get_sub_prop("createDisposition")
154 @create_disposition.setter
155 def create_disposition(self, value):
156 self._set_sub_prop("createDisposition", value)
158 @property
159 def create_session(self) -> Optional[bool]:
160 """[Preview] If :data:`True`, creates a new session, where
161 :attr:`~google.cloud.bigquery.job.LoadJob.session_info` will contain a
162 random server generated session id.
164 If :data:`False`, runs load job with an existing ``session_id`` passed in
165 :attr:`~google.cloud.bigquery.job.LoadJobConfig.connection_properties`,
166 otherwise runs load job in non-session mode.
168 See
169 https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.create_session
171 .. versionadded:: 3.7.0
172 """
173 return self._get_sub_prop("createSession")
175 @create_session.setter
176 def create_session(self, value: Optional[bool]):
177 self._set_sub_prop("createSession", value)
179 @property
180 def decimal_target_types(self) -> Optional[FrozenSet[str]]:
181 """Possible SQL data types to which the source decimal values are converted.
183 See:
184 https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.decimal_target_types
186 .. versionadded:: 2.21.0
187 """
188 prop = self._get_sub_prop("decimalTargetTypes")
189 if prop is not None:
190 prop = frozenset(prop)
191 return prop
193 @decimal_target_types.setter
194 def decimal_target_types(self, value: Optional[Iterable[str]]):
195 if value is not None:
196 self._set_sub_prop("decimalTargetTypes", list(value))
197 else:
198 self._del_sub_prop("decimalTargetTypes")
200 @property
201 def destination_encryption_configuration(self):
202 """Optional[google.cloud.bigquery.encryption_configuration.EncryptionConfiguration]: Custom
203 encryption configuration for the destination table.
205 Custom encryption configuration (e.g., Cloud KMS keys) or :data:`None`
206 if using default encryption.
208 See:
209 https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.destination_encryption_configuration
210 """
211 prop = self._get_sub_prop("destinationEncryptionConfiguration")
212 if prop is not None:
213 prop = EncryptionConfiguration.from_api_repr(prop)
214 return prop
216 @destination_encryption_configuration.setter
217 def destination_encryption_configuration(self, value):
218 api_repr = value
219 if value is not None:
220 api_repr = value.to_api_repr()
221 self._set_sub_prop("destinationEncryptionConfiguration", api_repr)
222 else:
223 self._del_sub_prop("destinationEncryptionConfiguration")
225 @property
226 def destination_table_description(self):
227 """Optional[str]: Description of the destination table.
229 See:
230 https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#DestinationTableProperties.FIELDS.description
231 """
232 prop = self._get_sub_prop("destinationTableProperties")
233 if prop is not None:
234 return prop["description"]
236 @destination_table_description.setter
237 def destination_table_description(self, value):
238 keys = [self._job_type, "destinationTableProperties", "description"]
239 if value is not None:
240 _helpers._set_sub_prop(self._properties, keys, value)
241 else:
242 _helpers._del_sub_prop(self._properties, keys)
244 @property
245 def destination_table_friendly_name(self):
246 """Optional[str]: Name given to destination table.
248 See:
249 https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#DestinationTableProperties.FIELDS.friendly_name
250 """
251 prop = self._get_sub_prop("destinationTableProperties")
252 if prop is not None:
253 return prop["friendlyName"]
255 @destination_table_friendly_name.setter
256 def destination_table_friendly_name(self, value):
257 keys = [self._job_type, "destinationTableProperties", "friendlyName"]
258 if value is not None:
259 _helpers._set_sub_prop(self._properties, keys, value)
260 else:
261 _helpers._del_sub_prop(self._properties, keys)
263 @property
264 def encoding(self):
265 """Optional[google.cloud.bigquery.job.Encoding]: The character encoding of the
266 data.
268 See:
269 https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.encoding
270 """
271 return self._get_sub_prop("encoding")
273 @encoding.setter
274 def encoding(self, value):
275 self._set_sub_prop("encoding", value)
277 @property
278 def field_delimiter(self):
279 """Optional[str]: The separator for fields in a CSV file.
281 See:
282 https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.field_delimiter
283 """
284 return self._get_sub_prop("fieldDelimiter")
286 @field_delimiter.setter
287 def field_delimiter(self, value):
288 self._set_sub_prop("fieldDelimiter", value)
290 @property
291 def hive_partitioning(self):
292 """Optional[:class:`~.external_config.HivePartitioningOptions`]: [Beta] When set, \
293 it configures hive partitioning support.
295 .. note::
296 **Experimental**. This feature is experimental and might change or
297 have limited support.
299 See:
300 https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.hive_partitioning_options
301 """
302 prop = self._get_sub_prop("hivePartitioningOptions")
303 if prop is None:
304 return None
305 return HivePartitioningOptions.from_api_repr(prop)
307 @hive_partitioning.setter
308 def hive_partitioning(self, value):
309 if value is not None:
310 if isinstance(value, HivePartitioningOptions):
311 value = value.to_api_repr()
312 else:
313 raise TypeError("Expected a HivePartitioningOptions instance or None.")
315 self._set_sub_prop("hivePartitioningOptions", value)
317 @property
318 def ignore_unknown_values(self):
319 """Optional[bool]: Ignore extra values not represented in the table schema.
321 See:
322 https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.ignore_unknown_values
323 """
324 return self._get_sub_prop("ignoreUnknownValues")
326 @ignore_unknown_values.setter
327 def ignore_unknown_values(self, value):
328 self._set_sub_prop("ignoreUnknownValues", value)
330 @property
331 def max_bad_records(self):
332 """Optional[int]: Number of invalid rows to ignore.
334 See:
335 https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.max_bad_records
336 """
337 return _helpers._int_or_none(self._get_sub_prop("maxBadRecords"))
339 @max_bad_records.setter
340 def max_bad_records(self, value):
341 self._set_sub_prop("maxBadRecords", value)
343 @property
344 def null_marker(self):
345 """Optional[str]: Represents a null value (CSV only).
347 See:
348 https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.null_marker
349 """
350 return self._get_sub_prop("nullMarker")
352 @null_marker.setter
353 def null_marker(self, value):
354 self._set_sub_prop("nullMarker", value)
356 @property
357 def preserve_ascii_control_characters(self):
358 """Optional[bool]: Preserves the embedded ASCII control characters when sourceFormat is set to CSV.
360 See:
361 https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.preserve_ascii_control_characters
362 """
363 return self._get_sub_prop("preserveAsciiControlCharacters")
365 @preserve_ascii_control_characters.setter
366 def preserve_ascii_control_characters(self, value):
367 self._set_sub_prop("preserveAsciiControlCharacters", bool(value))
369 @property
370 def projection_fields(self) -> Optional[List[str]]:
371 """Optional[List[str]]: If
372 :attr:`google.cloud.bigquery.job.LoadJobConfig.source_format` is set to
373 "DATASTORE_BACKUP", indicates which entity properties to load into
374 BigQuery from a Cloud Datastore backup.
376 Property names are case sensitive and must be top-level properties. If
377 no properties are specified, BigQuery loads all properties. If any
378 named property isn't found in the Cloud Datastore backup, an invalid
379 error is returned in the job result.
381 See:
382 https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.projection_fields
383 """
384 return self._get_sub_prop("projectionFields")
386 @projection_fields.setter
387 def projection_fields(self, value: Optional[List[str]]):
388 self._set_sub_prop("projectionFields", value)
390 @property
391 def quote_character(self):
392 """Optional[str]: Character used to quote data sections (CSV only).
394 See:
395 https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.quote
396 """
397 return self._get_sub_prop("quote")
399 @quote_character.setter
400 def quote_character(self, value):
401 self._set_sub_prop("quote", value)
403 @property
404 def range_partitioning(self):
405 """Optional[google.cloud.bigquery.table.RangePartitioning]:
406 Configures range-based partitioning for destination table.
408 .. note::
409 **Beta**. The integer range partitioning feature is in a
410 pre-release state and might change or have limited support.
412 Only specify at most one of
413 :attr:`~google.cloud.bigquery.job.LoadJobConfig.time_partitioning` or
414 :attr:`~google.cloud.bigquery.job.LoadJobConfig.range_partitioning`.
416 Raises:
417 ValueError:
418 If the value is not
419 :class:`~google.cloud.bigquery.table.RangePartitioning` or
420 :data:`None`.
421 """
422 resource = self._get_sub_prop("rangePartitioning")
423 if resource is not None:
424 return RangePartitioning(_properties=resource)
426 @range_partitioning.setter
427 def range_partitioning(self, value):
428 resource = value
429 if isinstance(value, RangePartitioning):
430 resource = value._properties
431 elif value is not None:
432 raise ValueError(
433 "Expected value to be RangePartitioning or None, got {}.".format(value)
434 )
435 self._set_sub_prop("rangePartitioning", resource)
437 @property
438 def reference_file_schema_uri(self):
439 """Optional[str]:
440 When creating an external table, the user can provide a reference file with the
441 table schema. This is enabled for the following formats:
443 AVRO, PARQUET, ORC
444 """
445 return self._get_sub_prop("referenceFileSchemaUri")
447 @reference_file_schema_uri.setter
448 def reference_file_schema_uri(self, value):
449 return self._set_sub_prop("referenceFileSchemaUri", value)
451 @property
452 def schema(self):
453 """Optional[Sequence[Union[ \
454 :class:`~google.cloud.bigquery.schema.SchemaField`, \
455 Mapping[str, Any] \
456 ]]]: Schema of the destination table.
458 See:
459 https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.schema
460 """
461 schema = _helpers._get_sub_prop(self._properties, ["load", "schema", "fields"])
462 if schema is None:
463 return
464 return [SchemaField.from_api_repr(field) for field in schema]
466 @schema.setter
467 def schema(self, value):
468 if value is None:
469 self._del_sub_prop("schema")
470 return
472 value = _to_schema_fields(value)
474 _helpers._set_sub_prop(
475 self._properties,
476 ["load", "schema", "fields"],
477 [field.to_api_repr() for field in value],
478 )
480 @property
481 def schema_update_options(self):
482 """Optional[List[google.cloud.bigquery.job.SchemaUpdateOption]]: Specifies
483 updates to the destination table schema to allow as a side effect of
484 the load job.
485 """
486 return self._get_sub_prop("schemaUpdateOptions")
488 @schema_update_options.setter
489 def schema_update_options(self, values):
490 self._set_sub_prop("schemaUpdateOptions", values)
492 @property
493 def skip_leading_rows(self):
494 """Optional[int]: Number of rows to skip when reading data (CSV only).
496 See:
497 https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.skip_leading_rows
498 """
499 return _helpers._int_or_none(self._get_sub_prop("skipLeadingRows"))
501 @skip_leading_rows.setter
502 def skip_leading_rows(self, value):
503 self._set_sub_prop("skipLeadingRows", str(value))
505 @property
506 def source_format(self):
507 """Optional[google.cloud.bigquery.job.SourceFormat]: File format of the data.
509 See:
510 https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.source_format
511 """
512 return self._get_sub_prop("sourceFormat")
514 @source_format.setter
515 def source_format(self, value):
516 self._set_sub_prop("sourceFormat", value)
518 @property
519 def time_partitioning(self):
520 """Optional[google.cloud.bigquery.table.TimePartitioning]: Specifies time-based
521 partitioning for the destination table.
523 Only specify at most one of
524 :attr:`~google.cloud.bigquery.job.LoadJobConfig.time_partitioning` or
525 :attr:`~google.cloud.bigquery.job.LoadJobConfig.range_partitioning`.
526 """
527 prop = self._get_sub_prop("timePartitioning")
528 if prop is not None:
529 prop = TimePartitioning.from_api_repr(prop)
530 return prop
532 @time_partitioning.setter
533 def time_partitioning(self, value):
534 api_repr = value
535 if value is not None:
536 api_repr = value.to_api_repr()
537 self._set_sub_prop("timePartitioning", api_repr)
538 else:
539 self._del_sub_prop("timePartitioning")
541 @property
542 def use_avro_logical_types(self):
543 """Optional[bool]: For loads of Avro data, governs whether Avro logical types are
544 converted to their corresponding BigQuery types (e.g. TIMESTAMP) rather than
545 raw types (e.g. INTEGER).
546 """
547 return self._get_sub_prop("useAvroLogicalTypes")
549 @use_avro_logical_types.setter
550 def use_avro_logical_types(self, value):
551 self._set_sub_prop("useAvroLogicalTypes", bool(value))
553 @property
554 def write_disposition(self):
555 """Optional[google.cloud.bigquery.job.WriteDisposition]: Action that occurs if
556 the destination table already exists.
558 See:
559 https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.write_disposition
560 """
561 return self._get_sub_prop("writeDisposition")
563 @write_disposition.setter
564 def write_disposition(self, value):
565 self._set_sub_prop("writeDisposition", value)
567 @property
568 def parquet_options(self):
569 """Optional[google.cloud.bigquery.format_options.ParquetOptions]: Additional
570 properties to set if ``sourceFormat`` is set to PARQUET.
572 See:
573 https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.parquet_options
574 """
575 prop = self._get_sub_prop("parquetOptions")
576 if prop is not None:
577 prop = ParquetOptions.from_api_repr(prop)
578 return prop
580 @parquet_options.setter
581 def parquet_options(self, value):
582 if value is not None:
583 self._set_sub_prop("parquetOptions", value.to_api_repr())
584 else:
585 self._del_sub_prop("parquetOptions")
588class LoadJob(_AsyncJob):
589 """Asynchronous job for loading data into a table.
591 Can load from Google Cloud Storage URIs or from a file.
593 Args:
594 job_id (str): the job's ID
596 source_uris (Optional[Sequence[str]]):
597 URIs of one or more data files to be loaded. See
598 https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.source_uris
599 for supported URI formats. Pass None for jobs that load from a file.
601 destination (google.cloud.bigquery.table.TableReference): reference to table into which data is to be loaded.
603 client (google.cloud.bigquery.client.Client):
604 A client which holds credentials and project configuration
605 for the dataset (which requires a project).
606 """
608 _JOB_TYPE = "load"
609 _CONFIG_CLASS = LoadJobConfig
611 def __init__(self, job_id, source_uris, destination, client, job_config=None):
612 super(LoadJob, self).__init__(job_id, client)
614 if job_config is not None:
615 self._properties["configuration"] = job_config._properties
617 if source_uris is not None:
618 _helpers._set_sub_prop(
619 self._properties, ["configuration", "load", "sourceUris"], source_uris
620 )
622 if destination is not None:
623 _helpers._set_sub_prop(
624 self._properties,
625 ["configuration", "load", "destinationTable"],
626 destination.to_api_repr(),
627 )
629 @property
630 def configuration(self) -> LoadJobConfig:
631 """The configuration for this load job."""
632 return typing.cast(LoadJobConfig, super().configuration)
634 @property
635 def destination(self):
636 """google.cloud.bigquery.table.TableReference: table where loaded rows are written
638 See:
639 https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.destination_table
640 """
641 dest_config = _helpers._get_sub_prop(
642 self._properties, ["configuration", "load", "destinationTable"]
643 )
644 return TableReference.from_api_repr(dest_config)
646 @property
647 def source_uris(self):
648 """Optional[Sequence[str]]: URIs of data files to be loaded. See
649 https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.source_uris
650 for supported URI formats. None for jobs that load from a file.
651 """
652 return _helpers._get_sub_prop(
653 self._properties, ["configuration", "load", "sourceUris"]
654 )
656 @property
657 def allow_jagged_rows(self):
658 """See
659 :attr:`google.cloud.bigquery.job.LoadJobConfig.allow_jagged_rows`.
660 """
661 return self.configuration.allow_jagged_rows
663 @property
664 def allow_quoted_newlines(self):
665 """See
666 :attr:`google.cloud.bigquery.job.LoadJobConfig.allow_quoted_newlines`.
667 """
668 return self.configuration.allow_quoted_newlines
670 @property
671 def autodetect(self):
672 """See
673 :attr:`google.cloud.bigquery.job.LoadJobConfig.autodetect`.
674 """
675 return self.configuration.autodetect
677 @property
678 def connection_properties(self) -> List[ConnectionProperty]:
679 """See
680 :attr:`google.cloud.bigquery.job.LoadJobConfig.connection_properties`.
682 .. versionadded:: 3.7.0
683 """
684 return self.configuration.connection_properties
686 @property
687 def create_disposition(self):
688 """See
689 :attr:`google.cloud.bigquery.job.LoadJobConfig.create_disposition`.
690 """
691 return self.configuration.create_disposition
693 @property
694 def create_session(self) -> Optional[bool]:
695 """See
696 :attr:`google.cloud.bigquery.job.LoadJobConfig.create_session`.
698 .. versionadded:: 3.7.0
699 """
700 return self.configuration.create_session
702 @property
703 def encoding(self):
704 """See
705 :attr:`google.cloud.bigquery.job.LoadJobConfig.encoding`.
706 """
707 return self.configuration.encoding
709 @property
710 def field_delimiter(self):
711 """See
712 :attr:`google.cloud.bigquery.job.LoadJobConfig.field_delimiter`.
713 """
714 return self.configuration.field_delimiter
716 @property
717 def ignore_unknown_values(self):
718 """See
719 :attr:`google.cloud.bigquery.job.LoadJobConfig.ignore_unknown_values`.
720 """
721 return self.configuration.ignore_unknown_values
723 @property
724 def max_bad_records(self):
725 """See
726 :attr:`google.cloud.bigquery.job.LoadJobConfig.max_bad_records`.
727 """
728 return self.configuration.max_bad_records
730 @property
731 def null_marker(self):
732 """See
733 :attr:`google.cloud.bigquery.job.LoadJobConfig.null_marker`.
734 """
735 return self.configuration.null_marker
737 @property
738 def quote_character(self):
739 """See
740 :attr:`google.cloud.bigquery.job.LoadJobConfig.quote_character`.
741 """
742 return self.configuration.quote_character
744 @property
745 def reference_file_schema_uri(self):
746 """See:
747 attr:`google.cloud.bigquery.job.LoadJobConfig.reference_file_schema_uri`.
748 """
749 return self.configuration.reference_file_schema_uri
751 @property
752 def skip_leading_rows(self):
753 """See
754 :attr:`google.cloud.bigquery.job.LoadJobConfig.skip_leading_rows`.
755 """
756 return self.configuration.skip_leading_rows
758 @property
759 def source_format(self):
760 """See
761 :attr:`google.cloud.bigquery.job.LoadJobConfig.source_format`.
762 """
763 return self.configuration.source_format
765 @property
766 def write_disposition(self):
767 """See
768 :attr:`google.cloud.bigquery.job.LoadJobConfig.write_disposition`.
769 """
770 return self.configuration.write_disposition
772 @property
773 def schema(self):
774 """See
775 :attr:`google.cloud.bigquery.job.LoadJobConfig.schema`.
776 """
777 return self.configuration.schema
779 @property
780 def destination_encryption_configuration(self):
781 """google.cloud.bigquery.encryption_configuration.EncryptionConfiguration: Custom
782 encryption configuration for the destination table.
784 Custom encryption configuration (e.g., Cloud KMS keys)
785 or :data:`None` if using default encryption.
787 See
788 :attr:`google.cloud.bigquery.job.LoadJobConfig.destination_encryption_configuration`.
789 """
790 return self.configuration.destination_encryption_configuration
792 @property
793 def destination_table_description(self):
794 """Optional[str] name given to destination table.
796 See:
797 https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#DestinationTableProperties.FIELDS.description
798 """
799 return self.configuration.destination_table_description
801 @property
802 def destination_table_friendly_name(self):
803 """Optional[str] name given to destination table.
805 See:
806 https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#DestinationTableProperties.FIELDS.friendly_name
807 """
808 return self.configuration.destination_table_friendly_name
810 @property
811 def range_partitioning(self):
812 """See
813 :attr:`google.cloud.bigquery.job.LoadJobConfig.range_partitioning`.
814 """
815 return self.configuration.range_partitioning
817 @property
818 def time_partitioning(self):
819 """See
820 :attr:`google.cloud.bigquery.job.LoadJobConfig.time_partitioning`.
821 """
822 return self.configuration.time_partitioning
824 @property
825 def use_avro_logical_types(self):
826 """See
827 :attr:`google.cloud.bigquery.job.LoadJobConfig.use_avro_logical_types`.
828 """
829 return self.configuration.use_avro_logical_types
831 @property
832 def clustering_fields(self):
833 """See
834 :attr:`google.cloud.bigquery.job.LoadJobConfig.clustering_fields`.
835 """
836 return self.configuration.clustering_fields
838 @property
839 def schema_update_options(self):
840 """See
841 :attr:`google.cloud.bigquery.job.LoadJobConfig.schema_update_options`.
842 """
843 return self.configuration.schema_update_options
845 @property
846 def input_file_bytes(self):
847 """Count of bytes loaded from source files.
849 Returns:
850 Optional[int]: the count (None until set from the server).
852 Raises:
853 ValueError: for invalid value types.
854 """
855 return _helpers._int_or_none(
856 _helpers._get_sub_prop(
857 self._properties, ["statistics", "load", "inputFileBytes"]
858 )
859 )
861 @property
862 def input_files(self):
863 """Count of source files.
865 Returns:
866 Optional[int]: the count (None until set from the server).
867 """
868 return _helpers._int_or_none(
869 _helpers._get_sub_prop(
870 self._properties, ["statistics", "load", "inputFiles"]
871 )
872 )
874 @property
875 def output_bytes(self):
876 """Count of bytes saved to destination table.
878 Returns:
879 Optional[int]: the count (None until set from the server).
880 """
881 return _helpers._int_or_none(
882 _helpers._get_sub_prop(
883 self._properties, ["statistics", "load", "outputBytes"]
884 )
885 )
887 @property
888 def output_rows(self):
889 """Count of rows saved to destination table.
891 Returns:
892 Optional[int]: the count (None until set from the server).
893 """
894 return _helpers._int_or_none(
895 _helpers._get_sub_prop(
896 self._properties, ["statistics", "load", "outputRows"]
897 )
898 )
900 def to_api_repr(self):
901 """Generate a resource for :meth:`_begin`."""
902 # Exclude statistics, if set.
903 return {
904 "jobReference": self._properties["jobReference"],
905 "configuration": self._properties["configuration"],
906 }
908 @classmethod
909 def from_api_repr(cls, resource: dict, client) -> "LoadJob":
910 """Factory: construct a job given its API representation
912 .. note::
914 This method assumes that the project found in the resource matches
915 the client's project.
917 Args:
918 resource (Dict): dataset job representation returned from the API
920 client (google.cloud.bigquery.client.Client):
921 Client which holds credentials and project
922 configuration for the dataset.
924 Returns:
925 google.cloud.bigquery.job.LoadJob: Job parsed from ``resource``.
926 """
927 cls._check_resource_config(resource)
928 job_ref = _JobReference._from_api_repr(resource["jobReference"])
929 job = cls(job_ref, None, None, client)
930 job._set_properties(resource)
931 return job