Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/google/cloud/bigquery/format_options.py: 63%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

51 statements  

1# Copyright 2021 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. 

14 

15import copy 

16from typing import Dict, Optional, Union 

17 

18 

19class AvroOptions: 

20 """Options if source format is set to AVRO.""" 

21 

22 _SOURCE_FORMAT = "AVRO" 

23 _RESOURCE_NAME = "avroOptions" 

24 

25 def __init__(self): 

26 self._properties = {} 

27 

28 @property 

29 def use_avro_logical_types(self) -> Optional[bool]: 

30 """[Optional] If sourceFormat is set to 'AVRO', indicates whether to 

31 interpret logical types as the corresponding BigQuery data type (for 

32 example, TIMESTAMP), instead of using the raw type (for example, 

33 INTEGER). 

34 

35 See 

36 https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#AvroOptions.FIELDS.use_avro_logical_types 

37 """ 

38 return self._properties.get("useAvroLogicalTypes") 

39 

40 @use_avro_logical_types.setter 

41 def use_avro_logical_types(self, value): 

42 self._properties["useAvroLogicalTypes"] = value 

43 

44 @classmethod 

45 def from_api_repr(cls, resource: Dict[str, bool]) -> "AvroOptions": 

46 """Factory: construct an instance from a resource dict. 

47 

48 Args: 

49 resource (Dict[str, bool]): 

50 Definition of a :class:`~.format_options.AvroOptions` instance in 

51 the same representation as is returned from the API. 

52 

53 Returns: 

54 :class:`~.format_options.AvroOptions`: 

55 Configuration parsed from ``resource``. 

56 """ 

57 config = cls() 

58 config._properties = copy.deepcopy(resource) 

59 return config 

60 

61 def to_api_repr(self) -> dict: 

62 """Build an API representation of this object. 

63 

64 Returns: 

65 Dict[str, bool]: 

66 A dictionary in the format used by the BigQuery API. 

67 """ 

68 return copy.deepcopy(self._properties) 

69 

70 

71class ParquetOptions: 

72 """Additional options if the PARQUET source format is used.""" 

73 

74 _SOURCE_FORMAT = "PARQUET" 

75 _RESOURCE_NAME = "parquetOptions" 

76 

77 def __init__(self): 

78 self._properties = {} 

79 

80 @property 

81 def enum_as_string(self) -> bool: 

82 """Indicates whether to infer Parquet ENUM logical type as STRING instead of 

83 BYTES by default. 

84 

85 See 

86 https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#ParquetOptions.FIELDS.enum_as_string 

87 """ 

88 return self._properties.get("enumAsString") 

89 

90 @enum_as_string.setter 

91 def enum_as_string(self, value: bool) -> None: 

92 self._properties["enumAsString"] = value 

93 

94 @property 

95 def enable_list_inference(self) -> bool: 

96 """Indicates whether to use schema inference specifically for Parquet LIST 

97 logical type. 

98 

99 See 

100 https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#ParquetOptions.FIELDS.enable_list_inference 

101 """ 

102 return self._properties.get("enableListInference") 

103 

104 @enable_list_inference.setter 

105 def enable_list_inference(self, value: bool) -> None: 

106 self._properties["enableListInference"] = value 

107 

108 @property 

109 def map_target_type(self) -> Optional[Union[bool, str]]: 

110 """Indicates whether to simplify the representation of parquet maps to only show keys and values.""" 

111 

112 return self._properties.get("mapTargetType") 

113 

114 @map_target_type.setter 

115 def map_target_type(self, value: str) -> None: 

116 """Sets the map target type. 

117 

118 Args: 

119 value: The map target type (eg ARRAY_OF_STRUCT). 

120 """ 

121 self._properties["mapTargetType"] = value 

122 

123 @classmethod 

124 def from_api_repr(cls, resource: Dict[str, bool]) -> "ParquetOptions": 

125 """Factory: construct an instance from a resource dict. 

126 

127 Args: 

128 resource (Dict[str, bool]): 

129 Definition of a :class:`~.format_options.ParquetOptions` instance in 

130 the same representation as is returned from the API. 

131 

132 Returns: 

133 :class:`~.format_options.ParquetOptions`: 

134 Configuration parsed from ``resource``. 

135 """ 

136 config = cls() 

137 config._properties = copy.deepcopy(resource) 

138 return config 

139 

140 def to_api_repr(self) -> dict: 

141 """Build an API representation of this object. 

142 

143 Returns: 

144 Dict[str, bool]: 

145 A dictionary in the format used by the BigQuery API. 

146 """ 

147 return copy.deepcopy(self._properties)