Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Athena query cost #4077

Merged
merged 1 commit into from
May 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions redash/query_runner/athena.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,21 @@ def configuration_schema(cls):
"title": "Athena Work Group",
"default": "primary",
},
"cost_per_tb": {
"type": "number",
"title": "Athena cost per Tb scanned (USD)",
"default": 5,
},
},
"required": ["region", "s3_staging_dir"],
"extra_options": ["glue"],
"order": ["region", "s3_staging_dir", "schema", "work_group"],
"extra_options": ["glue", "cost_per_tb"],
"order": [
"region",
"s3_staging_dir",
"schema",
"work_group",
"cost_per_tb",
],
"secret": ["aws_secret_key"],
}

Expand Down Expand Up @@ -234,14 +245,18 @@ def run_query(self, query, user):
athena_query_id = cursor.query_id
except AttributeError as e:
logger.debug("Athena Upstream can't get query_id: %s", e)

price = self.configuration.get("cost_per_tb", 5)
data = {
"columns": columns,
"rows": rows,
"metadata": {
"data_scanned": qbytes,
"athena_query_id": athena_query_id,
"query_cost": price * qbytes * 10e-12,
},
}

json_data = json_dumps(data, ignore_nan=True)
error = None
except Exception:
Expand Down