Skip to content

Commit 9241326

Browse files
committed
address a few minor gemini concerns
1 parent 56b8e24 commit 9241326

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

sdks/python/apache_beam/yaml/yaml_mapping.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161

6262
_JS_DATE_ISO_REGEX = re.compile(
6363
r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$')
64+
_JS_IDENTIFIER_PATTERN = re.compile(r'^[a-zA-Z_$][a-zA-Z0-9_$]*$')
6465

6566
_str_expression_fields = {
6667
'AssignTimestamps': 'timestamp',
@@ -257,10 +258,9 @@ def __init__(self, fields, original_fields, input_schema):
257258
# that aren't compliant dot-access identifiers.
258259
if 'expression' in expr:
259260
e = expr['expression']
260-
js_identifier_pattern = re.compile(r'^[a-zA-Z_$][a-zA-Z0-9_$]*$')
261261
valid_fields = [
262262
n for n in original_fields
263-
if n in e and js_identifier_pattern.match(n)
263+
if n in e and _JS_IDENTIFIER_PATTERN.match(n)
264264
]
265265
consts = " ".join(
266266
[f"const {n} = __row__['{n}'];" for n in valid_fields])
@@ -775,6 +775,10 @@ def _PyJsMapToFields(
775775

776776
if language == 'javascript':
777777
options.YamlOptions.check_enabled(pcoll.pipeline, 'javascript')
778+
if MiniRacer is None:
779+
raise ValueError(
780+
"JavaScript mapping functions require the 'py-mini-racer' package to be installed."
781+
)
778782
return pcoll | beam.ParDo(
779783
JsMapToFieldsDoFn(fields, original_fields, input_schema))
780784

0 commit comments

Comments
 (0)