33
33
)
34
34
import warnings
35
35
36
- import bigframes_vendored .constants as constants
37
36
import bigframes_vendored .ibis .backends .bigquery .datatypes as third_party_ibis_bqtypes
38
37
import bigframes_vendored .ibis .expr .datatypes as ibis_dtypes
39
38
import bigframes_vendored .ibis .expr .operations .udf as ibis_udf
49
48
from bigframes import clients
50
49
import bigframes .core .compile .ibis_types
51
50
import bigframes .exceptions as bfe
51
+ import bigframes .formatting_helpers as bf_formatting
52
52
import bigframes .series as bf_series
53
53
54
54
if TYPE_CHECKING :
@@ -87,9 +87,10 @@ def _resolve_bigquery_client(
87
87
if not bigquery_client :
88
88
bigquery_client = session .bqclient
89
89
if not bigquery_client :
90
- raise ValueError (
90
+ raise bf_formatting .create_exception_with_feedback_link (
91
+ ValueError ,
91
92
"A bigquery client must be provided, either directly or via "
92
- f "session. { constants . FEEDBACK_LINK } "
93
+ "session." ,
93
94
)
94
95
return bigquery_client
95
96
@@ -104,9 +105,10 @@ def _resolve_bigquery_connection_client(
104
105
if not bigquery_connection_client :
105
106
bigquery_connection_client = session .bqconnectionclient
106
107
if not bigquery_connection_client :
107
- raise ValueError (
108
+ raise bf_formatting .create_exception_with_feedback_link (
109
+ ValueError ,
108
110
"A bigquery connection client must be provided, either "
109
- f "directly or via session. { constants . FEEDBACK_LINK } "
111
+ "directly or via session." ,
110
112
)
111
113
return bigquery_connection_client
112
114
@@ -119,9 +121,10 @@ def _resolve_resource_manager_client(
119
121
if not resource_manager_client :
120
122
resource_manager_client = session .resourcemanagerclient
121
123
if not resource_manager_client :
122
- raise ValueError (
124
+ raise bf_formatting .create_exception_with_feedback_link (
125
+ ValueError ,
123
126
"A resource manager client must be provided, either directly "
124
- f "or via session. { constants . FEEDBACK_LINK } "
127
+ "or via session." ,
125
128
)
126
129
return resource_manager_client
127
130
@@ -149,9 +152,10 @@ def _resolve_cloud_functions_client(
149
152
if not cloud_functions_client :
150
153
cloud_functions_client = session .cloudfunctionsclient
151
154
if not cloud_functions_client :
152
- raise ValueError (
155
+ raise bf_formatting .create_exception_with_feedback_link (
156
+ ValueError ,
153
157
"A cloud functions client must be provided, either directly "
154
- f "or via session. { constants . FEEDBACK_LINK } "
158
+ "or via session." ,
155
159
)
156
160
return cloud_functions_client
157
161
@@ -178,14 +182,16 @@ def _resolve_bigquery_connection_id(
178
182
bq_connection_id ,
179
183
) = bigquery_connection .split ("." )
180
184
if gcp_project_id .casefold () != dataset_ref .project .casefold ():
181
- raise ValueError (
185
+ raise bf_formatting .create_exception_with_feedback_link (
186
+ ValueError ,
182
187
"The project_id does not match BigQuery connection "
183
- f"gcp_project_id: { dataset_ref .project } ."
188
+ f"gcp_project_id: { dataset_ref .project } ." ,
184
189
)
185
190
if bq_connection_location .casefold () != bq_location .casefold ():
186
- raise ValueError (
191
+ raise bf_formatting .create_exception_with_feedback_link (
192
+ ValueError ,
187
193
"The location does not match BigQuery connection location: "
188
- f"{ bq_location } ."
194
+ f"{ bq_location } ." ,
189
195
)
190
196
return bq_connection_id
191
197
@@ -506,9 +512,10 @@ def remote_function(
506
512
cloud_function_kms_key_name is not None
507
513
and cloud_function_docker_repository is None
508
514
):
509
- raise ValueError (
515
+ raise bf_formatting .create_exception_with_feedback_link (
516
+ ValueError ,
510
517
"cloud_function_docker_repository must be specified with cloud_function_kms_key_name."
511
- " For more details see https://cloud.google.com/functions/docs/securing/cmek#before_you_begin"
518
+ " For more details see https://cloud.google.com/functions/docs/securing/cmek#before_you_begin." ,
512
519
)
513
520
514
521
if cloud_function_ingress_settings is None :
@@ -521,13 +528,25 @@ def remote_function(
521
528
)
522
529
warnings .warn (msg , category = FutureWarning , stacklevel = 2 )
523
530
531
+ if cloud_function_ingress_settings is None :
532
+ cloud_function_ingress_settings = "all"
533
+ msg = bfe .format_message (
534
+ "The `cloud_function_ingress_settings` are set to 'all' by default, "
535
+ "which will change to 'internal-only' for enhanced security in future version 2.0 onwards. "
536
+ "However, you will be able to explicitly pass cloud_function_ingress_settings='all' if you need. "
537
+ "See https://cloud.google.com/functions/docs/networking/network-settings#ingress_settings for details."
538
+ )
539
+ warnings .warn (msg , category = FutureWarning , stacklevel = 2 )
540
+
524
541
bq_connection_manager = session .bqconnectionmanager
525
542
526
543
def wrapper (func ):
527
544
nonlocal input_types , output_type
528
545
529
546
if not callable (func ):
530
- raise TypeError ("f must be callable, got {}" .format (func ))
547
+ raise bf_formatting .create_exception_with_feedback_link (
548
+ TypeError , f"func must be a callable, got { func } "
549
+ )
531
550
532
551
if sys .version_info >= (3 , 10 ):
533
552
# Add `eval_str = True` so that deferred annotations are turned into their
@@ -547,10 +566,11 @@ def wrapper(func):
547
566
input_types = []
548
567
for parameter in signature .parameters .values ():
549
568
if (param_type := parameter .annotation ) is inspect .Signature .empty :
550
- raise ValueError (
569
+ raise bf_formatting .create_exception_with_feedback_link (
570
+ ValueError ,
551
571
"'input_types' was not set and parameter "
552
572
f"'{ parameter .name } ' is missing a type annotation. "
553
- "Types are required to use @remote_function."
573
+ "Types are required to use @remote_function." ,
554
574
)
555
575
input_types .append (param_type )
556
576
elif not isinstance (input_types , collections .abc .Sequence ):
@@ -560,10 +580,11 @@ def wrapper(func):
560
580
if (
561
581
output_type := signature .return_annotation
562
582
) is inspect .Signature .empty :
563
- raise ValueError (
583
+ raise bf_formatting .create_exception_with_feedback_link (
584
+ ValueError ,
564
585
"'output_type' was not set and function is missing a "
565
586
"return type annotation. Types are required to use "
566
- "@remote_function."
587
+ "@remote_function." ,
567
588
)
568
589
569
590
# The function will actually be receiving a pandas Series, but allow both
@@ -789,14 +810,15 @@ def udf(
789
810
https://pip.pypa.io/en/stable/reference/requirements-file-format/.
790
811
"""
791
812
if not bigframes .options .experiments .udf :
792
- raise NotImplementedError ( )
813
+ raise bf_formatting . create_exception_with_feedback_link ( NotImplementedError )
793
814
794
815
# Check the Python version.
795
816
python_version = _utils .get_python_version ()
796
817
if python_version not in _MANAGED_FUNC_PYTHON_VERSIONS :
797
- raise RuntimeError (
818
+ raise bf_formatting .create_exception_with_feedback_link (
819
+ RuntimeError ,
798
820
f"Python version { python_version } is not supported yet for "
799
- "BigFrames managed function."
821
+ "BigFrames managed function." ,
800
822
)
801
823
802
824
# Some defaults may be used from the session if not provided otherwise.
@@ -823,7 +845,9 @@ def wrapper(func):
823
845
nonlocal input_types , output_type
824
846
825
847
if not callable (func ):
826
- raise TypeError ("f must be callable, got {}" .format (func ))
848
+ raise bf_formatting .create_exception_with_feedback_link (
849
+ TypeError , f"func must be a callable, got { func } "
850
+ )
827
851
828
852
# Managed function supports version >= 3.11.
829
853
signature_kwargs : Mapping [str , Any ] = {"eval_str" : True }
@@ -834,10 +858,11 @@ def wrapper(func):
834
858
input_types = []
835
859
for parameter in signature .parameters .values ():
836
860
if (param_type := parameter .annotation ) is inspect .Signature .empty :
837
- raise ValueError (
861
+ raise bf_formatting .create_exception_with_feedback_link (
862
+ ValueError ,
838
863
"'input_types' was not set and parameter "
839
864
f"'{ parameter .name } ' is missing a type annotation. "
840
- "Types are required to use managed function."
865
+ "Types are required to use managed function." ,
841
866
)
842
867
input_types .append (param_type )
843
868
elif not isinstance (input_types , collections .abc .Sequence ):
@@ -847,10 +872,11 @@ def wrapper(func):
847
872
if (
848
873
output_type := signature .return_annotation
849
874
) is inspect .Signature .empty :
850
- raise ValueError (
875
+ raise bf_formatting .create_exception_with_feedback_link (
876
+ ValueError ,
851
877
"'output_type' was not set and function is missing a "
852
878
"return type annotation. Types are required to use "
853
- "managed function."
879
+ "managed function." ,
854
880
)
855
881
856
882
# The function will actually be receiving a pandas Series, but allow
0 commit comments