Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
kuranium authored Feb 27, 2025
2 parents 1258e3d + d0af449 commit 38673a4
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 58 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ clean:

clean-all: clean
docker image rm --force \
redash/redash:10.1.0.b50633 redis:7-alpine maildev/maildev:latest \
redash/redash:latest redis:7-alpine maildev/maildev:latest \
pgautoupgrade/pgautoupgrade:15-alpine3.8 pgautoupgrade/pgautoupgrade:latest

down:
Expand Down
9 changes: 2 additions & 7 deletions client/app/pages/queries/hooks/useAutocompleteFlags.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import { useCallback, useMemo, useState } from "react";
import { reduce } from "lodash";
import localOptions from "@/lib/localOptions";

function calculateTokensCount(schema) {
return reduce(schema, (totalLength, table) => totalLength + table.columns.length, 0);
}

export default function useAutocompleteFlags(schema) {
const isAvailable = useMemo(() => calculateTokensCount(schema) <= 5000, [schema]);
const isAvailable = true;
const [isEnabled, setIsEnabled] = useState(localOptions.get("liveAutocomplete", true));

const toggleAutocomplete = useCallback(state => {
const toggleAutocomplete = useCallback((state) => {
setIsEnabled(state);
localOptions.set("liveAutocomplete", state);
}, []);
Expand Down
68 changes: 34 additions & 34 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ tzlocal = "4.3.1"
pyodbc = "5.1.0"
debugpy = "^1.8.9"
paramiko = "3.4.1"
oracledb = "2.5.1"

[tool.poetry.group.all_ds]
optional = true
Expand All @@ -113,7 +114,6 @@ nzalchemy = "^11.0.2"
nzpy = ">=1.15"
oauth2client = "4.1.3"
openpyxl = "3.0.7"
oracledb = "2.1.2"
pandas = "1.3.4"
phoenixdb = "0.7"
pinotdb = ">=0.4.5"
Expand Down
1 change: 1 addition & 0 deletions redash/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,7 @@ def next_state(op, value, threshold):
# boolean value is Python specific and most likely will be confusing to
# users.
value = str(value).lower()
value_is_number = False
else:
try:
value = float(value)
Expand Down
14 changes: 13 additions & 1 deletion redash/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import hashlib
import io
import json
import math
import os
import random
import re
Expand Down Expand Up @@ -120,6 +121,17 @@ def json_loads(data, *args, **kwargs):
return json.loads(data, *args, **kwargs)


# Convert NaN, Inf, and -Inf to None, as they are not valid JSON values.
def _sanitize_data(data):
if isinstance(data, dict):
return {k: _sanitize_data(v) for k, v in data.items()}
if isinstance(data, list):
return [_sanitize_data(v) for v in data]
if isinstance(data, float) and (math.isnan(data) or math.isinf(data)):
return None
return data


def json_dumps(data, *args, **kwargs):
"""A custom JSON dumping function which passes all parameters to the
json.dumps function."""
Expand All @@ -128,7 +140,7 @@ def json_dumps(data, *args, **kwargs):
# Float value nan or inf in Python should be render to None or null in json.
# Using allow_nan = True will make Python render nan as NaN, leading to parse error in front-end
kwargs.setdefault("allow_nan", False)
return json.dumps(data, *args, **kwargs)
return json.dumps(_sanitize_data(data), *args, **kwargs)


def mustache_render(template, context=None, **kwargs):
Expand Down
4 changes: 2 additions & 2 deletions redash/utils/query_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from sqlalchemy.orm.properties import ColumnProperty
from sqlalchemy.orm.query import _ColumnEntity
from sqlalchemy.orm.util import AliasedInsp
from sqlalchemy.sql.expression import asc, desc
from sqlalchemy.sql.expression import asc, desc, nullslast


def get_query_descriptor(query, entity, attr):
Expand Down Expand Up @@ -225,7 +225,7 @@ def __init__(self, silent=True, separator="-"):
def assign_order_by(self, entity, attr, func):
expr = get_query_descriptor(self.query, entity, attr)
if expr is not None:
return self.query.order_by(func(expr))
return self.query.order_by(nullslast(func(expr)))
if not self.silent:
raise QuerySorterException("Could not sort query with expression '%s'" % attr)
return self.query
Expand Down
31 changes: 31 additions & 0 deletions tests/utils/test_json_dumps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from redash.utils import json_dumps, json_loads
from tests import BaseTestCase


class TestJsonDumps(BaseTestCase):
"""
NaN, Inf, and -Inf are sanitized to None.
"""

def test_data_with_nan_is_sanitized(self):
input_data = {
"columns": [
{"name": "_col0", "friendly_name": "_col0", "type": "float"},
{"name": "_col1", "friendly_name": "_col1", "type": "float"},
{"name": "_col2", "friendly_name": "_col1", "type": "float"},
{"name": "_col3", "friendly_name": "_col1", "type": "float"},
],
"rows": [{"_col0": 1.0, "_col1": float("nan"), "_col2": float("inf"), "_col3": float("-inf")}],
}
expected_output_data = {
"columns": [
{"name": "_col0", "friendly_name": "_col0", "type": "float"},
{"name": "_col1", "friendly_name": "_col1", "type": "float"},
{"name": "_col2", "friendly_name": "_col1", "type": "float"},
{"name": "_col3", "friendly_name": "_col1", "type": "float"},
],
"rows": [{"_col0": 1.0, "_col1": None, "_col2": None, "_col3": None}],
}
json_data = json_dumps(input_data)
actual_output_data = json_loads(json_data)
self.assertEquals(actual_output_data, expected_output_data)
17 changes: 5 additions & 12 deletions viz-lib/src/visualizations/chart/plotly/prepareDefaultData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,36 +99,29 @@ function prepareSeries(series: any, options: any, numSeries: any, additionalOpti
};

const sourceData = new Map();

const labelsValuesMap = new Map();
const xValues: any[] = [];
const yValues: any[] = [];

const yErrorValues: any = [];
each(data, row => {
const x = normalizeValue(row.x, options.xAxis.type); // number/datetime/category
const y = cleanYValue(row.y, seriesYAxis === "y2" ? options.yAxis[1].type : options.yAxis[0].type); // depends on series type!
const yError = cleanNumber(row.yError); // always number
const size = cleanNumber(row.size); // always number
if (labelsValuesMap.has(x)) {
labelsValuesMap.set(x, labelsValuesMap.get(x) + y);
} else {
labelsValuesMap.set(x, y);
}
const aggregatedY = labelsValuesMap.get(x);

sourceData.set(x, {
x,
y: aggregatedY,
y,
yError,
size,
yPercent: null, // will be updated later
row,
});
xValues.push(x);
yValues.push(y);
yErrorValues.push(yError);
});

const xValues = Array.from(labelsValuesMap.keys());
const yValues = Array.from(labelsValuesMap.values());

const plotlySeries = {
visible: true,
hoverinfo: hoverInfoPattern,
Expand Down

0 comments on commit 38673a4

Please sign in to comment.