|
| 1 | +--- |
| 2 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 3 | +# or more contributor license agreements. See the NOTICE file |
| 4 | +# distributed with this work for additional information |
| 5 | +# regarding copyright ownership. The ASF licenses this file |
| 6 | +# to you under the Apache License, Version 2.0 (the |
| 7 | +# "License"); you may not use this file except in compliance |
| 8 | +# with the License. You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, |
| 13 | +# software distributed under the License is distributed on an |
| 14 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | +# KIND, either express or implied. See the License for the |
| 16 | +# specific language governing permissions and limitations |
| 17 | +# under the License. |
| 18 | + |
| 19 | +name: yaml-development |
| 20 | +description: Guides YAML SDK development in Apache Beam, including environment setup, testing, and key concepts. Use when working with Beam YAML code in sdks/python/apache_beam/yaml/. |
| 21 | +--- |
| 22 | + |
| 23 | +# YAML Development in Apache Beam |
| 24 | + |
| 25 | +## Project Structure |
| 26 | + |
| 27 | +### Key Files in `sdks/python/apache_beam/yaml/` |
| 28 | +- `integration_tests.py` - Runs integration tests defined in YAML files or using testcontainers. |
| 29 | +- `main.py` - Entry point for running YAML pipelines from the command line. |
| 30 | +- `pipeline.schema.yaml` - JSON schema defining the valid structure for Beam YAML pipelines. |
| 31 | +- `standard_io.yaml` - Declarations of standard IO transforms and their mappings to providers. |
| 32 | +- `standard_providers.yaml` - Configuration for standard providers (e.g., Java expansion services). |
| 33 | +- `yaml_combine.py` - Implementations for aggregation and combining operations. |
| 34 | +- `yaml_io.py` - Mappings and logic for IO transforms (e.g., PubSub, BigQuery, Iceberg). |
| 35 | +- `yaml_join.py` - Implementations for join operations. |
| 36 | +- `yaml_mapping.py` - Implementations for mapping operations (e.g., `MapToFields`). |
| 37 | +- `yaml_provider.py` - Manages providers (Python, Java cross-language) that implement transforms. |
| 38 | +- `yaml_transform.py` - Core YAML expansion logic, parsing, and translation to Beam pipelines. |
| 39 | + |
| 40 | +## Environment Setup |
| 41 | +Since Beam YAML is implemented within the Python SDK, the environment setup is identical to Python development. Refer to the `python-development` skill for details on using `pyenv` and installing in editable mode (e.g., use `pip install -e sdks/python[gcp,test]` from the root directory). |
| 42 | + |
| 43 | +## Running YAML Pipelines |
| 44 | + |
| 45 | +You can run Beam YAML pipelines using the `main.py` script in the YAML directory. |
| 46 | + |
| 47 | +### Using `main.py` directly |
| 48 | +```bash |
| 49 | +python -m apache_beam.yaml.main --yaml_pipeline_file=/path/to/pipeline.yaml [pipeline_options] |
| 50 | +``` |
| 51 | + |
| 52 | +### Example: Running locally |
| 53 | +```bash |
| 54 | +python -m apache_beam.yaml.main \ |
| 55 | + --yaml_pipeline_file=sdks/python/apache_beam/yaml/examples/simple_filter.yaml \ |
| 56 | + --runner=DirectRunner |
| 57 | +``` |
| 58 | + |
| 59 | +### Example: Running on Dataflow |
| 60 | +```bash |
| 61 | +python -m apache_beam.yaml.main \ |
| 62 | + --yaml_pipeline_file=sdks/python/apache_beam/yaml/examples/simple_filter.yaml \ |
| 63 | + --runner=DataflowRunner \ |
| 64 | + --project=my-project \ |
| 65 | + --region=us-central1 \ |
| 66 | + --temp_location=gs://my-bucket/temp |
| 67 | +``` |
| 68 | + |
| 69 | +## Running Tests |
| 70 | + |
| 71 | +### Unit Tests |
| 72 | +Beam YAML has extensive unit tests covering parsing, expansion, and specific transforms. |
| 73 | +```bash |
| 74 | +# Run all tests in a file |
| 75 | +pytest sdks/python/apache_beam/yaml/yaml_transform_test.py |
| 76 | + |
| 77 | +# Run a specific test |
| 78 | +pytest sdks/python/apache_beam/yaml/yaml_transform_test.py::YamlTransformTest::test_simple_pipeline |
| 79 | +``` |
| 80 | + |
| 81 | +### Integration Tests |
| 82 | +Integration tests often spin up Docker containers (via `testcontainers`) for external services like MongoDB, Kafka, or databases. |
| 83 | +```bash |
| 84 | +# Run integration tests matching a specific keyword (e.g., mongodb) |
| 85 | +pytest sdks/python/apache_beam/yaml/integration_tests.py -k mongodb |
| 86 | +``` |
| 87 | + |
| 88 | +## Key Concepts |
| 89 | + |
| 90 | +### Providers |
| 91 | +Beam YAML uses "providers" to find implementations for transforms requested in the YAML file. |
| 92 | +- **Inline/Python Providers**: Leverage Python functions or PTransforms directly. |
| 93 | +- **Java/External Providers**: Use Beam's cross-language capabilities to invoke Java transforms via an expansion service. |
| 94 | + |
| 95 | +### Preprocessing |
| 96 | +Before execution, a YAML pipeline is preprocessed to resolve schemas, match transforms to providers, and expand shorthand notations (like `chain` or `source`/`sink` composites). |
| 97 | + |
| 98 | +## Common Issues |
| 99 | + |
| 100 | +### Cross-language Failures |
| 101 | +If a test requires a Java transform, ensure that: |
| 102 | +1. Docker is running (if using testcontainers). |
| 103 | +2. The correct expansion service is available or can be started. |
| 104 | +3. Java environment is correctly configured (sometimes requires specific Java versions like Java 17/21). |
| 105 | + |
| 106 | +### Schema Mismatches |
| 107 | +YAML relies heavily on Beam schemas. Ensure that fields produced by a transform match the fields expected by the next transform. Use explicit mapping if necessary. |
0 commit comments