You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "charlespnh (via GitHub)" <gi...@apache.org> on 2025/06/04 14:05:22 UTC
[PR] Add more YAML examples involving Kafka and Iceberg [beam]
charlespnh opened a new pull request, #35151:
URL: https://github.com/apache/beam/pull/35151
**Please** add a meaningful description for your change here
Part of a larger effort https://github.com/apache/beam/issues/35068 to add more YAML examples involving Kafka and Iceberg
------------------------
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
- [ ] Mention the appropriate issue in your description (for example: `addresses #123`), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment `fixes #<ISSUE NUMBER>` instead.
- [ ] Update `CHANGES.md` with noteworthy changes.
- [ ] If this contribution is large, please file an Apache [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
See the [Contributor Guide](https://beam.apache.org/contribute) for more tips on [how to make review process smoother](https://github.com/apache/beam/blob/master/CONTRIBUTING.md#make-the-reviewers-job-easier).
To check the build health, please visit [https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md](https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md)
GitHub Actions Tests Status (on master branch)
------------------------------------------------------------------------------------------------
[](https://github.com/apache/beam/actions?query=workflow%3A%22Build+python+source+distribution+and+wheels%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Python+Tests%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Java+Tests%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Go+tests%22+branch%3Amaster+event%3Aschedule)
See [CI.md](https://github.com/apache/beam/blob/master/CI.md) for more information about GitHub Actions CI or the [workflows README](https://github.com/apache/beam/blob/master/.github/workflows/README.md) to see a list of phrases to trigger workflows.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add more YAML examples involving Kafka and Iceberg [beam]
Posted by "chamikaramj (via GitHub)" <gi...@apache.org>.
chamikaramj commented on code in PR #35151:
URL: https://github.com/apache/beam/pull/35151#discussion_r2129410914
##########
sdks/python/apache_beam/yaml/examples/README.md:
##########
@@ -71,25 +79,173 @@ Examples in this directory show off the various built-in transforms of the Beam
YAML framework.
### Aggregation
+
These examples leverage the built-in `Combine` transform for performing simple
aggregations including sum, mean, count, etc.
### Blueprints
+
These examples leverage DF or other existing templates and convert them to yaml
blueprints.
### Element-wise
+
These examples leverage the built-in mapping transforms including `MapToFields`,
`Filter` and `Explode`. More information can be found about mapping transforms
[here](https://beam.apache.org/documentation/sdks/yaml-udf/).
### IO
-These examples leverage the built-in `Spanner_Read` and `Spanner_Write`
-transform for performing simple reads and writes from a spanner DB.
+
+#### Spanner
+
+Examples [Spanner Read](transforms/io/spanner_read.yaml) and [Spanner Write](
+transforms/io/spanner_write.yaml) leverage the built-in `Spanner_Read` and
+`Spanner_Write` transform for performing simple reads and writes from a spanner
Review Comment:
nit: s/transform/transforms
##########
sdks/python/apache_beam/yaml/examples/README.md:
##########
@@ -71,25 +79,173 @@ Examples in this directory show off the various built-in transforms of the Beam
YAML framework.
### Aggregation
+
These examples leverage the built-in `Combine` transform for performing simple
aggregations including sum, mean, count, etc.
### Blueprints
+
These examples leverage DF or other existing templates and convert them to yaml
blueprints.
### Element-wise
+
These examples leverage the built-in mapping transforms including `MapToFields`,
`Filter` and `Explode`. More information can be found about mapping transforms
[here](https://beam.apache.org/documentation/sdks/yaml-udf/).
### IO
-These examples leverage the built-in `Spanner_Read` and `Spanner_Write`
-transform for performing simple reads and writes from a spanner DB.
+
+#### Spanner
+
+Examples [Spanner Read](transforms/io/spanner_read.yaml) and [Spanner Write](
+transforms/io/spanner_write.yaml) leverage the built-in `Spanner_Read` and
+`Spanner_Write` transform for performing simple reads and writes from a spanner
+DB.
+
+#### Kafka
+
+Examples involving Kafka such as [Streaming Wordcount](streaming_wordcount.yaml)
+and [Kafka Read Write](transforms/io/kafka.yaml) require users to set up
+a Kafka cluster that Dataflow runner executing the
+Beam pipeline has access to. See
+issue [here](https://github.com/apache/beam/issues/22809) for context on running
Review Comment:
Probably change this sentence to.
Please note that \`ReadFromKafka\` transform has a \[known issue\](https://github.com/apache/beam/issues/22809) when using non-Dataflow portable runners where reading may get stuck in streaming pipelines. Hence we recommend using the Dataflow runner for examples that involve reading from Kafka in a streaming pipeline.
##########
sdks/python/apache_beam/yaml/examples/streaming_wordcount.yaml:
##########
@@ -0,0 +1,97 @@
+# coding=utf-8
+#
+# 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.
+#
+
+pipeline:
+ type: chain
+ transforms:
+ # Assuming the given topic exists with the following message JSON schema,
+ # read the records from Kafka
+ - type: ReadFromKafka
+ config:
+ format: JSON
+ schema: |
+ {
+ "type": "object",
+ "properties": {
+ "value": {"type": "string"}
+ }
+ }
+ topic: {{ TOPIC }}
+ bootstrap_servers: {{ BOOTSTRAP_SERVERS }}
+ auto_offset_reset_config: earliest
+ consumer_config:
+ sasl.jaas.config: "org.apache.kafka.common.security.plain.PlainLoginModule required \
+ username={{ USERNAME }} \
+ password={{ PASSWORD }};"
+ security.protocol: "SASL_PLAINTEXT"
+ sasl.mechanism: "PLAIN"
+
+ # Split line field in each row into list of words.
Review Comment:
\`value\` field
##########
sdks/python/apache_beam/yaml/examples/README.md:
##########
@@ -71,25 +79,173 @@ Examples in this directory show off the various built-in transforms of the Beam
YAML framework.
### Aggregation
+
These examples leverage the built-in `Combine` transform for performing simple
aggregations including sum, mean, count, etc.
### Blueprints
+
These examples leverage DF or other existing templates and convert them to yaml
blueprints.
### Element-wise
+
These examples leverage the built-in mapping transforms including `MapToFields`,
`Filter` and `Explode`. More information can be found about mapping transforms
[here](https://beam.apache.org/documentation/sdks/yaml-udf/).
### IO
-These examples leverage the built-in `Spanner_Read` and `Spanner_Write`
-transform for performing simple reads and writes from a spanner DB.
+
+#### Spanner
+
+Examples [Spanner Read](transforms/io/spanner_read.yaml) and [Spanner Write](
+transforms/io/spanner_write.yaml) leverage the built-in `Spanner_Read` and
+`Spanner_Write` transform for performing simple reads and writes from a spanner
Review Comment:
s/spanner DB/Google Spanner database
##########
sdks/python/apache_beam/yaml/examples/transforms/io/kafka.yaml:
##########
@@ -0,0 +1,87 @@
+# coding=utf-8
+#
+# 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.
+#
+
+# A non-linear pipeline that both writes to and reads from the same Kafka topic.
+
+pipeline:
+ transforms:
+ - type: ReadFromText
+ name: ReadFromGCS
+ config:
+ path: gs://dataflow-samples/shakespeare/kinglear.txt
+
+ - type: MapToFields
+ name: BuildKafkaRecords
+ input: ReadFromGCS
+ config:
+ language: python
+ fields:
+ value:
+ callable: |
+ def func(row):
+ return row.line.encode('utf-8')
+ output_type: bytes
+
+ - type: WriteToKafka
+ name: SendRecordsToKafka
+ input: BuildKafkaRecords
+ config:
+ format: RAW
+ topic: {{ TOPIC }}
+ bootstrap_servers: {{ BOOTSTRAP_SERVERS }}
+ producer_config_updates:
+ sasl.jaas.config: "org.apache.kafka.common.security.plain.PlainLoginModule required \
+ username={{ USERNAME }} \
+ password={{ PASSWORD }};"
+ security.protocol: "SASL_PLAINTEXT"
+ sasl.mechanism: "PLAIN"
+
+ - type: ReadFromKafka
+ name: ReadFromMyTopic
+ config:
+ format: RAW
+ topic: {{ TOPIC }}
+ bootstrap_servers: {{ BOOTSTRAP_SERVERS }}
+ auto_offset_reset_config: earliest
+ consumer_config:
+ sasl.jaas.config: "org.apache.kafka.common.security.plain.PlainLoginModule required \
+ username={{ USERNAME }} \
+ password={{ PASSWORD }};"
+ security.protocol: "SASL_PLAINTEXT"
+ sasl.mechanism: "PLAIN"
+
+ - type: MapToFields
+ name: ParseKafkaRecords
+ input: ReadFromMyTopic
+ config:
+ language: python
+ fields:
+ text:
+ callable: |
+ def func(row):
+ return row.payload.decode('utf-8')
+
+ - type: LogForTesting
+ input: ParseKafkaRecords
+
+# Expected:
+# Row(text="\tLook there, look there!")
+# Row(text="\tNever, never, never, never, never!")
Review Comment:
Let's add instructions regarding pushing this data into the Iceberg table for testing.
##########
sdks/python/apache_beam/yaml/examples/transforms/io/iceberg_write.yaml:
##########
@@ -0,0 +1,45 @@
+# coding=utf-8
+#
+# 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.
+#
+
+pipeline:
+ type: chain
+ transforms:
+ - type: Create
+ name: CreateSampleData
+ config:
+ elements:
+ - { id: 1, name: "John", email: "john@example.com", zip: "WA" }
+ - { id: 2, name: "Jane", email: "jane@example.com", zip: "CA" }
+ - { id: 3, name: "Beamberg", email: "beamberg@example.com", zip: "NY" }
+
+ - type: LogForTesting
+
+ - type: WriteToIceberg
+ name: WriteToAnIcebergTable
+ config:
+ # Dynamic destinations
+ table: "demo.users.{zip}"
+ catalog_name: "hadoop_catalog"
+ catalog_properties:
+ type: "hadoop"
+ warehouse: "gs://MY-WAREHOUSE"
Review Comment:
Let's clearly identify the things used have to set, may be in a comment at the top of the file (in here and other examples).
##########
sdks/python/apache_beam/yaml/examples/streaming_wordcount.yaml:
##########
@@ -0,0 +1,97 @@
+# coding=utf-8
+#
+# 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.
+#
+
+pipeline:
+ type: chain
+ transforms:
+ # Assuming the given topic exists with the following message JSON schema,
+ # read the records from Kafka
+ - type: ReadFromKafka
+ config:
+ format: JSON
+ schema: |
+ {
+ "type": "object",
+ "properties": {
+ "value": {"type": "string"}
+ }
+ }
+ topic: {{ TOPIC }}
+ bootstrap_servers: {{ BOOTSTRAP_SERVERS }}
+ auto_offset_reset_config: earliest
+ consumer_config:
+ sasl.jaas.config: "org.apache.kafka.common.security.plain.PlainLoginModule required \
+ username={{ USERNAME }} \
+ password={{ PASSWORD }};"
+ security.protocol: "SASL_PLAINTEXT"
+ sasl.mechanism: "PLAIN"
+
+ # Split line field in each row into list of words.
+ - type: MapToFields
+ config:
+ language: python
+ fields:
+ words:
+ callable: |
+ import re
+ def my_mapping(row):
+ return re.findall(r"[A-Za-z\']+", row.value.lower())
+
+ # Explode each list of words into separate rows.
+ - type: Explode
+ config:
+ fields: words
+
+ # Since each word is now distinct row, rename field to "word".
+ - type: MapToFields
+ config:
+ fields:
+ word: words
+
+ # With an unbounded source such as Kafka, a window is required for
+ # any subsequent GroupBy transform.
+ - type: WindowInto
+ name: Windowing
+ windowing:
+ type: fixed
+ size: 3s
+
+ # Group by distinct words in the collection and add field "count" that
+ # contains number of instances, or count, for each word in the collection.
+ - type: Combine
+ config:
+ language: python
+ group_by: word
+ combine:
+ count:
+ value: word
+ fn: count
+
+ - type: LogForTesting
+
+# Expected:
+# Row(word='king', count=311)
Review Comment:
Should we also add instructions for pushing to data into the Kafka cluster ? Otherwise this example will be less useful.
##########
sdks/python/apache_beam/yaml/examples/streaming_wordcount.yaml:
##########
@@ -0,0 +1,97 @@
+# coding=utf-8
+#
+# 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.
+#
+
+pipeline:
+ type: chain
+ transforms:
+ # Assuming the given topic exists with the following message JSON schema,
+ # read the records from Kafka
+ - type: ReadFromKafka
+ config:
+ format: JSON
+ schema: |
+ {
+ "type": "object",
+ "properties": {
+ "value": {"type": "string"}
+ }
+ }
+ topic: {{ TOPIC }}
+ bootstrap_servers: {{ BOOTSTRAP_SERVERS }}
+ auto_offset_reset_config: earliest
+ consumer_config:
+ sasl.jaas.config: "org.apache.kafka.common.security.plain.PlainLoginModule required \
+ username={{ USERNAME }} \
+ password={{ PASSWORD }};"
+ security.protocol: "SASL_PLAINTEXT"
+ sasl.mechanism: "PLAIN"
+
+ # Split line field in each row into list of words.
+ - type: MapToFields
+ config:
+ language: python
+ fields:
+ words:
+ callable: |
+ import re
+ def my_mapping(row):
+ return re.findall(r"[A-Za-z\']+", row.value.lower())
+
+ # Explode each list of words into separate rows.
+ - type: Explode
+ config:
+ fields: words
+
+ # Since each word is now distinct row, rename field to "word".
+ - type: MapToFields
+ config:
+ fields:
+ word: words
+
+ # With an unbounded source such as Kafka, a window is required for
+ # any subsequent GroupBy transform.
+ - type: WindowInto
+ name: Windowing
+ windowing:
+ type: fixed
+ size: 3s
Review Comment:
Probably make this a bit larger. We use 15 seconds in other Kafka examples.
##########
sdks/python/apache_beam/yaml/examples/README.md:
##########
@@ -71,25 +79,173 @@ Examples in this directory show off the various built-in transforms of the Beam
YAML framework.
### Aggregation
+
These examples leverage the built-in `Combine` transform for performing simple
aggregations including sum, mean, count, etc.
### Blueprints
+
These examples leverage DF or other existing templates and convert them to yaml
blueprints.
### Element-wise
+
These examples leverage the built-in mapping transforms including `MapToFields`,
`Filter` and `Explode`. More information can be found about mapping transforms
[here](https://beam.apache.org/documentation/sdks/yaml-udf/).
### IO
-These examples leverage the built-in `Spanner_Read` and `Spanner_Write`
-transform for performing simple reads and writes from a spanner DB.
+
+#### Spanner
+
+Examples [Spanner Read](transforms/io/spanner_read.yaml) and [Spanner Write](
+transforms/io/spanner_write.yaml) leverage the built-in `Spanner_Read` and
+`Spanner_Write` transform for performing simple reads and writes from a spanner
+DB.
+
+#### Kafka
+
+Examples involving Kafka such as [Streaming Wordcount](streaming_wordcount.yaml)
+and [Kafka Read Write](transforms/io/kafka.yaml) require users to set up
+a Kafka cluster that Dataflow runner executing the
+Beam pipeline has access to. See
+issue [here](https://github.com/apache/beam/issues/22809) for context on running
+streaming pipelines with Kafka on Dataflow runner vs. portable runners.
+
+See [here](https://kafka.apache.org/quickstart) for general instructions on
+setting up a Kafka cluster. An option is to use [Click to Deploy](
+https://console.cloud.google.com/marketplace/details/click-to-deploy-images/kafka?)
+to quickly launch a Kafka cluster on [GCE](
+https://cloud.google.com/products/compute?hl=en). [SASL/PLAIN](
+https://kafka.apache.org/documentation/#security_sasl_plain) authentication
+mechanism is configured for the brokers as part of the deployment. See
+also [here](
+https://github.com/GoogleCloudPlatform/java-docs-samples/tree/main/dataflow/flex-templates/kafka_to_bigquery)
+for an alternative step-by-step guide on setting up Kafka on GCE without the
+authentication mechanism.
+
+Let's assume one of the bootstrap servers is on VM instance `kafka-vm-0`
+with the internal IP address `123.45.67.89` and port `9092` that the bootstrap
+server is listening on. SASL/PLAIN `USERNAME` and `PASSWORD` can be viewed from
+the VM instance's metadata on the GCE console, or with gcloud CLI:
+
+```sh
+gcloud compute instances describe kafka-vm-0 \
+ --format='value[](metadata.items.kafka-user)'
+gcloud compute instances describe kafka-vm-0 \
+ --format='value[](metadata.items.kafka-password)'
+```
+
+Beam pipeline [Streaming Wordcount](streaming_wordcount.yaml) reads from an
+existing Kafka topic `MY-TOPIC` containing lines of text and then applies
+transformation logic similar to [Wordcount](wordcount_minimal.yaml) example,
+before finally logs out the output. Run the pipeline:
+
+```sh
+export PROJECT="$(gcloud config get-value project)"
+export TEMP_LOCATION="gs://MY-BUCKET/tmp"
+export REGION="us-central1"
+export JOB_NAME="streaming-wordcount-`date +%Y%m%d-%H%M%S`"
+export NUM_WORKERS="1"
+
+python -m apache_beam.yaml.main \
+ --yaml_pipeline_file streaming_wordcount.yaml \
+ --runner DataflowRunner \
+ --temp_location $TEMP_LOCATION \
+ --project $PROJECT \
+ --region $REGION \
+ --num_workers $NUM_WORKERS \
+ --job_name $JOB_NAME \
+ --jinja_variables '{ "BOOTSTRAP_SERVERS": "123.45.67.89:9092",
Review Comment:
Probably also put the IP to an environmental variable so that someone can quickly modify.
##########
sdks/python/apache_beam/yaml/examples/README.md:
##########
@@ -71,25 +79,173 @@ Examples in this directory show off the various built-in transforms of the Beam
YAML framework.
### Aggregation
+
These examples leverage the built-in `Combine` transform for performing simple
aggregations including sum, mean, count, etc.
### Blueprints
+
These examples leverage DF or other existing templates and convert them to yaml
blueprints.
### Element-wise
+
These examples leverage the built-in mapping transforms including `MapToFields`,
`Filter` and `Explode`. More information can be found about mapping transforms
[here](https://beam.apache.org/documentation/sdks/yaml-udf/).
### IO
-These examples leverage the built-in `Spanner_Read` and `Spanner_Write`
-transform for performing simple reads and writes from a spanner DB.
+
+#### Spanner
+
+Examples [Spanner Read](transforms/io/spanner_read.yaml) and [Spanner Write](
+transforms/io/spanner_write.yaml) leverage the built-in `Spanner_Read` and
+`Spanner_Write` transform for performing simple reads and writes from a spanner
+DB.
+
+#### Kafka
+
+Examples involving Kafka such as [Streaming Wordcount](streaming_wordcount.yaml)
+and [Kafka Read Write](transforms/io/kafka.yaml) require users to set up
+a Kafka cluster that Dataflow runner executing the
+Beam pipeline has access to. See
+issue [here](https://github.com/apache/beam/issues/22809) for context on running
+streaming pipelines with Kafka on Dataflow runner vs. portable runners.
+
+See [here](https://kafka.apache.org/quickstart) for general instructions on
+setting up a Kafka cluster. An option is to use [Click to Deploy](
+https://console.cloud.google.com/marketplace/details/click-to-deploy-images/kafka?)
+to quickly launch a Kafka cluster on [GCE](
+https://cloud.google.com/products/compute?hl=en). [SASL/PLAIN](
+https://kafka.apache.org/documentation/#security_sasl_plain) authentication
+mechanism is configured for the brokers as part of the deployment. See
+also [here](
+https://github.com/GoogleCloudPlatform/java-docs-samples/tree/main/dataflow/flex-templates/kafka_to_bigquery)
+for an alternative step-by-step guide on setting up Kafka on GCE without the
+authentication mechanism.
+
+Let's assume one of the bootstrap servers is on VM instance `kafka-vm-0`
+with the internal IP address `123.45.67.89` and port `9092` that the bootstrap
+server is listening on. SASL/PLAIN `USERNAME` and `PASSWORD` can be viewed from
+the VM instance's metadata on the GCE console, or with gcloud CLI:
+
+```sh
+gcloud compute instances describe kafka-vm-0 \
+ --format='value[](metadata.items.kafka-user)'
+gcloud compute instances describe kafka-vm-0 \
+ --format='value[](metadata.items.kafka-password)'
+```
+
+Beam pipeline [Streaming Wordcount](streaming_wordcount.yaml) reads from an
+existing Kafka topic `MY-TOPIC` containing lines of text and then applies
+transformation logic similar to [Wordcount](wordcount_minimal.yaml) example,
+before finally logs out the output. Run the pipeline:
+
+```sh
+export PROJECT="$(gcloud config get-value project)"
+export TEMP_LOCATION="gs://MY-BUCKET/tmp"
+export REGION="us-central1"
+export JOB_NAME="streaming-wordcount-`date +%Y%m%d-%H%M%S`"
+export NUM_WORKERS="1"
+
+python -m apache_beam.yaml.main \
+ --yaml_pipeline_file streaming_wordcount.yaml \
+ --runner DataflowRunner \
+ --temp_location $TEMP_LOCATION \
+ --project $PROJECT \
+ --region $REGION \
+ --num_workers $NUM_WORKERS \
+ --job_name $JOB_NAME \
+ --jinja_variables '{ "BOOTSTRAP_SERVERS": "123.45.67.89:9092",
+ "TOPIC": "MY-TOPIC", "USERNAME": "USERNAME", "PASSWORD": "PASSWORD" }'
+```
+
+Beam pipeline [Kafka Read Write](transforms/io/kafka.yaml) is a non-linear
Review Comment:
Probably change
is a non-linear
pipeline that both writes to and reads from the same Kafka topic
to
first write data to the Kafka topic using the \`WriteToKafka\` transform and then reads that data back using the \`ReadFromKafka\` transform.
##########
sdks/python/apache_beam/yaml/examples/transforms/io/iceberg_read.yaml:
##########
@@ -0,0 +1,41 @@
+# coding=utf-8
+#
+# 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.
+#
+
+pipeline:
+ type: chain
+ transforms:
+ - type: ReadFromIceberg
+ name: ReadFromAnIcebergTable
+ config:
+ table: "demo.users.NY"
+ catalog_name: "hadoop_catalog"
+ catalog_properties:
+ type: "hadoop"
Review Comment:
Also add instructions regarding creating the warehouse/table and pushing data into it ?
##########
sdks/python/apache_beam/yaml/examples/README.md:
##########
@@ -71,25 +79,173 @@ Examples in this directory show off the various built-in transforms of the Beam
YAML framework.
### Aggregation
+
These examples leverage the built-in `Combine` transform for performing simple
aggregations including sum, mean, count, etc.
### Blueprints
+
These examples leverage DF or other existing templates and convert them to yaml
blueprints.
### Element-wise
+
These examples leverage the built-in mapping transforms including `MapToFields`,
`Filter` and `Explode`. More information can be found about mapping transforms
[here](https://beam.apache.org/documentation/sdks/yaml-udf/).
### IO
-These examples leverage the built-in `Spanner_Read` and `Spanner_Write`
-transform for performing simple reads and writes from a spanner DB.
+
+#### Spanner
+
+Examples [Spanner Read](transforms/io/spanner_read.yaml) and [Spanner Write](
+transforms/io/spanner_write.yaml) leverage the built-in `Spanner_Read` and
+`Spanner_Write` transform for performing simple reads and writes from a spanner
+DB.
+
+#### Kafka
+
+Examples involving Kafka such as [Streaming Wordcount](streaming_wordcount.yaml)
+and [Kafka Read Write](transforms/io/kafka.yaml) require users to set up
+a Kafka cluster that Dataflow runner executing the
+Beam pipeline has access to. See
+issue [here](https://github.com/apache/beam/issues/22809) for context on running
+streaming pipelines with Kafka on Dataflow runner vs. portable runners.
+
+See [here](https://kafka.apache.org/quickstart) for general instructions on
+setting up a Kafka cluster. An option is to use [Click to Deploy](
+https://console.cloud.google.com/marketplace/details/click-to-deploy-images/kafka?)
+to quickly launch a Kafka cluster on [GCE](
+https://cloud.google.com/products/compute?hl=en). [SASL/PLAIN](
+https://kafka.apache.org/documentation/#security_sasl_plain) authentication
+mechanism is configured for the brokers as part of the deployment. See
+also [here](
+https://github.com/GoogleCloudPlatform/java-docs-samples/tree/main/dataflow/flex-templates/kafka_to_bigquery)
+for an alternative step-by-step guide on setting up Kafka on GCE without the
+authentication mechanism.
+
+Let's assume one of the bootstrap servers is on VM instance `kafka-vm-0`
+with the internal IP address `123.45.67.89` and port `9092` that the bootstrap
+server is listening on. SASL/PLAIN `USERNAME` and `PASSWORD` can be viewed from
+the VM instance's metadata on the GCE console, or with gcloud CLI:
+
+```sh
+gcloud compute instances describe kafka-vm-0 \
+ --format='value[](metadata.items.kafka-user)'
+gcloud compute instances describe kafka-vm-0 \
+ --format='value[](metadata.items.kafka-password)'
+```
+
+Beam pipeline [Streaming Wordcount](streaming_wordcount.yaml) reads from an
+existing Kafka topic `MY-TOPIC` containing lines of text and then applies
+transformation logic similar to [Wordcount](wordcount_minimal.yaml) example,
+before finally logs out the output. Run the pipeline:
+
+```sh
+export PROJECT="$(gcloud config get-value project)"
+export TEMP_LOCATION="gs://MY-BUCKET/tmp"
+export REGION="us-central1"
+export JOB_NAME="streaming-wordcount-`date +%Y%m%d-%H%M%S`"
+export NUM_WORKERS="1"
+
+python -m apache_beam.yaml.main \
+ --yaml_pipeline_file streaming_wordcount.yaml \
+ --runner DataflowRunner \
Review Comment:
Seems like this is run as a batch pipeline (without the --streaming) option ?
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add more YAML examples involving Kafka and Iceberg [beam]
Posted by "charlespnh (via GitHub)" <gi...@apache.org>.
charlespnh commented on PR #35151:
URL: https://github.com/apache/beam/pull/35151#issuecomment-2940342055
cc @chamikaramj and @derrickaw
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add more YAML examples involving Kafka and Iceberg [beam]
Posted by "charlespnh (via GitHub)" <gi...@apache.org>.
charlespnh commented on PR #35151:
URL: https://github.com/apache/beam/pull/35151#issuecomment-2940556003
Taking a look at the failing tests... I didn't modify any Python source file though so likely it's linting error
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add more YAML examples involving Kafka and Iceberg [beam]
Posted by "charlespnh (via GitHub)" <gi...@apache.org>.
charlespnh commented on code in PR #35151:
URL: https://github.com/apache/beam/pull/35151#discussion_r2132997083
##########
sdks/python/apache_beam/yaml/examples/README.md:
##########
@@ -71,25 +79,173 @@ Examples in this directory show off the various built-in transforms of the Beam
YAML framework.
### Aggregation
+
These examples leverage the built-in `Combine` transform for performing simple
aggregations including sum, mean, count, etc.
### Blueprints
+
These examples leverage DF or other existing templates and convert them to yaml
blueprints.
### Element-wise
+
These examples leverage the built-in mapping transforms including `MapToFields`,
`Filter` and `Explode`. More information can be found about mapping transforms
[here](https://beam.apache.org/documentation/sdks/yaml-udf/).
### IO
-These examples leverage the built-in `Spanner_Read` and `Spanner_Write`
-transform for performing simple reads and writes from a spanner DB.
+
+#### Spanner
+
+Examples [Spanner Read](transforms/io/spanner_read.yaml) and [Spanner Write](
+transforms/io/spanner_write.yaml) leverage the built-in `Spanner_Read` and
+`Spanner_Write` transform for performing simple reads and writes from a spanner
+DB.
+
+#### Kafka
+
+Examples involving Kafka such as [Streaming Wordcount](streaming_wordcount.yaml)
+and [Kafka Read Write](transforms/io/kafka.yaml) require users to set up
+a Kafka cluster that Dataflow runner executing the
+Beam pipeline has access to. See
+issue [here](https://github.com/apache/beam/issues/22809) for context on running
+streaming pipelines with Kafka on Dataflow runner vs. portable runners.
+
+See [here](https://kafka.apache.org/quickstart) for general instructions on
+setting up a Kafka cluster. An option is to use [Click to Deploy](
+https://console.cloud.google.com/marketplace/details/click-to-deploy-images/kafka?)
+to quickly launch a Kafka cluster on [GCE](
+https://cloud.google.com/products/compute?hl=en). [SASL/PLAIN](
+https://kafka.apache.org/documentation/#security_sasl_plain) authentication
+mechanism is configured for the brokers as part of the deployment. See
+also [here](
+https://github.com/GoogleCloudPlatform/java-docs-samples/tree/main/dataflow/flex-templates/kafka_to_bigquery)
+for an alternative step-by-step guide on setting up Kafka on GCE without the
+authentication mechanism.
+
+Let's assume one of the bootstrap servers is on VM instance `kafka-vm-0`
+with the internal IP address `123.45.67.89` and port `9092` that the bootstrap
+server is listening on. SASL/PLAIN `USERNAME` and `PASSWORD` can be viewed from
+the VM instance's metadata on the GCE console, or with gcloud CLI:
+
+```sh
+gcloud compute instances describe kafka-vm-0 \
+ --format='value[](metadata.items.kafka-user)'
+gcloud compute instances describe kafka-vm-0 \
+ --format='value[](metadata.items.kafka-password)'
+```
+
+Beam pipeline [Streaming Wordcount](streaming_wordcount.yaml) reads from an
+existing Kafka topic `MY-TOPIC` containing lines of text and then applies
+transformation logic similar to [Wordcount](wordcount_minimal.yaml) example,
+before finally logs out the output. Run the pipeline:
+
+```sh
+export PROJECT="$(gcloud config get-value project)"
+export TEMP_LOCATION="gs://MY-BUCKET/tmp"
+export REGION="us-central1"
+export JOB_NAME="streaming-wordcount-`date +%Y%m%d-%H%M%S`"
+export NUM_WORKERS="1"
+
+python -m apache_beam.yaml.main \
+ --yaml_pipeline_file streaming_wordcount.yaml \
+ --runner DataflowRunner \
Review Comment:
Looks like it's not necessary to specify --streaming option. At least on Dataflow it automatically infers that it's a streaming pipeline.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add more YAML examples involving Kafka and Iceberg [beam]
Posted by "charlespnh (via GitHub)" <gi...@apache.org>.
charlespnh commented on code in PR #35151:
URL: https://github.com/apache/beam/pull/35151#discussion_r2132982106
##########
sdks/python/apache_beam/yaml/examples/README.md:
##########
@@ -71,25 +79,173 @@ Examples in this directory show off the various built-in transforms of the Beam
YAML framework.
### Aggregation
+
These examples leverage the built-in `Combine` transform for performing simple
aggregations including sum, mean, count, etc.
### Blueprints
+
These examples leverage DF or other existing templates and convert them to yaml
blueprints.
### Element-wise
+
These examples leverage the built-in mapping transforms including `MapToFields`,
`Filter` and `Explode`. More information can be found about mapping transforms
[here](https://beam.apache.org/documentation/sdks/yaml-udf/).
### IO
-These examples leverage the built-in `Spanner_Read` and `Spanner_Write`
-transform for performing simple reads and writes from a spanner DB.
+
+#### Spanner
+
+Examples [Spanner Read](transforms/io/spanner_read.yaml) and [Spanner Write](
+transforms/io/spanner_write.yaml) leverage the built-in `Spanner_Read` and
+`Spanner_Write` transform for performing simple reads and writes from a spanner
Review Comment:
Fixed
##########
sdks/python/apache_beam/yaml/examples/README.md:
##########
@@ -71,25 +79,173 @@ Examples in this directory show off the various built-in transforms of the Beam
YAML framework.
### Aggregation
+
These examples leverage the built-in `Combine` transform for performing simple
aggregations including sum, mean, count, etc.
### Blueprints
+
These examples leverage DF or other existing templates and convert them to yaml
blueprints.
### Element-wise
+
These examples leverage the built-in mapping transforms including `MapToFields`,
`Filter` and `Explode`. More information can be found about mapping transforms
[here](https://beam.apache.org/documentation/sdks/yaml-udf/).
### IO
-These examples leverage the built-in `Spanner_Read` and `Spanner_Write`
-transform for performing simple reads and writes from a spanner DB.
+
+#### Spanner
+
+Examples [Spanner Read](transforms/io/spanner_read.yaml) and [Spanner Write](
+transforms/io/spanner_write.yaml) leverage the built-in `Spanner_Read` and
+`Spanner_Write` transform for performing simple reads and writes from a spanner
Review Comment:
Fixed
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add more YAML examples involving Kafka and Iceberg [beam]
Posted by "charlespnh (via GitHub)" <gi...@apache.org>.
charlespnh commented on code in PR #35151:
URL: https://github.com/apache/beam/pull/35151#discussion_r2132988057
##########
sdks/python/apache_beam/yaml/examples/README.md:
##########
@@ -71,25 +79,173 @@ Examples in this directory show off the various built-in transforms of the Beam
YAML framework.
### Aggregation
+
These examples leverage the built-in `Combine` transform for performing simple
aggregations including sum, mean, count, etc.
### Blueprints
+
These examples leverage DF or other existing templates and convert them to yaml
blueprints.
### Element-wise
+
These examples leverage the built-in mapping transforms including `MapToFields`,
`Filter` and `Explode`. More information can be found about mapping transforms
[here](https://beam.apache.org/documentation/sdks/yaml-udf/).
### IO
-These examples leverage the built-in `Spanner_Read` and `Spanner_Write`
-transform for performing simple reads and writes from a spanner DB.
+
+#### Spanner
+
+Examples [Spanner Read](transforms/io/spanner_read.yaml) and [Spanner Write](
+transforms/io/spanner_write.yaml) leverage the built-in `Spanner_Read` and
+`Spanner_Write` transform for performing simple reads and writes from a spanner
+DB.
+
+#### Kafka
+
+Examples involving Kafka such as [Streaming Wordcount](streaming_wordcount.yaml)
+and [Kafka Read Write](transforms/io/kafka.yaml) require users to set up
+a Kafka cluster that Dataflow runner executing the
+Beam pipeline has access to. See
+issue [here](https://github.com/apache/beam/issues/22809) for context on running
+streaming pipelines with Kafka on Dataflow runner vs. portable runners.
+
+See [here](https://kafka.apache.org/quickstart) for general instructions on
+setting up a Kafka cluster. An option is to use [Click to Deploy](
+https://console.cloud.google.com/marketplace/details/click-to-deploy-images/kafka?)
+to quickly launch a Kafka cluster on [GCE](
+https://cloud.google.com/products/compute?hl=en). [SASL/PLAIN](
+https://kafka.apache.org/documentation/#security_sasl_plain) authentication
+mechanism is configured for the brokers as part of the deployment. See
+also [here](
+https://github.com/GoogleCloudPlatform/java-docs-samples/tree/main/dataflow/flex-templates/kafka_to_bigquery)
+for an alternative step-by-step guide on setting up Kafka on GCE without the
+authentication mechanism.
+
+Let's assume one of the bootstrap servers is on VM instance `kafka-vm-0`
+with the internal IP address `123.45.67.89` and port `9092` that the bootstrap
+server is listening on. SASL/PLAIN `USERNAME` and `PASSWORD` can be viewed from
+the VM instance's metadata on the GCE console, or with gcloud CLI:
+
+```sh
+gcloud compute instances describe kafka-vm-0 \
+ --format='value[](metadata.items.kafka-user)'
+gcloud compute instances describe kafka-vm-0 \
+ --format='value[](metadata.items.kafka-password)'
+```
+
+Beam pipeline [Streaming Wordcount](streaming_wordcount.yaml) reads from an
+existing Kafka topic `MY-TOPIC` containing lines of text and then applies
+transformation logic similar to [Wordcount](wordcount_minimal.yaml) example,
+before finally logs out the output. Run the pipeline:
+
+```sh
+export PROJECT="$(gcloud config get-value project)"
+export TEMP_LOCATION="gs://MY-BUCKET/tmp"
+export REGION="us-central1"
+export JOB_NAME="streaming-wordcount-`date +%Y%m%d-%H%M%S`"
+export NUM_WORKERS="1"
+
+python -m apache_beam.yaml.main \
+ --yaml_pipeline_file streaming_wordcount.yaml \
+ --runner DataflowRunner \
+ --temp_location $TEMP_LOCATION \
+ --project $PROJECT \
+ --region $REGION \
+ --num_workers $NUM_WORKERS \
+ --job_name $JOB_NAME \
+ --jinja_variables '{ "BOOTSTRAP_SERVERS": "123.45.67.89:9092",
Review Comment:
That'd be neat but AFAIK there's isn't a way to put in the env variables in the `--jinja_variables` flag. It expects JSON string so hardcoded value string is required.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add more YAML examples involving Kafka and Iceberg [beam]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #35151:
URL: https://github.com/apache/beam/pull/35151#issuecomment-2940602292
Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment `assign set of reviewers`
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add more YAML examples involving Kafka and Iceberg [beam]
Posted by "charlespnh (via GitHub)" <gi...@apache.org>.
charlespnh commented on code in PR #35151:
URL: https://github.com/apache/beam/pull/35151#discussion_r2132988475
##########
sdks/python/apache_beam/yaml/examples/README.md:
##########
@@ -71,25 +79,173 @@ Examples in this directory show off the various built-in transforms of the Beam
YAML framework.
### Aggregation
+
These examples leverage the built-in `Combine` transform for performing simple
aggregations including sum, mean, count, etc.
### Blueprints
+
These examples leverage DF or other existing templates and convert them to yaml
blueprints.
### Element-wise
+
These examples leverage the built-in mapping transforms including `MapToFields`,
`Filter` and `Explode`. More information can be found about mapping transforms
[here](https://beam.apache.org/documentation/sdks/yaml-udf/).
### IO
-These examples leverage the built-in `Spanner_Read` and `Spanner_Write`
-transform for performing simple reads and writes from a spanner DB.
+
+#### Spanner
+
+Examples [Spanner Read](transforms/io/spanner_read.yaml) and [Spanner Write](
+transforms/io/spanner_write.yaml) leverage the built-in `Spanner_Read` and
+`Spanner_Write` transform for performing simple reads and writes from a spanner
+DB.
+
+#### Kafka
+
+Examples involving Kafka such as [Streaming Wordcount](streaming_wordcount.yaml)
+and [Kafka Read Write](transforms/io/kafka.yaml) require users to set up
+a Kafka cluster that Dataflow runner executing the
+Beam pipeline has access to. See
+issue [here](https://github.com/apache/beam/issues/22809) for context on running
+streaming pipelines with Kafka on Dataflow runner vs. portable runners.
+
+See [here](https://kafka.apache.org/quickstart) for general instructions on
+setting up a Kafka cluster. An option is to use [Click to Deploy](
+https://console.cloud.google.com/marketplace/details/click-to-deploy-images/kafka?)
+to quickly launch a Kafka cluster on [GCE](
+https://cloud.google.com/products/compute?hl=en). [SASL/PLAIN](
+https://kafka.apache.org/documentation/#security_sasl_plain) authentication
+mechanism is configured for the brokers as part of the deployment. See
+also [here](
+https://github.com/GoogleCloudPlatform/java-docs-samples/tree/main/dataflow/flex-templates/kafka_to_bigquery)
+for an alternative step-by-step guide on setting up Kafka on GCE without the
+authentication mechanism.
+
+Let's assume one of the bootstrap servers is on VM instance `kafka-vm-0`
+with the internal IP address `123.45.67.89` and port `9092` that the bootstrap
+server is listening on. SASL/PLAIN `USERNAME` and `PASSWORD` can be viewed from
+the VM instance's metadata on the GCE console, or with gcloud CLI:
+
+```sh
+gcloud compute instances describe kafka-vm-0 \
+ --format='value[](metadata.items.kafka-user)'
+gcloud compute instances describe kafka-vm-0 \
+ --format='value[](metadata.items.kafka-password)'
+```
+
+Beam pipeline [Streaming Wordcount](streaming_wordcount.yaml) reads from an
+existing Kafka topic `MY-TOPIC` containing lines of text and then applies
+transformation logic similar to [Wordcount](wordcount_minimal.yaml) example,
+before finally logs out the output. Run the pipeline:
+
+```sh
+export PROJECT="$(gcloud config get-value project)"
+export TEMP_LOCATION="gs://MY-BUCKET/tmp"
+export REGION="us-central1"
+export JOB_NAME="streaming-wordcount-`date +%Y%m%d-%H%M%S`"
+export NUM_WORKERS="1"
+
+python -m apache_beam.yaml.main \
+ --yaml_pipeline_file streaming_wordcount.yaml \
+ --runner DataflowRunner \
+ --temp_location $TEMP_LOCATION \
+ --project $PROJECT \
+ --region $REGION \
+ --num_workers $NUM_WORKERS \
+ --job_name $JOB_NAME \
+ --jinja_variables '{ "BOOTSTRAP_SERVERS": "123.45.67.89:9092",
+ "TOPIC": "MY-TOPIC", "USERNAME": "USERNAME", "PASSWORD": "PASSWORD" }'
+```
+
+Beam pipeline [Kafka Read Write](transforms/io/kafka.yaml) is a non-linear
Review Comment:
Changed
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add more YAML examples involving Kafka and Iceberg [beam]
Posted by "charlespnh (via GitHub)" <gi...@apache.org>.
charlespnh commented on code in PR #35151:
URL: https://github.com/apache/beam/pull/35151#discussion_r2132993912
##########
sdks/python/apache_beam/yaml/examples/streaming_wordcount.yaml:
##########
@@ -0,0 +1,97 @@
+# coding=utf-8
+#
+# 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.
+#
+
+pipeline:
+ type: chain
+ transforms:
+ # Assuming the given topic exists with the following message JSON schema,
+ # read the records from Kafka
+ - type: ReadFromKafka
+ config:
+ format: JSON
+ schema: |
+ {
+ "type": "object",
+ "properties": {
+ "value": {"type": "string"}
+ }
+ }
+ topic: {{ TOPIC }}
+ bootstrap_servers: {{ BOOTSTRAP_SERVERS }}
+ auto_offset_reset_config: earliest
+ consumer_config:
+ sasl.jaas.config: "org.apache.kafka.common.security.plain.PlainLoginModule required \
+ username={{ USERNAME }} \
+ password={{ PASSWORD }};"
+ security.protocol: "SASL_PLAINTEXT"
+ sasl.mechanism: "PLAIN"
+
+ # Split line field in each row into list of words.
+ - type: MapToFields
+ config:
+ language: python
+ fields:
+ words:
+ callable: |
+ import re
+ def my_mapping(row):
+ return re.findall(r"[A-Za-z\']+", row.value.lower())
+
+ # Explode each list of words into separate rows.
+ - type: Explode
+ config:
+ fields: words
+
+ # Since each word is now distinct row, rename field to "word".
+ - type: MapToFields
+ config:
+ fields:
+ word: words
+
+ # With an unbounded source such as Kafka, a window is required for
+ # any subsequent GroupBy transform.
+ - type: WindowInto
+ name: Windowing
+ windowing:
+ type: fixed
+ size: 3s
+
+ # Group by distinct words in the collection and add field "count" that
+ # contains number of instances, or count, for each word in the collection.
+ - type: Combine
+ config:
+ language: python
+ group_by: word
+ combine:
+ count:
+ value: word
+ fn: count
+
+ - type: LogForTesting
+
+# Expected:
+# Row(word='king', count=311)
Review Comment:
Based on discussion this streaming wordcount example is removed. There're already kafka.yaml and wordcount_minimal.yaml examples that can be referenced.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add more YAML examples involving Kafka and Iceberg [beam]
Posted by "charlespnh (via GitHub)" <gi...@apache.org>.
charlespnh commented on code in PR #35151:
URL: https://github.com/apache/beam/pull/35151#discussion_r2132994631
##########
sdks/python/apache_beam/yaml/examples/transforms/io/iceberg_read.yaml:
##########
@@ -0,0 +1,41 @@
+# coding=utf-8
+#
+# 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.
+#
+
+pipeline:
+ type: chain
+ transforms:
+ - type: ReadFromIceberg
+ name: ReadFromAnIcebergTable
+ config:
+ table: "demo.users.NY"
+ catalog_name: "hadoop_catalog"
+ catalog_properties:
+ type: "hadoop"
Review Comment:
Added
##########
sdks/python/apache_beam/yaml/examples/transforms/io/iceberg_write.yaml:
##########
@@ -0,0 +1,45 @@
+# coding=utf-8
+#
+# 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.
+#
+
+pipeline:
+ type: chain
+ transforms:
+ - type: Create
+ name: CreateSampleData
+ config:
+ elements:
+ - { id: 1, name: "John", email: "john@example.com", zip: "WA" }
+ - { id: 2, name: "Jane", email: "jane@example.com", zip: "CA" }
+ - { id: 3, name: "Beamberg", email: "beamberg@example.com", zip: "NY" }
+
+ - type: LogForTesting
+
+ - type: WriteToIceberg
+ name: WriteToAnIcebergTable
+ config:
+ # Dynamic destinations
+ table: "demo.users.{zip}"
+ catalog_name: "hadoop_catalog"
+ catalog_properties:
+ type: "hadoop"
+ warehouse: "gs://MY-WAREHOUSE"
Review Comment:
Added
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add more YAML examples involving Kafka and Iceberg [beam]
Posted by "derrickaw (via GitHub)" <gi...@apache.org>.
derrickaw commented on PR #35151:
URL: https://github.com/apache/beam/pull/35151#issuecomment-2941387513
> > Taking a look at the failing tests... I didn't modify any Python source file though so likely it's linting error
>
> Looks like I'll have to take a closer look at writing tests for my examples as well. Completely wasn't aware of this...
Robert setup the example testing to simplify the input and output transforms and also test based on what the expected comments at the end of each transform are.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add more YAML examples involving Kafka and Iceberg [beam]
Posted by "chamikaramj (via GitHub)" <gi...@apache.org>.
chamikaramj commented on PR #35151:
URL: https://github.com/apache/beam/pull/35151#issuecomment-2940905115
Thanks for the PR. I'll take a look.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add more YAML examples involving Kafka and Iceberg [beam]
Posted by "chamikaramj (via GitHub)" <gi...@apache.org>.
chamikaramj merged PR #35151:
URL: https://github.com/apache/beam/pull/35151
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add more YAML examples involving Kafka and Iceberg [beam]
Posted by "charlespnh (via GitHub)" <gi...@apache.org>.
charlespnh commented on PR #35151:
URL: https://github.com/apache/beam/pull/35151#issuecomment-2941245252
> Taking a look at the failing tests... I didn't modify any Python source file though so likely it's linting error
Looks like I'll have to take a closer look at writing tests for my examples as well. Completely wasn't aware of this...
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add more YAML examples involving Kafka and Iceberg [beam]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #35151:
URL: https://github.com/apache/beam/pull/35151#issuecomment-2951300201
Assigning reviewers:
R: @claudevdm for label python.
Note: If you would like to opt out of this review, comment `assign to next reviewer`.
Available commands:
- `stop reviewer notifications` - opt out of the automated review tooling
- `remind me after tests pass` - tag the comment author after tests pass
- `waiting on author` - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)
The PR bot will only process comments in the main thread (not review comments).
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add more YAML examples involving Kafka and Iceberg [beam]
Posted by "charlespnh (via GitHub)" <gi...@apache.org>.
charlespnh commented on code in PR #35151:
URL: https://github.com/apache/beam/pull/35151#discussion_r2132988057
##########
sdks/python/apache_beam/yaml/examples/README.md:
##########
@@ -71,25 +79,173 @@ Examples in this directory show off the various built-in transforms of the Beam
YAML framework.
### Aggregation
+
These examples leverage the built-in `Combine` transform for performing simple
aggregations including sum, mean, count, etc.
### Blueprints
+
These examples leverage DF or other existing templates and convert them to yaml
blueprints.
### Element-wise
+
These examples leverage the built-in mapping transforms including `MapToFields`,
`Filter` and `Explode`. More information can be found about mapping transforms
[here](https://beam.apache.org/documentation/sdks/yaml-udf/).
### IO
-These examples leverage the built-in `Spanner_Read` and `Spanner_Write`
-transform for performing simple reads and writes from a spanner DB.
+
+#### Spanner
+
+Examples [Spanner Read](transforms/io/spanner_read.yaml) and [Spanner Write](
+transforms/io/spanner_write.yaml) leverage the built-in `Spanner_Read` and
+`Spanner_Write` transform for performing simple reads and writes from a spanner
+DB.
+
+#### Kafka
+
+Examples involving Kafka such as [Streaming Wordcount](streaming_wordcount.yaml)
+and [Kafka Read Write](transforms/io/kafka.yaml) require users to set up
+a Kafka cluster that Dataflow runner executing the
+Beam pipeline has access to. See
+issue [here](https://github.com/apache/beam/issues/22809) for context on running
+streaming pipelines with Kafka on Dataflow runner vs. portable runners.
+
+See [here](https://kafka.apache.org/quickstart) for general instructions on
+setting up a Kafka cluster. An option is to use [Click to Deploy](
+https://console.cloud.google.com/marketplace/details/click-to-deploy-images/kafka?)
+to quickly launch a Kafka cluster on [GCE](
+https://cloud.google.com/products/compute?hl=en). [SASL/PLAIN](
+https://kafka.apache.org/documentation/#security_sasl_plain) authentication
+mechanism is configured for the brokers as part of the deployment. See
+also [here](
+https://github.com/GoogleCloudPlatform/java-docs-samples/tree/main/dataflow/flex-templates/kafka_to_bigquery)
+for an alternative step-by-step guide on setting up Kafka on GCE without the
+authentication mechanism.
+
+Let's assume one of the bootstrap servers is on VM instance `kafka-vm-0`
+with the internal IP address `123.45.67.89` and port `9092` that the bootstrap
+server is listening on. SASL/PLAIN `USERNAME` and `PASSWORD` can be viewed from
+the VM instance's metadata on the GCE console, or with gcloud CLI:
+
+```sh
+gcloud compute instances describe kafka-vm-0 \
+ --format='value[](metadata.items.kafka-user)'
+gcloud compute instances describe kafka-vm-0 \
+ --format='value[](metadata.items.kafka-password)'
+```
+
+Beam pipeline [Streaming Wordcount](streaming_wordcount.yaml) reads from an
+existing Kafka topic `MY-TOPIC` containing lines of text and then applies
+transformation logic similar to [Wordcount](wordcount_minimal.yaml) example,
+before finally logs out the output. Run the pipeline:
+
+```sh
+export PROJECT="$(gcloud config get-value project)"
+export TEMP_LOCATION="gs://MY-BUCKET/tmp"
+export REGION="us-central1"
+export JOB_NAME="streaming-wordcount-`date +%Y%m%d-%H%M%S`"
+export NUM_WORKERS="1"
+
+python -m apache_beam.yaml.main \
+ --yaml_pipeline_file streaming_wordcount.yaml \
+ --runner DataflowRunner \
+ --temp_location $TEMP_LOCATION \
+ --project $PROJECT \
+ --region $REGION \
+ --num_workers $NUM_WORKERS \
+ --job_name $JOB_NAME \
+ --jinja_variables '{ "BOOTSTRAP_SERVERS": "123.45.67.89:9092",
Review Comment:
That'd be neat but AKAIK there's isn't a way to put in the env variables in the `--jinja_variables` flag. It expects JSON string so hardcoded value string is required.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add more YAML examples involving Kafka and Iceberg [beam]
Posted by "charlespnh (via GitHub)" <gi...@apache.org>.
charlespnh commented on code in PR #35151:
URL: https://github.com/apache/beam/pull/35151#discussion_r2132983350
##########
sdks/python/apache_beam/yaml/examples/README.md:
##########
@@ -71,25 +79,173 @@ Examples in this directory show off the various built-in transforms of the Beam
YAML framework.
### Aggregation
+
These examples leverage the built-in `Combine` transform for performing simple
aggregations including sum, mean, count, etc.
### Blueprints
+
These examples leverage DF or other existing templates and convert them to yaml
blueprints.
### Element-wise
+
These examples leverage the built-in mapping transforms including `MapToFields`,
`Filter` and `Explode`. More information can be found about mapping transforms
[here](https://beam.apache.org/documentation/sdks/yaml-udf/).
### IO
-These examples leverage the built-in `Spanner_Read` and `Spanner_Write`
-transform for performing simple reads and writes from a spanner DB.
+
+#### Spanner
+
+Examples [Spanner Read](transforms/io/spanner_read.yaml) and [Spanner Write](
+transforms/io/spanner_write.yaml) leverage the built-in `Spanner_Read` and
+`Spanner_Write` transform for performing simple reads and writes from a spanner
+DB.
+
+#### Kafka
+
+Examples involving Kafka such as [Streaming Wordcount](streaming_wordcount.yaml)
+and [Kafka Read Write](transforms/io/kafka.yaml) require users to set up
+a Kafka cluster that Dataflow runner executing the
+Beam pipeline has access to. See
+issue [here](https://github.com/apache/beam/issues/22809) for context on running
Review Comment:
Changed
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org