Skip to content

Commit a99319f

Browse files
docs: add more examples to garf-executors library
1 parent 8661a09 commit a99319f

File tree

7 files changed

+313
-71
lines changed

7 files changed

+313
-71
lines changed

docs/usage/api-executor.md

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,72 @@
1-
# Combine fetching and saving with `ApiQueryExecutor`
1+
#ApiExecutor
2+
3+
If your job is to execute query and write it to local/remote storage you can use `ApiQueryExecutor` to do it easily.
24

35
## Install
46

57
Ensure that `garf-executors` library is installed:
68

7-
```
9+
```bash
810
pip install garf-executors
911
```
12+
## Run
1013

11-
## Initialize
12-
13-
If your job is to execute query and write it to local/remote storage you can use `ApiQueryExecutor` to do it easily.
14-
> When reading query from file `ApiQueryExecutor` will use query file name as a name for output file/table.
15-
/// tab | Python
16-
```python
17-
from garf_core.fetchers import FakeApiReportFetcher
18-
from garf_executors import api_executor
19-
from garf_io import reader
14+
Let's take an example of working with [YouTube Data API fetcher](../fetchers/youtube-data-api.md) to get some stats on YouTube video.
2015

16+
!!! important
17+
Make sure that corresponding library for interacting with YouTube Data API is installed
2118

22-
# initialize query_executor to fetch report and store them in local/remote storage
23-
fake_report_fetcher = FakeApiReportFetcher(data=[{'campaign': {'id': 1}}])
19+
```bash
20+
pip install garf_youtube_data_api
21+
```
2422

25-
query_executor = api_executor.ApiQueryExecutor(fetcher=fake_report_fetcher)
23+
/// tab | bash
2624

27-
context = api_executor.ApiExecutionContext(writer='csv')
28-
```
29-
///
25+
```bash
3026

31-
## Run
27+
echo "
28+
SELECT
29+
id,
30+
snippet.publishedAt AS published_at,
31+
snippet.title AS title
32+
FROM videos" > query.sql
3233

33-
/// tab | bash
3434

35-
```
36-
garf <QUERIES> --source <API_SOURCE> \
37-
--output <OUTPUT_TYPE> \
38-
--source.params1=<VALUE>
35+
garf query.sql --source youtube_data_api \
36+
--output console \
37+
--source.ids=VIDEO_ID
3938
```
4039

4140
where
4241

43-
* `<QUERIES>`- local or remote path(s) to files with queries.
44-
* `<API_SOURCE>`- type of API to use. Based on that the appropriate report fetcher will be initialized.
45-
* `<OUTPUT_TYPE>` - output supported by [`garf-io` library](../garf_io/README.md).
46-
47-
If your report fetcher requires additional parameters you can pass them via key value pairs under `--source.` argument, i.e.`--source.regionCode='US'` - to get data only from *US*.
48-
> Concrete `--source` parameters are dependent on a particular report fetcher and should be looked up in a documentation for this fetcher.
42+
* `query` - local or remote path(s) to files with queries.
43+
* `source`- type of API to use. Based on that the appropriate report fetcher will be initialized.
44+
* `output` - output supported by [`garf-io` library](https://google.github.io/garf/usage/writers/).
4945

5046
///
5147
/// tab | Python
5248
```python
53-
query_text = "SELECT campaign.id AS campaign_id, FROM campaign"
49+
from garf_executors import api_executor
50+
51+
5452

55-
# execute query and save results to `campaign.csv`
56-
query_executor.execute(query=query_text, title="campaign", context=context)
53+
query_executor = api_executor.ApiQueryExecutor.from_fetcher_alias(
54+
'youtube-data-api'
55+
)
56+
context = api_executor.ApiExecutionContext(writer='csv')
5757

58-
# execute query from file and save to results to `query.csv`
59-
reader_client = reader.FileReader()
60-
query_path="path/to/query.sql"
58+
query_text = """
59+
SELECT
60+
id,
61+
snippet.publishedAt AS published_at,
62+
snippet.title AS title
63+
FROM videos
64+
"""
6165

6266
query_executor.execute(
63-
query=reader_client.read(query_path),
64-
title=query_path,
65-
context=context
67+
query=query_text,
68+
title="query",
69+
context=context
6670
)
6771
```
6872
///

docs/usage/bq-executor.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# BigQuery Executor
22

3+
`BigQueryExecutor` allows you to execute SQL code in BigQuery.
4+
35
## Install
46

57
Ensure that `garf-executors` library is installed with BigQuery support:
68

7-
```
9+
```bash
810
pip install garf-executors[bq]
911
```
1012

@@ -13,15 +15,15 @@ pip install garf-executors[bq]
1315
After `garf-executors` is installed you can use `garf` utility to perform fetching.
1416

1517
/// tab | bash
16-
```
18+
```bash
1719
garf <QUERIES> --source bq \
18-
--output <OUTPUT_TYPE> \
19-
--source.project_id=YOUR_GCP_PROJECT
20+
--output csv \
21+
--source.project_id=MY_PROJECT
2022
```
2123
where
2224

23-
* `<QUERIES>`- local or remote path(s) to files with queries.
24-
* `<OUTPUT_TYPE>` - output supported by [`garf-io` library](../garf_io/README.md).
25+
* `query`- local or remote path(s) to files with queries.
26+
* `output` - output supported by [`garf-io` library](../garf_io/README.md).
2527
///
2628

2729
/// tab | Python

0 commit comments

Comments
 (0)