Skip to content

Commit

Permalink
fix: add a clear_sheet parameter for google sheet exporter (#1401)
Browse files Browse the repository at this point in the history
  • Loading branch information
jczhong84 authored Jan 26, 2024
1 parent 900d2d6 commit 0e1917c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
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

0 comments on commit 0e1917c

Please sign in to comment.