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

fix: add a clear_sheet parameter for google sheet exporter #1401

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "querybook",
"version": "3.29.0",
"version": "3.29.1",
"description": "A Big Data Webapp",
"private": true,
"scripts": {
Expand Down
14 changes: 13 additions & 1 deletion querybook/server/lib/export/exporters/gspread_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from env import QuerybookSettings
from logic.user import get_user_by_id, update_user_properties
from lib.export.base_exporter import BaseExporter
from lib.form import StructFormField, FormField
from lib.form import StructFormField, FormField, FormFieldType
from logic.query_execution import (
get_statement_execution_by_id,
update_statement_execution,
Expand Down Expand Up @@ -118,6 +118,13 @@ def export_form(self):
regex="^[A-Z]{1,3}[1-9][0-9]*$",
),
),
(
"clear_sheet",
FormField(
field_type=FormFieldType.Boolean,
helper="If checked, the sheet will be cleared before writing the result",
),
),
)

@with_session
Expand Down Expand Up @@ -159,6 +166,7 @@ def export(
sheet_url=None,
worksheet_title="Sheet1",
start_cell="A1",
clear_sheet=False,
):
sheet = None
try:
Expand All @@ -174,6 +182,7 @@ def export(
statement_execution_id,
worksheet_title,
start_cell,
clear_sheet,
)
sheet_url = f"https://docs.google.com/spreadsheets/d/{sheet.id}"
self._save_sheet_to_statement_meta(sheet_url, statement_execution_id)
Expand Down Expand Up @@ -213,6 +222,7 @@ def write_csv_to_sheet(
statement_execution_id: int,
worksheet_title: str,
start_cell: str,
clear_sheet: bool,
):
with DBSession() as session:
max_rows = self._get_max_rows(
Expand All @@ -236,6 +246,8 @@ def write_csv_to_sheet(
with gspread_worksheet(
sheet, worksheet_title, end_cell_coord[0], end_cell_coord[1]
) as worksheet:
if clear_sheet:
worksheet.clear()
csv = self._get_statement_execution_result_iter(
statement_execution_id, number_of_lines=max_rows, session=session
)
Expand Down
Loading