|
| 1 | +--- |
| 2 | +title: "Enrichment with CloudSQL" |
| 3 | +--- |
| 4 | +<!-- |
| 5 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +you may not use this file except in compliance with the License. |
| 7 | +You may obtain a copy of the License at |
| 8 | +
|
| 9 | +http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +
|
| 11 | +Unless required by applicable law or agreed to in writing, software |
| 12 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +See the License for the specific language governing permissions and |
| 15 | +limitations under the License. |
| 16 | +--> |
| 17 | + |
| 18 | +# Use CloudSQL to enrich data |
| 19 | + |
| 20 | +{{< localstorage language language-py >}} |
| 21 | + |
| 22 | +<table> |
| 23 | + <tr> |
| 24 | + <td> |
| 25 | + <a> |
| 26 | + {{< button-pydoc path="apache_beam.transforms.enrichment_handlers.cloudsql" class="CloudSQLEnrichmentHandler" >}} |
| 27 | + </a> |
| 28 | + </td> |
| 29 | + </tr> |
| 30 | +</table> |
| 31 | + |
| 32 | +In Apache Beam <version> and later versions, the enrichment transform includes |
| 33 | +a built-in enrichment handler for |
| 34 | +[CloudSQL](https://cloud.google.com/sql/docs). |
| 35 | +The following example demonstrates how to create a pipeline that use the enrichment transform with the [`CloudSQLEnrichmentHandler`](https://beam.apache.org/releases/pydoc/current/apache_beam.transforms.enrichment_handlers.cloudsql.html#apache_beam.transforms.enrichment_handlers.cloudsql.CloudSQLEnrichmentHandler) handler. |
| 36 | + |
| 37 | +The data in the CloudSQL PostgreSQL products table instance follows this format: |
| 38 | + |
| 39 | +{{< table >}} |
| 40 | +| product_id | name | quantity | region_id | |
| 41 | +|:----------:|:----:|:--------:|:---------:| |
| 42 | +| 1 | A | 2 | 3 | |
| 43 | +| 2 | B | 3 | 1 | |
| 44 | +| 3 | C | 10 | 4 | |
| 45 | +{{< /table >}} |
| 46 | + |
| 47 | + |
| 48 | +{{< highlight language="py" >}} |
| 49 | +{{< code_sample "sdks/python/apache_beam/examples/snippets/transforms/elementwise/enrichment.py" enrichment_with_cloudsql >}} |
| 50 | +{{</ highlight >}} |
| 51 | + |
| 52 | +{{< paragraph class="notebook-skip" >}} |
| 53 | +Output: |
| 54 | +{{< /paragraph >}} |
| 55 | +{{< highlight class="notebook-skip" >}} |
| 56 | +{{< code_sample "sdks/python/apache_beam/examples/snippets/transforms/elementwise/enrichment_test.py" enrichment_with_cloudsql >}} |
| 57 | +{{< /highlight >}} |
| 58 | + |
| 59 | +## Related transforms |
| 60 | + |
| 61 | +Not applicable. |
| 62 | + |
| 63 | +{{< button-pydoc path="apache_beam.transforms.enrichment_handlers.cloudsql" class="CloudSQLEnrichmentHandler" >}} |
0 commit comments