From 10b60f5d5191a21679ece26378174cfd8e11cade Mon Sep 17 00:00:00 2001 From: Seebs Date: Thu, 9 Feb 2023 11:17:40 -0600 Subject: [PATCH] set default epoch for timestamps in system tables If we don't set an epoch, we get a cryptic message on the console. Note, this message isn't logged properly, it doesn't use the logger, it uses the `log` package. 2023/02/09 11:07:23 ERROR: converting timestamp options for end_time: checking overflow: custom epoch too far from Unix epoch: 0001-01-01 00:00:00 +0000 UTC Because this uses the log package, it doesn't go to the same place as other messages, making it a pain to debug. The underlying problem is that a timestamp can't just have a zero value for its epoch. So, we set a default epoch of 0 Unix Time. We should possibly revisit the question of whether the conversion in the top-level schema.go should handle an epoch which IsZero, but I'm not sure what "base" should be in that case. In practice, all existing usages except this one are specifying time.Unix(0, 0) already. --- sql3/planner/executionplannersystemtables.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sql3/planner/executionplannersystemtables.go b/sql3/planner/executionplannersystemtables.go index ac620e3e1..db263ce57 100644 --- a/sql3/planner/executionplannersystemtables.go +++ b/sql3/planner/executionplannersystemtables.go @@ -4,6 +4,7 @@ package planner import ( "context" + "time" pilosa "github.com/featurebasedb/featurebase/v3" "github.com/featurebasedb/featurebase/v3/dax" @@ -104,6 +105,7 @@ func indexInfoFromSystemTableB(st *systemTable) (*dax.Table, error) { for _, f := range st.schema { var baseType dax.BaseType + var epoch time.Time switch f.Type.(type) { case *parser.DataTypeInt: baseType = dax.BaseTypeInt @@ -113,13 +115,15 @@ func indexInfoFromSystemTableB(st *systemTable) (*dax.Table, error) { baseType = dax.BaseTypeString case *parser.DataTypeTimestamp: baseType = dax.BaseTypeTimestamp + epoch = time.Unix(0, 0) default: return nil, sql3.NewErrInternalf("unexpected system table field type '%T'", f.Type) } - + _ = dax.FieldOptions{} fld := &dax.Field{ - Name: dax.FieldName(f.ColumnName), - Type: baseType, + Name: dax.FieldName(f.ColumnName), + Type: baseType, + Options: dax.FieldOptions{Epoch: epoch}, } fields = append(fields, fld) }