Skip to content

Commit

Permalink
docs: Add custom-query code snippet for Cloud Run sample documentation (
Browse files Browse the repository at this point in the history
  • Loading branch information
helensilva14 committed Apr 17, 2024
1 parent ee8d6da commit 93bb64f
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions samples/run/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ gcloud run deploy --image gcr.io/${PROJECT_ID}/data-validation \

### Test Cloud Run Endpoint

You can easily run a request via Python. For a quick test, we have provided this logic in `test.py` to run a validation against a public BigQuery table. The example is similar and also shows how you can forward results to BigQuery from the Cloud Run job:
You can easily run a request via Python. For a quick test, we have provided this logic in `test.py` to run a validation against a public BigQuery table. The example below is similar and also shows how you can forward results to BigQuery from the Cloud Run job:

```python
# Copyright 2020 Google LLC
Expand Down Expand Up @@ -95,8 +95,7 @@ data = {
"type": "BigQuery",
"project_id": PROJECT_ID,
"table_id": "pso_data_validator.results"
},

},
"aggregates": [
{
"source_column": None,
Expand All @@ -112,6 +111,45 @@ res = requests.post(
print(res.content.decode())
```

If you intend to execute custom query validations, you will need to declare each aggregation column from your SQL query inside the `data` configuration object as shown in the code snippet below:

```python
query = """
SELECT start_station_id,
SUM(CASE WHEN bikeid = 18104 THEN 1 END ) AS bike_18104
FROM `bigquery-public-data.new_york_citibike.citibike_trips`
WHERE bikeid = 18104
GROUP BY start_station_id
ORDER BY bike_18104 DESC
"""

data = {
"source_conn": {
"source_type": "BigQuery",
"project_id": PROJECT_ID,
},
"target_conn": {
"source_type": "BigQuery",
"project_id": PROJECT_ID,
},
"type": "Custom-query",
"custom_query_type": "Column",
"schema_name": "bigquery-public-data.new_york_citibike",
"table_name": "citibike_stations",
"source_query": query,
"target_query": query,
"aggregates": [
{
"source_column": "bike_18104",
"target_column": "bike_18104",
"field_alias": "sum_bike",
"type": "sum",
}
],
}
```


### Oracle Setup

If you would like to use Data Validation against an Oracle DB you will need to
Expand Down

0 comments on commit 93bb64f

Please sign in to comment.