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

null filling and coalescing for mv agg query #6088

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
2,580 changes: 1,295 additions & 1,285 deletions proto/gen/rill/runtime/v1/queries.pb.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions proto/gen/rill/runtime/v1/queries.pb.validate.go

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

1,482 changes: 746 additions & 736 deletions proto/gen/rill/runtime/v1/resources.pb.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions proto/gen/rill/runtime/v1/resources.pb.validate.go

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

7 changes: 7 additions & 0 deletions proto/gen/rill/runtime/v1/runtime.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,8 @@ paths:
title: Optional
exact:
type: boolean
fillMissing:
type: boolean
tags:
- QueryService
/v1/instances/{instanceId}/queries/metrics-views/{metricsViewName}/compare-toplist:
Expand Down Expand Up @@ -2999,6 +3001,9 @@ definitions:
type: object
validPercentOfTotal:
type: boolean
treatNullsAs:
type: string
title: TODO what should the type, using string values will not work when coalescing numeric cols
title: Measures are aggregated computed values
MetricsViewSpecMeasureWindow:
type: object
Expand Down Expand Up @@ -4711,6 +4716,8 @@ definitions:
title: Optional
exact:
type: boolean
fillMissing:
type: boolean
v1MetricsViewAggregationResponse:
type: object
properties:
Expand Down
1 change: 1 addition & 0 deletions proto/rill/runtime/v1/queries.proto
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ message MetricsViewAggregationRequest {
// Optional
MetricsViewFilter filter = 14; // Deprecated. should be removed once UI is moved to use new filters
bool exact = 17;
bool fill_missing = 21;
}

message MetricsViewAggregationResponse {
Expand Down
1 change: 1 addition & 0 deletions proto/rill/runtime/v1/resources.proto
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ message MetricsViewSpec {
string format_d3 = 7;
google.protobuf.Struct format_d3_locale = 13;
bool valid_percent_of_total = 6;
string treat_nulls_as = 14; // TODO what should the type, using string values will not work when coalescing numeric cols
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should just consider this to be a SQL expression to be templated into the query literally. For example:

treat_nulls_as: 0
treat_nulls_as: CAST(0 AS HUGEINT)
treat_nulls_as: "'Not available'"

}
// Connector containing the table
string connector = 1;
Expand Down
2 changes: 2 additions & 0 deletions runtime/compilers/rillv1/parse_metrics_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type MetricsViewYAML struct {
FormatD3Locale map[string]any `yaml:"format_d3_locale"`
Ignore bool `yaml:"ignore"` // Deprecated
ValidPercentOfTotal bool `yaml:"valid_percent_of_total"`
TreatNullsAs string `yaml:"treat_nulls_as"`
}
Security *SecurityPolicyYAML

Expand Down Expand Up @@ -696,6 +697,7 @@ func (p *Parser) parseMetricsView(node *Node) error {
FormatD3: measure.FormatD3,
FormatD3Locale: formatD3Locale,
ValidPercentOfTotal: measure.ValidPercentOfTotal,
TreatNullsAs: measure.TreatNullsAs,
})
}
if len(measures) == 0 {
Expand Down
4 changes: 3 additions & 1 deletion runtime/drivers/druid/druidsqldriver/druid_api_sql_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"time"

"github.com/google/uuid"
"github.com/rilldata/rill/admin/pkg/urlutil"
"github.com/rilldata/rill/runtime/drivers/druid/retrier"
)

Expand Down Expand Up @@ -83,7 +84,7 @@ func (c *sqlConnection) QueryContext(ctx context.Context, query string, args []d
context.AfterFunc(ctx, func() {
tctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
r, err := http.NewRequestWithContext(tctx, http.MethodDelete, c.dsn+"/"+dr.Context.SQLQueryID, http.NoBody)
r, err := http.NewRequestWithContext(tctx, http.MethodDelete, urlutil.MustJoinURL(c.dsn, dr.Context.SQLQueryID), http.NoBody)
if err != nil {
return
}
Expand Down Expand Up @@ -442,6 +443,7 @@ func newDruidRequest(query string, args []driver.NamedValue) *DruidRequest {
Value: arg.Value,
}
}

return &DruidRequest{
Query: query,
Header: true,
Expand Down
41 changes: 40 additions & 1 deletion runtime/drivers/olap.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/google/uuid"
"github.com/jmoiron/sqlx"
runtimev1 "github.com/rilldata/rill/proto/gen/rill/runtime/v1"

// Load IANA time zone data
_ "time/tzdata"
)
Expand Down Expand Up @@ -193,6 +192,10 @@ func (d Dialect) String() string {
}
}

func (d Dialect) ContextKeyArgPrefix() string {
return fmt.Sprintf("%s_context__", d.String())
}

func (d Dialect) CanPivot() bool {
return d == DialectDuckDB
}
Expand Down Expand Up @@ -475,6 +478,42 @@ func (d Dialect) DateDiff(grain runtimev1.TimeGrain, t1, t2 time.Time) (string,
}
}

/*func (d Dialect) SelectTimeRangeBins(start, end time.Time, grain metricsview.TimeGrain, alias string) (string, error) {
switch d {
case DialectDuckDB:
return fmt.Sprintf("SELECT range AS %s FROM range('%s'::TIMESTAMP, '%s'::TIMESTAMP, INTERVAL '1 %s')", d.EscapeIdentifier(alias), start.Format(time.RFC3339), end.Format(time.RFC3339), grain), nil
case DialectClickHouse:
// generate select like - SELECT '2021-01-01T00:00:00.000'::DATETIME64 AS "time" UNION ALL SELECT '2021-01-01T01:00:00.000'::DATETIME64 AS "time" ...
var sb strings.Builder
sb.WriteString("SELECT ")
for t := start; t.Before(end); t = timeutil.AddTime(t, grain.ToTimeutil(), 1) {
if t != start {
sb.WriteString(" UNION ALL ")
}
sb.WriteString(fmt.Sprintf("'%s'::DATETIME64 as %s", t.Format("2006-01-02T15:04:05.000"), d.EscapeIdentifier(alias)))
}
return sb.String(), nil
case DialectDruid:
// generate select like - SELECT * FROM (
// VALUES
// (CAST('2006-01-02T15:04:05Z' AS TIMESTAMP)),
// (CAST('2006-01-02T15:04:05Z' AS TIMESTAMP))
//) t (time)
var sb strings.Builder
sb.WriteString("SELECT * FROM (VALUES ")
for t := start; t.Before(end); t = timeutil.AddTime(t, grain.ToTimeutil(), 1) {
if t != start {
sb.WriteString(", ")
}
sb.WriteString(fmt.Sprintf("(CAST('%s' AS TIMESTAMP))", t.Format(time.RFC3339)))
}
sb.WriteString(fmt.Sprintf(") t (%s)", d.EscapeIdentifier(alias)))
return sb.String(), nil
default:
return "", fmt.Errorf("unsupported dialect %q", d)
}
}*/

func druidTimeFloorSpecifier(grain runtimev1.TimeGrain) string {
switch grain {
case runtimev1.TimeGrain_TIME_GRAIN_MILLISECOND:
Expand Down
Loading
Loading