Skip to content

Commit 56b8e24

Browse files
committed
address more gemini comments
1 parent e0dd1f5 commit 56b8e24

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

sdks/python/apache_beam/yaml/yaml_mapping.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,14 @@ def __init__(self, fields, original_fields, input_schema):
257257
# that aren't compliant dot-access identifiers.
258258
if 'expression' in expr:
259259
e = expr['expression']
260-
code = f"var func_{i} = (__row__) => {{ " + " ".join(
261-
[f"const {n} = __row__['{n}'];"
262-
for n in original_fields if n in e]) + f" return ({e}); }}"
260+
js_identifier_pattern = re.compile(r'^[a-zA-Z_$][a-zA-Z0-9_$]*$')
261+
valid_fields = [
262+
n for n in original_fields
263+
if n in e and js_identifier_pattern.match(n)
264+
]
265+
consts = " ".join(
266+
[f"const {n} = __row__['{n}'];" for n in valid_fields])
267+
code = f"var func_{i} = (__row__) => {{ {consts} return ({e}); }}"
263268
script.append(code)
264269
self.field_funcs[name] = f"func_{i}"
265270
elif 'callable' in expr:

sdks/python/apache_beam/yaml/yaml_udf_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,9 @@ def test_map_to_fields_js_date(self):
396396

397397
expected_date = datetime.datetime(
398398
2026, 4, 17, 18, tzinfo=datetime.timezone.utc)
399+
assert_that(result, equal_to([
400+
beam.Row(date=expected_date),
401+
]))
399402

400403
@unittest.skipIf(MiniRacer is None, 'py_mini_racer not installed.')
401404
def test_map_to_fields_js_special_names(self):

0 commit comments

Comments
 (0)