Skip to content

Commit e0d0469

Browse files
authored
feat(BigQuery): Add missing setters for LoadJobConfiguration options (#8468)
1 parent 8f20636 commit e0d0469

2 files changed

Lines changed: 401 additions & 21 deletions

File tree

BigQuery/src/LoadJobConfiguration.php

Lines changed: 344 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Copyright 2017 Google Inc. All Rights Reserved.
45
*
@@ -698,4 +699,347 @@ public function referenceFileSchemaUri(string $referenceFileSchemaUri)
698699

699700
return $this;
700701
}
702+
703+
/**
704+
* Character map supported for column names in CSV/Parquet loads.
705+
* Defaults to STRICT and can be overridden by Project Config Service. Using
706+
* this option with unsupporting load formats will result in an error.
707+
*
708+
* Example:
709+
* ```
710+
* $loadJobConfig->columnNameCharacterMap('V2');
711+
* ```
712+
*
713+
* @param string $columnNameCharacterMap The column name character map.
714+
* Acceptable values include "COLUMN_NAME_CHARACTER_MAP_UNSPECIFIED",
715+
* "STRICT", "V1", "V2".
716+
* @return LoadJobConfiguration
717+
*/
718+
public function columnNameCharacterMap(string $columnNameCharacterMap): self
719+
{
720+
$this->config['configuration']['load']['columnNameCharacterMap'] = $columnNameCharacterMap;
721+
722+
return $this;
723+
}
724+
725+
/**
726+
* [Experimental] Configures the load job to copy files directly to the
727+
* destination BigLake managed table, bypassing file content reading and
728+
* rewriting. Copying files only is supported when all the following are
729+
* true:
730+
* * `source_uris` are located in the same Cloud Storage location as the
731+
* destination table's `storage_uri` location.
732+
* * `source_format` is `PARQUET`.
733+
* * `destination_table` is an existing BigLake managed table. The table's
734+
* schema does not have flexible column names. The table's columns do not
735+
* have type parameters other than precision and scale.
736+
* * No options other than the above are specified.
737+
*
738+
* Example:
739+
* ```
740+
* $loadJobConfig->copyFilesOnly(true);
741+
* ```
742+
*
743+
* @param bool $copyFilesOnly Whether to copy files only.
744+
* @return LoadJobConfiguration
745+
*/
746+
public function copyFilesOnly(bool $copyFilesOnly): self
747+
{
748+
$this->config['configuration']['load']['copyFilesOnly'] = $copyFilesOnly;
749+
750+
return $this;
751+
}
752+
753+
/**
754+
* Date format used for parsing DATE values.
755+
*
756+
* Example:
757+
* ```
758+
* $loadJobConfig->dateFormat('%Y-%m-%d');
759+
* ```
760+
*
761+
* @param string $dateFormat The date format string.
762+
* @return LoadJobConfiguration
763+
*/
764+
public function dateFormat(string $dateFormat): self
765+
{
766+
$this->config['configuration']['load']['dateFormat'] = $dateFormat;
767+
768+
return $this;
769+
}
770+
771+
/**
772+
* Date format used for parsing DATETIME values.
773+
*
774+
* Example:
775+
* ```
776+
* $loadJobConfig->datetimeFormat('%Y-%m-%d %H:%M:%S');
777+
* ```
778+
*
779+
* @param string $datetimeFormat The datetime format string.
780+
* @return LoadJobConfiguration
781+
*/
782+
public function datetimeFormat(string $datetimeFormat): self
783+
{
784+
$this->config['configuration']['load']['datetimeFormat'] = $datetimeFormat;
785+
786+
return $this;
787+
}
788+
789+
/**
790+
* Defines the list of possible SQL data types to which the source decimal
791+
* values are converted. This list and the precision and the scale parameters
792+
* of the decimal field determine the target type. In the order of NUMERIC,
793+
* BIGNUMERIC, and STRING, a type is picked if it is in the specified list
794+
* and if it supports the precision and the scale. STRING supports all
795+
* precision and scale values. If none of the listed types supports the
796+
* precision and the scale, the type supporting the widest range in the
797+
* specified list is picked, and if a value exceeds the supported range
798+
* when reading the data, an error will be thrown. Example: Suppose the value
799+
* of this field is ["NUMERIC", "BIGNUMERIC"]. If (precision,scale) is:
800+
* * (38,9) -> NUMERIC;
801+
* * (39,9) -> BIGNUMERIC (NUMERIC cannot hold 30 integer digits);
802+
* * (38,10) -> BIGNUMERIC (NUMERIC cannot hold 10 fractional digits);
803+
* * (76,38) -> BIGNUMERIC;
804+
* * (77,38) -> BIGNUMERIC (error if value exceeds supported range).
805+
* This field cannot contain duplicate types. The order of the types in this
806+
* field is ignored. For example, ["BIGNUMERIC", "NUMERIC"] is the same as
807+
* ["NUMERIC", "BIGNUMERIC"] and NUMERIC always takes precedence over BIGNUMERIC.
808+
* Defaults to ["NUMERIC", "STRING"] for ORC and ["NUMERIC"] for the other
809+
* file formats.
810+
*
811+
* Example:
812+
* ```
813+
* $loadJobConfig->decimalTargetTypes(['NUMERIC', 'BIGNUMERIC']);
814+
* ```
815+
*
816+
* @param string[] $decimalTargetTypes An array of target decimal types.
817+
* Acceptable values include "DECIMAL_TARGET_TYPE_UNSPECIFIED",
818+
* "NUMERIC", "BIGNUMERIC", "STRING".
819+
* @return LoadJobConfiguration
820+
*/
821+
public function decimalTargetTypes(array $decimalTargetTypes): self
822+
{
823+
$this->config['configuration']['load']['decimalTargetTypes'] = $decimalTargetTypes;
824+
825+
return $this;
826+
}
827+
828+
/**
829+
* [Experimental] Properties with which to create the destination table
830+
* if it is new.
831+
*
832+
* Example:
833+
* ```
834+
* $loadJobConfig->destinationTableProperties([
835+
* 'description' => 'My new table',
836+
* 'friendlyName' => 'New Table',
837+
* 'labels' => ['env' => 'dev']
838+
* ]);
839+
* ```
840+
*
841+
* @see https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#destinationtableproperties
842+
* DestinationTableProperties
843+
*
844+
* @param array $destinationTableProperties Properties for the destination table.
845+
* @return LoadJobConfiguration
846+
*/
847+
public function destinationTableProperties(array $destinationTableProperties): self
848+
{
849+
$this->config['configuration']['load']['destinationTableProperties'] = $destinationTableProperties;
850+
851+
return $this;
852+
}
853+
854+
/**
855+
* Specifies how source URIs are interpreted for constructing the
856+
* file set to load. By default, source URIs are expanded against the
857+
* underlying storage. You can also specify manifest files to control how the
858+
* file set is constructed. This option is only applicable to object storage
859+
* systems.
860+
*
861+
* Example:
862+
* ```
863+
* $loadJobConfig->fileSetSpecType('FILE_SET_SPEC_TYPE_NEW_LINE_DELIMITED_MANIFEST');
864+
* ```
865+
*
866+
* @param string $fileSetSpecType The file set specification type.
867+
* Acceptable values include "FILE_SET_SPEC_TYPE_FILE_SYSTEM_MATCH",
868+
* "FILE_SET_SPEC_TYPE_NEW_LINE_DELIMITED_MANIFEST".
869+
* @return LoadJobConfiguration
870+
*/
871+
public function fileSetSpecType(string $fileSetSpecType): self
872+
{
873+
$this->config['configuration']['load']['fileSetSpecType'] = $fileSetSpecType;
874+
875+
return $this;
876+
}
877+
878+
/**
879+
* Load option to be used together with source_format
880+
* newline-delimited JSON to indicate that a variant of JSON is being loaded.
881+
* To load newline-delimited GeoJSON, specify GEOJSON (and source_format
882+
* must be set to NEWLINE_DELIMITED_JSON).
883+
*
884+
* Example:
885+
* ```
886+
* $loadJobConfig->jsonExtension('GEOJSON');
887+
* ```
888+
*
889+
* @param string $jsonExtension The JSON extension type.
890+
* Acceptable values include "JSON_EXTENSION_UNSPECIFIED", "GEOJSON".
891+
* @return LoadJobConfiguration
892+
*/
893+
public function jsonExtension(string $jsonExtension): self
894+
{
895+
$this->config['configuration']['load']['jsonExtension'] = $jsonExtension;
896+
897+
return $this;
898+
}
899+
900+
/**
901+
* A list of strings represented as SQL NULL value in a CSV file.
902+
* null_marker and null_markers can't be set at the same time. If null_marker
903+
* is set, null_markers has to be not set. If null_markers is set, null_marker
904+
* has to be not set. If both null_marker and null_markers are set at the same
905+
* time, a user error would be thrown. Any strings listed in null_markers,
906+
* including empty string would be interpreted as SQL NULL. This applies to all
907+
* column types.
908+
*
909+
* Example:
910+
* ```
911+
* $loadJobConfig->nullMarkers(['\\N', 'NULL']);
912+
* ```
913+
*
914+
* @param string[] $nullMarkers An array of strings to be interpreted as NULL.
915+
* @return LoadJobConfiguration
916+
*/
917+
public function nullMarkers(array $nullMarkers): self
918+
{
919+
$this->config['configuration']['load']['nullMarkers'] = $nullMarkers;
920+
921+
return $this;
922+
}
923+
924+
/**
925+
* Additional properties to set if sourceFormat is set to PARQUET.
926+
*
927+
* @see https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#ParquetOptions ParquetOptions
928+
*
929+
* Example:
930+
* ```
931+
* $loadJobConfig->parquetOptions([
932+
* 'enumAsString' => true
933+
* ]);
934+
* ```
935+
*
936+
* @param array $parquetOptions Additional Parquet options.
937+
* @return LoadJobConfiguration
938+
*/
939+
public function parquetOptions(array $parquetOptions): self
940+
{
941+
$this->config['configuration']['load']['parquetOptions'] = $parquetOptions;
942+
943+
return $this;
944+
}
945+
946+
/**
947+
* When sourceFormat is set to "CSV", this indicates whether the
948+
* embedded ASCII control characters (the first 32 characters in the
949+
* ASCII-table, from '\\x00' to '\\x1F') are preserved.
950+
*
951+
* Example:
952+
* ```
953+
* $loadJobConfig->preserveAsciiControlCharacters(true);
954+
* ```
955+
*
956+
* @param bool $preserveAsciiControlCharacters Whether to preserve ASCII
957+
* control characters.
958+
* @return LoadJobConfiguration
959+
*/
960+
public function preserveAsciiControlCharacters(bool $preserveAsciiControlCharacters): self
961+
{
962+
$this->config['configuration']['load']['preserveAsciiControlCharacters'] = $preserveAsciiControlCharacters;
963+
964+
return $this;
965+
}
966+
967+
/**
968+
* Controls the strategy used to match loaded columns to the schema.
969+
* If not set, a sensible default is chosen based on how the schema is
970+
* provided. If autodetect is used, then columns are matched by name.
971+
* Otherwise, columns are matched by position. This is done to keep the
972+
* behavior backward-compatible.
973+
*
974+
* Example:
975+
* ```
976+
* $loadJobConfig->sourceColumnMatch('NAME');
977+
* ```
978+
*
979+
* @param string $sourceColumnMatch The column match strategy.
980+
* Acceptable values include "SOURCE_COLUMN_MATCH_UNSPECIFIED",
981+
* "POSITION", "NAME".
982+
* @return LoadJobConfiguration
983+
*/
984+
public function sourceColumnMatch(string $sourceColumnMatch): self
985+
{
986+
$this->config['configuration']['load']['sourceColumnMatch'] = $sourceColumnMatch;
987+
988+
return $this;
989+
}
990+
991+
/**
992+
* Date format used for parsing TIME values.
993+
*
994+
* Example:
995+
* ```
996+
* $loadJobConfig->timeFormat('%H:%M:%S');
997+
* ```
998+
*
999+
* @param string $timeFormat The time format string.
1000+
* @return LoadJobConfiguration
1001+
*/
1002+
public function timeFormat(string $timeFormat): self
1003+
{
1004+
$this->config['configuration']['load']['timeFormat'] = $timeFormat;
1005+
1006+
return $this;
1007+
}
1008+
1009+
/**
1010+
* Default time zone that will apply when parsing timestamp values
1011+
* that have no specific time zone.
1012+
*
1013+
* Example:
1014+
* ```
1015+
* $loadJobConfig->timeZone('America/Los_Angeles');
1016+
* ```
1017+
*
1018+
* @param string $timeZone The default time zone string.
1019+
* @return LoadJobConfiguration
1020+
*/
1021+
public function timeZone(string $timeZone): self
1022+
{
1023+
$this->config['configuration']['load']['timeZone'] = $timeZone;
1024+
1025+
return $this;
1026+
}
1027+
1028+
/**
1029+
* Date format used for parsing TIMESTAMP values.
1030+
*
1031+
* Example:
1032+
* ```
1033+
* $loadJobConfig->timestampFormat('%Y-%m-%d %H:%M:%S%F');
1034+
* ```
1035+
*
1036+
* @param string $timestampFormat The timestamp format string.
1037+
* @return LoadJobConfiguration
1038+
*/
1039+
public function timestampFormat(string $timestampFormat): self
1040+
{
1041+
$this->config['configuration']['load']['timestampFormat'] = $timestampFormat;
1042+
1043+
return $this;
1044+
}
7011045
}

0 commit comments

Comments
 (0)