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

Histogram infinity #5156

Merged
merged 2 commits into from
Jun 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
22 changes: 8 additions & 14 deletions runtime/queries/column_desc_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,14 @@ func (q *ColumnDescriptiveStatistics) Resolve(ctx context.Context, rt *runtime.R
switch olap.Dialect() {
case drivers.DialectDuckDB:
descriptiveStatisticsSQL = fmt.Sprintf("SELECT "+
"min(%s)::DOUBLE as min, "+
"approx_quantile(%s, 0.25)::DOUBLE as q25, "+
"approx_quantile(%s, 0.5)::DOUBLE as q50, "+
"approx_quantile(%s, 0.75)::DOUBLE as q75, "+
"max(%s)::DOUBLE as max, "+
"avg(%s)::DOUBLE as mean, "+
"stddev_pop(%s)::DOUBLE as sd "+
"FROM %s",
sanitizedColumnName,
sanitizedColumnName,
sanitizedColumnName,
sanitizedColumnName,
sanitizedColumnName,
sanitizedColumnName,
"min(%[1]s)::DOUBLE as min, "+
"approx_quantile(%[1]s, 0.25)::DOUBLE as q25, "+
"approx_quantile(%[1]s, 0.5)::DOUBLE as q50, "+
"approx_quantile(%[1]s, 0.75)::DOUBLE as q75, "+
"max(%[1]s)::DOUBLE as max, "+
"avg(%[1]s)::DOUBLE as mean, "+
"'NaN'::DOUBLE as sd "+
"FROM %[2]s WHERE NOT isinf(%[1]s) ",
sanitizedColumnName,
olap.Dialect().EscapeTable(q.Database, q.DatabaseSchema, q.TableName))
case drivers.DialectClickHouse:
Expand Down
8 changes: 4 additions & 4 deletions runtime/queries/column_numeric_histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ func (q *ColumnNumericHistogram) calculateFDMethod(ctx context.Context, rt *runt
WITH data_table AS (
SELECT %[1]s as %[2]s
FROM %[3]s
WHERE %[2]s IS NOT NULL
WHERE %[2]s IS NOT NULL AND NOT isinf(%[2]s)
), values AS (
SELECT %[2]s as value from data_table
WHERE %[2]s IS NOT NULL
WHERE %[2]s IS NOT NULL AND NOT isinf(%[2]s)
), buckets AS (
SELECT
`+rangeNumbersCol(olap.Dialect())+`::DOUBLE as bucket,
Expand Down Expand Up @@ -293,7 +293,7 @@ func (q *ColumnNumericHistogram) calculateDiagnosticMethod(ctx context.Context,
WITH data_table AS (
SELECT %[1]s as %[2]s
FROM %[3]s
WHERE %[2]s IS NOT NULL
WHERE %[2]s IS NOT NULL AND NOT isinf(%[2]s)
), S AS (
SELECT
min(%[2]s) as minVal,
Expand Down Expand Up @@ -398,7 +398,7 @@ func getMinMaxRange(ctx context.Context, olap drivers.OLAPStore, columnName, dat
max(%[2]s) AS max,
max(%[2]s) - min(%[2]s) AS range
FROM %[1]s
WHERE %[2]s IS NOT NULL
WHERE %[2]s IS NOT NULL AND NOT isinf(%[2]s)
`,
olap.Dialect().EscapeTable(database, databaseSchema, tableName),
selectColumn,
Expand Down
5 changes: 3 additions & 2 deletions runtime/server/queries_columns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package server_test
import (
"context"
"fmt"
"math"
"testing"
"time"

Expand Down Expand Up @@ -144,7 +145,7 @@ func TestServer_ColumnDescriptiveStatistics(t *testing.T) {
_, err := server.ColumnDescriptiveStatistics(testCtx(), &runtimev1.ColumnDescriptiveStatisticsRequest{InstanceId: instanceId, TableName: "test", ColumnName: "col"})
if err != nil {
// "col" is a varchar column, so this should fail
require.ErrorContains(t, err, "No function matches the given name and argument types 'approx_quantile(VARCHAR, DECIMAL(3,2))'")
require.ErrorContains(t, err, "No function matches the given name and argument types 'isinf(VARCHAR)'")
}

res, err := server.ColumnDescriptiveStatistics(testCtx(), &runtimev1.ColumnDescriptiveStatisticsRequest{InstanceId: instanceId, TableName: "test", ColumnName: "val"})
Expand All @@ -156,7 +157,7 @@ func TestServer_ColumnDescriptiveStatistics(t *testing.T) {
require.Equal(t, 1.0, res.NumericSummary.GetNumericStatistics().Q25)
require.Equal(t, 1.0, res.NumericSummary.GetNumericStatistics().Q50)
require.Equal(t, 4.0, res.NumericSummary.GetNumericStatistics().Q75)
require.Equal(t, 1.6, res.NumericSummary.GetNumericStatistics().Sd)
require.True(t, math.IsNaN(res.NumericSummary.GetNumericStatistics().Sd))
}

func TestServer_ColumnDescriptiveStatistics_EmptyModel(t *testing.T) {
Expand Down
Loading