Skip to content

Commit

Permalink
fix for aggregate function
Browse files Browse the repository at this point in the history
  • Loading branch information
unytics committed May 10, 2024
1 parent 7c90f9c commit 514d28d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
6 changes: 5 additions & 1 deletion bigfun/bigfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ def dataset(self):
self._dataset = self.bigquery.get_dataset(f'{self.project}.{self.dataset_name}')
return self._dataset

@property
def location(self):
return self.dataset.location

def test(self):
# WARNING: TO CHANGE THIS AND DEPLOY A PYTHON FUNCTION HERE WE NEED TO HAVE A REMOTE CONNECTION PER DATASET AS users between dataset and remote connection are identical
if self.config['type'] == 'function_py':
Expand Down Expand Up @@ -135,7 +139,7 @@ def deploy(self):
template = jinja2.Template(open(template_file, encoding='utf-8').read())
query = template.render(**self.config)
print_info('Creating function in dataset')
self.bigquery.query(query)
self.bigquery.query(query, location=self.location)
print_success(f'successfully created {self.project}.{self.dataset_name}.{self.name}')

@property
Expand Down
2 changes: 1 addition & 1 deletion bigfun/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def deploy(bigfunction, project, dataset):
if len(datasets) > 1:
with multiprocessing.Pool(processes=8) as pool:
pool.map(
BigFunction.deploy,
bf.BigFunction.deploy,
[
bf.BigFunction(name, project=project, dataset=dataset)
for dataset in datasets[1:]
Expand Down
2 changes: 1 addition & 1 deletion bigfun/templates/bigfunction.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ description: "BigFunction {{ name }}: {{ description.split('\n')[0] }}"
```sql
{% if example.with_clause is defined %}
with sample_data as (
{{ example.with_clause | indent(2) }}
{{ example.with_clause | indent(6) }}
)
{% endif %}
{% if type == 'procedure' %}call{% elif type == 'table_function' %}select * from{% else %}select{% endif %} {{ project }}.{{ dataset }}.{{ name }}({% for argument in example.arguments %}{{ argument | replace('{BIGFUNCTIONS_DATASET}', dataset) | replace('\n', '\n ') }}{% if not loop.last %}, {% endif %}{% endfor %}){% if type == 'procedure' %};{% elif 'output' in bigfunction and type != 'table_function' %} as {{ output.name }}{% endif %}
Expand Down
4 changes: 2 additions & 2 deletions bigfun/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ def get_dataset(self, dataset):
]
return dataset

def query(self, query):
def query(self, query, **kwargs):
try:
return self.client.query(query).result()
return self.client.query(query, **kwargs).result()
except google.api_core.exceptions.Forbidden as e:
handle_error("Access Denied", e.message)
except (
Expand Down
1 change: 1 addition & 0 deletions bigfunctions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ BigFunctions are open-source BigQuery routines that give you **SQL-superpowers**
- [<code>format_percentage(first_number, second_number, nb_decimals)</code>](format_percentage.md): Return `first_number / second_number` as a formatted percentage
- [<code>quantize_into_fixed_width_bins(value, min_bound, max_bound, nb_bins)</code>](quantize_into_fixed_width_bins.md): Get the `bin_range` in which belongs `value`
- [<code>quantize_into_bins(value, bin_bounds)</code>](quantize_into_bins.md): Get the `bin_range` in which belongs `value`
- [<code>weighted_average(element, weight)</code>](weighted_average.md): Returns the weigthed average elements.


## ✨ Transform string
Expand Down

0 comments on commit 514d28d

Please sign in to comment.