[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[],[],null,["# Package and import transforms\n\nApache Beam YAML lets you package and reuse transforms through [Beam YAML providers](https://beam.apache.org/documentation/sdks/yaml-providers/). Providers allow you to encapsulate transforms into a reusable unit that you can then import in your Beam YAML pipelines. YAML, Python, and Java Apache Beam transforms can all be packaged in this way.\n\nWith the job builder, you can load providers from Cloud Storage to use them in your job.\n\nWriting providers\n-----------------\n\nBeam YAML providers are defined in YAML files. These files specify the implementation and configuration of the provided transforms. Individual provider listings are expressed as YAML list items with `type` and `config` keys. Java and Python providers also have a `config` key that specifies the transform implementation. YAML-defined provider implementations are expressed inline.\n\n### YAML providers\n\nYAML providers define new YAML transforms as a map of names to transform definitions. For example, this provider defines a transform that squares a field from its input: \n\n - type: yaml\n transforms:\n SquareElement:\n body:\n type: chain\n transforms:\n - type: MapToFields\n config:\n language: python\n append: true\n fields:\n power: \"element ** 2\"\n\nYAML providers can also specify transform parameters with a `config_schema` key in the transform definition and use these parameters using [Jinja2 templatization](https://jinja.palletsprojects.com/en/stable/templates/): \n\n - type: yaml\n transforms:\n RaiseElementToPower:\n config_schema:\n properties:\n n: {type: integer}\n body:\n type: chain\n transforms:\n - type: MapToFields\n config:\n language: python\n append: true\n fields:\n power: \"element ** {{n}}\"\n\nIf a provided transform functions as a source, it must set `requires_inputs: false`: \n\n - type: yaml\n transforms:\n CreateTestElements:\n requires_inputs: false\n body: |\n type: Create\n config:\n elements: [1,2,3,4]\n\nIt is also possible to define composite transforms: \n\n - type: yaml\n transforms:\n ConsecutivePowers:\n config_schema:\n properties:\n end: {type: integer}\n n: {type: integer}\n requires_inputs: false\n body: |\n type: chain\n transforms:\n - type: Range\n config:\n end: {{end}}\n - type: RaiseElementToPower\n config:\n n: {{n}}\n\n### Python providers\n\nPython transforms can be provided using the following syntax: \n\n - type: pythonPackage\n config:\n packages:\n - pypi_package\u003e=version\n transforms:\n MyCustomTransform: \"pkg.module.PTransformClassOrCallable\"\n\nFor an in-depth example, see the [Python provider starter project](https://github.com/apache/beam-starter-python-provider) on GitHub.\n\n### Java providers\n\nJava transforms can be provided using the following syntax: \n\n - type: javaJar\n config:\n jar: gs://your-bucket/your-java-transform.jar\n transforms:\n MyCustomTransform: \"urn:registered:in:transform\"\n\nFor an in-depth example, see the [Java provider starter project](https://github.com/apache/beam-starter-java-provider) on GitHub.\n\nUsing providers in the job builder\n----------------------------------\n\nTransforms defined in providers can be imported from Cloud Storage and used in the job builder. To use a provider in the job builder:\n\n1. Save a provider as a YAML file in Cloud Storage.\n\n [Go to Cloud Storage](https://console.cloud.google.com/storage)\n2. Go to the **Jobs** page in the Google Cloud console.\n\n [Go to Jobs](https://console.cloud.google.com/dataflow)\n3. Click add_box**Create job from\n builder**.\n\n4. Locate the **YAML Providers** section. You might need to scroll.\n\n5. In the **YAML provider path** box, enter the Cloud Storage location of the provider file.\n\n6. Wait for the provider to load. If the provider is valid, the transform(s) defined in the provider will appear in the **Loaded transforms** section.\n\n7. Locate your transform's name in the **Loaded transforms** section and click the add_box button to insert the transform in your job.\n\n8. If your transform requires parameters, define them in the **YAML transform configuration** editor for your transform. Parameters should be defined as a YAML object mapping parameter names to parameter values.\n\nWhat's next\n-----------\n\n- Learn more about [Beam YAML providers](https://beam.apache.org/documentation/sdks/yaml-providers/)."]]