robertwb commented on code in PR #30035:
URL: https://github.com/apache/beam/pull/30035#discussion_r1457914435
##########
sdks/python/apache_beam/yaml/yaml_provider.py:
##########
@@ -665,6 +677,30 @@ def __init__(self, windowing):
def expand(self, pcoll):
return pcoll | self._window_transform
+ @staticmethod
+ def _parse_time_unit(value, name):
+ time_units = {
+ 'ms': 0.001, 's': 1, 'm': 60, 'h': 60 * 60, 'd': 60 * 60 * 12
+ }
+ value, suffix = re.match(r'^(.*?)([^\d]*)$', str(value)).groups()
+ # Default to seconds if time unit suffix is not defined
+ if not suffix:
+ suffix = 's'
+ if not value:
+ raise ValueError(
+ f"Invalid windowing {name} value "
+ f"'{suffix if not value else value}'. "
+ f"Must provide numeric value.")
+ if suffix not in time_units:
+ raise ValueError((
+ "Invalid windowing {} time unit '{}'. " +
+ "Valid time units are {}.").format(
+ name,
+ suffix,
+ ', '.join("'{}'".format(k) for k in time_units.keys())))
+ print(f'name: {name}\nvalue: {value}\nsuffix: {suffix}\n')
+ return float(value) * float(time_units[suffix])
Review Comment:
No need for the redundant float casting on `time_units[suffix]`.
##########
sdks/python/apache_beam/yaml/yaml_provider.py:
##########
@@ -665,6 +677,30 @@ def __init__(self, windowing):
def expand(self, pcoll):
return pcoll | self._window_transform
+ @staticmethod
+ def _parse_time_unit(value, name):
+ time_units = {
+ 'ms': 0.001, 's': 1, 'm': 60, 'h': 60 * 60, 'd': 60 * 60 * 12
+ }
+ value, suffix = re.match(r'^(.*?)([^\d]*)$', str(value)).groups()
+ # Default to seconds if time unit suffix is not defined
+ if not suffix:
+ suffix = 's'
+ if not value:
+ raise ValueError(
+ f"Invalid windowing {name} value "
+ f"'{suffix if not value else value}'. "
+ f"Must provide numeric value.")
+ if suffix not in time_units:
+ raise ValueError((
+ "Invalid windowing {} time unit '{}'. " +
+ "Valid time units are {}.").format(
+ name,
+ suffix,
+ ', '.join("'{}'".format(k) for k in time_units.keys())))
+ print(f'name: {name}\nvalue: {value}\nsuffix: {suffix}\n')
Review Comment:
Debugging?
##########
sdks/python/apache_beam/yaml/yaml_provider.py:
##########
@@ -665,6 +677,30 @@ def __init__(self, windowing):
def expand(self, pcoll):
return pcoll | self._window_transform
+ @staticmethod
+ def _parse_time_unit(value, name):
+ time_units = {
+ 'ms': 0.001, 's': 1, 'm': 60, 'h': 60 * 60, 'd': 60 * 60 * 12
+ }
+ value, suffix = re.match(r'^(.*?)([^\d]*)$', str(value)).groups()
+ # Default to seconds if time unit suffix is not defined
+ if not suffix:
+ suffix = 's'
+ if not value:
+ raise ValueError(
+ f"Invalid windowing {name} value "
+ f"'{suffix if not value else value}'. "
+ f"Must provide numeric value.")
+ if suffix not in time_units:
+ raise ValueError((
+ "Invalid windowing {} time unit '{}'. " +
+ "Valid time units are {}.").format(
+ name,
+ suffix,
+ ', '.join("'{}'".format(k) for k in time_units.keys())))
Review Comment:
You could probably just do `', '.join(time_units.keys())`.
##########
sdks/python/apache_beam/yaml/yaml_provider.py:
##########
@@ -48,7 +48,8 @@
from apache_beam.portability.api import schema_pb2
from apache_beam.transforms import external
from apache_beam.transforms import window
-from apache_beam.transforms.fully_qualified_named_transform import
FullyQualifiedNamedTransform
+from apache_beam.transforms.fully_qualified_named_transform import \
+ FullyQualifiedNamedTransform
Review Comment:
Imports are an exception to line length limits; keep it on the same line.
Also, don't use backslashes for line continuations:
https://google.github.io/styleguide/pyguide.html#32-line-length
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]