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 issues with number precision when showing values in sql table #264

Merged
merged 1 commit into from
Nov 28, 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
13 changes: 13 additions & 0 deletions apps/api/src/python/query/bigquery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,13 @@ def _briefer_make_bq_query():
df = pd.concat(chunks, ignore_index=True)
convert_columns(df, columns_by_type)
initial_rows = json.loads(df.head(250).to_json(orient='records', date_format="iso"))

# convert all values to string to make sure we preserve the python values
# when displaying this data in the browser
for row in initial_rows:
for key in row:
row[key] = str(row[key])

if columns is None:
columns = get_columns(df)

Expand Down Expand Up @@ -209,6 +216,12 @@ def _briefer_make_bq_query():
if len(initial_rows) < 250:
initial_rows = json.loads(df.head(250).to_json(orient='records', date_format="iso"))

# convert all values to string to make sure we preserve the python values
# when displaying this data in the browser
for row in initial_rows:
for key in row:
row[key] = str(row[key])

columns = get_columns(df)
result = {
"type": "success",
Expand Down
7 changes: 7 additions & 0 deletions apps/api/src/python/query/duckdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ def _briefer_make_duckdb_query():

df = query.df()
rows = json.loads(df.head(250).to_json(orient='records', date_format='iso'))

# convert all values to string to make sure we preserve the python values
# when displaying this data in the browser
for row in rows:
for key in row:
row[key] = str(row[key])

columns = [{"name": col, "type": dtype.name} for col, dtype in df.dtypes.items()]
for col in columns:
dtype = df[col["name"]].dtype
Expand Down
43 changes: 25 additions & 18 deletions apps/api/src/python/query/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,26 +337,33 @@ export async function readDataframePage(
const code = `import json

if not ("${dataframeName}" in globals()):
import pandas as pd
try:
${dataframeName} = pd.read_parquet("/home/jupyteruser/.briefer/query-${queryId}.parquet.gzip")
except:
print(json.dumps({"type": "not-found"}))
import pandas as pd
try:
${dataframeName} = pd.read_parquet("/home/jupyteruser/.briefer/query-${queryId}.parquet.gzip")
except:
print(json.dumps({"type": "not-found"}))

if "${dataframeName}" in globals():
start = ${page * pageSize}
end = (${page} + 1) * ${pageSize}
rows = ${dataframeName}.iloc[start:end].to_json(
orient="records", date_format="iso"
)
columns = [{"name": col, "type": dtype.name} for col, dtype in ${dataframeName}.dtypes.items()]
result = {
"type": "success",
"rows": json.loads(rows),
"count": len(${dataframeName}),
"columns": columns
}
print(json.dumps(result))`
start = ${page * pageSize}
end = (${page} + 1) * ${pageSize}
rows = json.loads(${dataframeName}.iloc[start:end].to_json(
orient="records", date_format="iso"
))

# convert all values to string to make sure we preserve the python values
# when displaying this data in the browser
for row in rows:
for key in row:
row[key] = str(row[key])

columns = [{"name": col, "type": dtype.name} for col, dtype in ${dataframeName}.dtypes.items()]
result = {
"type": "success",
"rows": rows,
"count": len(${dataframeName}),
"columns": columns
}
print(json.dumps(result))`

let result: RunQueryResult | null = null
let error: Error | null = null
Expand Down
7 changes: 7 additions & 0 deletions apps/api/src/python/query/sqlalchemy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ def briefer_make_sqlalchemy_query():
df = convert_df(pd.concat([df, chunk], ignore_index=True))
if rows is None:
rows = json.loads(df.head(250).to_json(orient='records', date_format="iso"))

# convert all values to string to make sure we preserve the python values
# when displaying this data in the browser
for row in rows:
for key in row:
row[key] = str(row[key])

if columns is None:
columns = [{"name": col, "type": dtype.name} for col, dtype in chunk.dtypes.items()]

Expand Down