3030from google .cloud .bigquery ._helpers import _int_or_none
3131from google .cloud .bigquery ._helpers import _str_or_none
3232from google .cloud .bigquery import _helpers
33+ from google .cloud .bigquery .enums import SourceColumnMatch
3334from google .cloud .bigquery .format_options import AvroOptions , ParquetOptions
3435from google .cloud .bigquery import schema
3536from google .cloud .bigquery .schema import SchemaField
@@ -499,14 +500,15 @@ def null_markers(self, value: Optional[List[str]]):
499500 self ._properties ["nullMarkers" ] = value
500501
501502 @property
502- def source_column_match (self ) -> Optional [str ]:
503- """Optional[str ]: Controls the strategy used to match loaded columns to the schema. If not
504- set, a sensible default is chosen based on how the schema is provided. If
505- autodetect is used, then columns are matched by name. Otherwise, columns
506- are matched by position. This is done to keep the behavior
507- backward-compatible.
503+ def source_column_match (self ) -> Optional [SourceColumnMatch ]:
504+ """Optional[SourceColumnMatch ]: Controls the strategy used to match loaded
505+ columns to the schema. If not set, a sensible default is chosen based on
506+ how the schema is provided. If autodetect is used, then columns are matched
507+ by name. Otherwise, columns are matched by position. This is done to keep
508+ the behavior backward-compatible.
508509
509510 Acceptable values are:
511+ SOURCE_COLUMN_MATCH_UNSPECIFIED - Unspecified column name match option.
510512 POSITION - matches by position. This assumes that the columns are ordered
511513 the same way as the schema.
512514 NAME - matches by name. This reads the header row as column names and
@@ -515,12 +517,19 @@ def source_column_match(self) -> Optional[str]:
515517 See
516518 https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#ExternalDataConfiguration.FIELDS.source_column_match
517519 """
518- result = self ._properties .get ("sourceColumnMatch" )
519- return typing .cast (str , result )
520+
521+ value = self ._properties .get ("sourceColumnMatch" )
522+ if value is not None :
523+ return SourceColumnMatch (value )
524+ return None
520525
521526 @source_column_match .setter
522- def source_column_match (self , value : Optional [str ]):
523- self ._properties ["sourceColumnMatch" ] = value
527+ def source_column_match (self , value : Optional [SourceColumnMatch ]):
528+ if value is not None and not isinstance (value , SourceColumnMatch ):
529+ raise TypeError (
530+ "value must be a google.cloud.bigquery.enums.SourceColumnMatch or None"
531+ )
532+ self ._properties ["sourceColumnMatch" ] = value .value if value else None
524533
525534 def to_api_repr (self ) -> dict :
526535 """Build an API representation of this object.
0 commit comments