You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2020/09/10 16:54:08 UTC

[GitHub] [beam] y1chi commented on a change in pull request #12807: [BEAM-2855] implement query 10

y1chi commented on a change in pull request #12807:
URL: https://github.com/apache/beam/pull/12807#discussion_r486491662



##########
File path: sdks/python/apache_beam/testing/benchmarks/nexmark/queries/query10.py
##########
@@ -0,0 +1,136 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+"""
+Query 10, 'Log to sharded files' (Not in original suite.)
+
+Every window_size_sec, save all events from the last period into
+2*max_workers log files.
+"""
+
+from __future__ import absolute_import
+
+import apache_beam as beam
+from apache_beam.options.pipeline_options import GoogleCloudOptions
+from apache_beam.transforms import trigger
+from apache_beam.transforms import window
+from apache_beam.utils.timestamp import Duration
+
+NUM_SHARD_PER_WORKER = 5
+LATE_BATCHING_PERIOD = Duration.of(10)
+
+output_path = None
+max_num_workers = 5
+
+num_log_shards = NUM_SHARD_PER_WORKER * max_num_workers
+
+
+class OutputFile(object):
+  def __init__(self, max_timestamp, shard, index, timing, filename):
+    self.max_timestamp = max_timestamp
+    self.shard = shard
+    self.index = index
+    self.timing = timing
+    self.filename = filename
+
+
+def open_writable_gcs_file(options, filename):
+  # TODO: it seems that beam team has not yet decided about this method and
+  #   it is left blank and unspecified.
+  pass
+
+
+def output_file_for(window, shard, pane):

Review comment:
       nit: add some documentation on what the function is used for.

##########
File path: sdks/python/apache_beam/testing/benchmarks/nexmark/queries/query10.py
##########
@@ -0,0 +1,136 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+"""
+Query 10, 'Log to sharded files' (Not in original suite.)
+
+Every window_size_sec, save all events from the last period into
+2*max_workers log files.
+"""
+
+from __future__ import absolute_import
+
+import apache_beam as beam
+from apache_beam.options.pipeline_options import GoogleCloudOptions
+from apache_beam.transforms import trigger
+from apache_beam.transforms import window
+from apache_beam.utils.timestamp import Duration
+
+NUM_SHARD_PER_WORKER = 5
+LATE_BATCHING_PERIOD = Duration.of(10)
+
+output_path = None
+max_num_workers = 5
+
+num_log_shards = NUM_SHARD_PER_WORKER * max_num_workers
+
+
+class OutputFile(object):
+  def __init__(self, max_timestamp, shard, index, timing, filename):
+    self.max_timestamp = max_timestamp
+    self.shard = shard
+    self.index = index
+    self.timing = timing
+    self.filename = filename
+
+
+def open_writable_gcs_file(options, filename):
+  # TODO: it seems that beam team has not yet decided about this method and

Review comment:
       Could you link or open a jira issue regarding this and comment it here?

##########
File path: sdks/python/apache_beam/testing/benchmarks/nexmark/queries/query10.py
##########
@@ -0,0 +1,136 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+"""
+Query 10, 'Log to sharded files' (Not in original suite.)
+
+Every window_size_sec, save all events from the last period into
+2*max_workers log files.
+"""
+
+from __future__ import absolute_import
+
+import apache_beam as beam
+from apache_beam.options.pipeline_options import GoogleCloudOptions
+from apache_beam.transforms import trigger
+from apache_beam.transforms import window
+from apache_beam.utils.timestamp import Duration
+
+NUM_SHARD_PER_WORKER = 5
+LATE_BATCHING_PERIOD = Duration.of(10)
+
+output_path = None
+max_num_workers = 5
+
+num_log_shards = NUM_SHARD_PER_WORKER * max_num_workers
+
+
+class OutputFile(object):
+  def __init__(self, max_timestamp, shard, index, timing, filename):
+    self.max_timestamp = max_timestamp
+    self.shard = shard
+    self.index = index
+    self.timing = timing
+    self.filename = filename
+
+
+def open_writable_gcs_file(options, filename):
+  # TODO: it seems that beam team has not yet decided about this method and
+  #   it is left blank and unspecified.
+  pass
+
+
+def output_file_for(window, shard, pane):
+  filename = '%s/LOG-%s-%s-%03d-%s' % (
+      output_path, window.max_timestamp(), shard, pane.index,
+      pane.timing) if output_path else None
+  return OutputFile(
+      window.max_timestamp(), shard, pane.index, pane.timing, filename)
+
+
+def index_path_for(window):
+  if output_path:
+    return '%s/INDEX-%s' % (output_path, window.max_timestamp())
+  else:
+    return None
+
+
+def load(events, pipeline_options, metadata=None):
+  return (
+      events
+      | 'query10_shard_events' >> beam.ParDo(ShardEventsDoFn())
+      | 'query10_fix_window' >> beam.WindowInto(
+          window.FixedWindows(metadata.get('window_size_sec')),
+          trigger=trigger.AfterEach(

Review comment:
       Can we add a comment on the desired behavior of this trigger as well?




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org