Skip to content

Commit

Permalink
histogram infinity
Browse files Browse the repository at this point in the history
  • Loading branch information
Egor Ryashin committed Jun 27, 2024
1 parent 35406b9 commit dd6c627
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
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

0 comments on commit dd6c627

Please sign in to comment.