1515"""Options for displaying objects."""
1616
1717import dataclasses
18- from typing import Optional
18+ from typing import Any , Dict , Optional
1919
2020
2121@dataclasses .dataclass
@@ -34,6 +34,26 @@ class ComputeOptions:
3434
3535 >>> bpd.options.compute.maximum_bytes_billed = None # reset option
3636
37+ To add multiple extra labels to a query configuration, use the `assign_extra_query_labels`
38+ method with keyword arguments:
39+
40+ >>> bpd.options.compute.assign_extra_query_labels(test1=1, test2="abc")
41+ >>> bpd.options.compute.extra_query_labels
42+ {'test1': 1, 'test2': 'abc'}
43+
44+ Alternatively, you can add labels individually by directly accessing the `extra_query_labels`
45+ dictionary:
46+
47+ >>> bpd.options.compute.extra_query_labels["test3"] = False
48+ >>> bpd.options.compute.extra_query_labels
49+ {'test1': 1, 'test2': 'abc', 'test3': False}
50+
51+ To remove a label from the configuration, use the `del` keyword on the desired label key:
52+
53+ >>> del bpd.options.compute.extra_query_labels["test1"]
54+ >>> bpd.options.compute.extra_query_labels
55+ {'test2': 'abc', 'test3': False}
56+
3757 Attributes:
3858 maximum_bytes_billed (int, Options):
3959 Limits the bytes billed for query jobs. Queries that will have
@@ -44,7 +64,38 @@ class ComputeOptions:
4464 If enabled, large queries may be factored into multiple smaller queries
4565 in order to avoid generating queries that are too complex for the query
4666 engine to handle. However this comes at the cost of increase cost and latency.
67+ extra_query_labels (Dict[str, Any], Options):
68+ Stores additional custom labels for query configuration.
4769 """
4870
4971 maximum_bytes_billed : Optional [int ] = None
5072 enable_multi_query_execution : bool = False
73+ extra_query_labels : Dict [str , Any ] = dataclasses .field (
74+ default_factory = dict , init = False
75+ )
76+
77+ def assign_extra_query_labels (self , ** kwargs : Any ) -> None :
78+ """
79+ Assigns additional custom labels for query configuration. The method updates the
80+ `extra_query_labels` dictionary with new labels provided through keyword arguments.
81+
82+ Args:
83+ kwargs (Any):
84+ Custom labels provided as keyword arguments. Each key-value pair
85+ in `kwargs` represents a label name and its value.
86+
87+ Raises:
88+ ValueError: If a key matches one of the reserved attribute names,
89+ specifically 'maximum_bytes_billed' or 'enable_multi_query_execution',
90+ to prevent conflicts with built-in settings.
91+ """
92+ reserved_keys = ["maximum_bytes_billed" , "enable_multi_query_execution" ]
93+ for key in kwargs :
94+ if key in reserved_keys :
95+ raise ValueError (
96+ f"'{ key } ' is a reserved attribute name. Please use "
97+ "a different key for your custom labels to avoid "
98+ "conflicts with built-in settings."
99+ )
100+
101+ self .extra_query_labels .update (kwargs )
0 commit comments