Skip to content

Commit

Permalink
pinot date fixes (#6362)
Browse files Browse the repository at this point in the history
* pinot date fixes

* comment
  • Loading branch information
pjain1 authored Jan 7, 2025
1 parent cfb74ab commit 1d29daa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 6 additions & 1 deletion runtime/drivers/olap.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,10 @@ func (d Dialect) DateTruncExpr(dim *runtimev1.MetricsViewSpec_DimensionV2, grain
case DialectPinot:
// TODO: Handle tz instead of ignoring it.
// TODO: Handle firstDayOfWeek and firstMonthOfYear. NOTE: We currently error when configuring these for Pinot in runtime/validate.go.
return fmt.Sprintf("ToDateTime(date_trunc('%s', %s, 'MILLISECONDS', '%s'), 'yyyy-MM-dd''T''HH:mm:ss''Z''')", specifier, expr, tz), nil
if tz == "" {
return fmt.Sprintf("date_trunc('%s', %s, 'MILLISECONDS')", specifier, expr), nil
}
return fmt.Sprintf("date_trunc('%s', %s, 'MILLISECONDS', '%s')", specifier, expr, tz), nil
default:
return "", fmt.Errorf("unsupported dialect %q", d)
}
Expand All @@ -490,6 +493,8 @@ func (d Dialect) DateDiff(grain runtimev1.TimeGrain, t1, t2 time.Time) (string,
return fmt.Sprintf("TIMESTAMPDIFF(%q, TIME_PARSE('%s'), TIME_PARSE('%s'))", unit, t1.Format(time.RFC3339), t2.Format(time.RFC3339)), nil
case DialectDuckDB:
return fmt.Sprintf("DATEDIFF('%s', TIMESTAMP '%s', TIMESTAMP '%s')", unit, t1.Format(time.RFC3339), t2.Format(time.RFC3339)), nil
case DialectPinot:
return fmt.Sprintf("DATETIMECONVERT(DATETRUNC('MILLISECONDS', %s) - DATETRUNC('MILLISECONDS', %s), '1:MILLISECONDS:EPOCH', '1:%s:EPOCH')", t1.Format(time.RFC3339), t2.Format(time.RFC3339), unit), nil
default:
return "", fmt.Errorf("unsupported dialect %q", d)
}
Expand Down
1 change: 0 additions & 1 deletion runtime/drivers/pinot/olap.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ func (i informationSchema) Lookup(ctx context.Context, db, schema, name string)
schemaFields = append(schemaFields, &runtimev1.StructType_Field{Name: field.Name, Type: databaseTypeToPB(field.DataType, !field.NotNull, singleValueField)})
}

// Mapping the schemaResponse to your Table structure
table := &drivers.Table{
Database: "",
DatabaseSchema: "",
Expand Down

0 comments on commit 1d29daa

Please sign in to comment.