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

44 statements  

« prev     ^ index     » next       coverage.py v7.2.2, created at 2023-03-26 06:07 +0000

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 

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 @classmethod 

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

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

111 

112 Args: 

113 resource (Dict[str, bool]): 

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

115 the same representation as is returned from the API. 

116 

117 Returns: 

118 :class:`~.format_options.ParquetOptions`: 

119 Configuration parsed from ``resource``. 

120 """ 

121 config = cls() 

122 config._properties = copy.deepcopy(resource) 

123 return config 

124 

125 def to_api_repr(self) -> dict: 

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

127 

128 Returns: 

129 Dict[str, bool]: 

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

131 """ 

132 return copy.deepcopy(self._properties)