From 6487da01a6d1f5a4df9cf9cf86bff2161a569f47 Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Fri, 7 Apr 2017 16:28:03 -0600 Subject: [PATCH] Default time quantum on new frames. Sets the frame time quantum to the quantum on the parent database when creating a new frame. --- db.go | 13 +++++++++++-- db_test.go | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/db.go b/db.go index 36fb38a94..04a8c1328 100644 --- a/db.go +++ b/db.go @@ -368,8 +368,17 @@ func (db *DB) createFrame(name string, opt FrameOptions) (*Frame, error) { return nil, err } - // Update options. - f.SetRowLabel(opt.RowLabel) + // Default the time quantum to what is set on the DB. + if err := f.SetTimeQuantum(db.timeQuantum); err != nil { + f.Close() + return nil, err + } + + // Set options. + if err := f.SetRowLabel(opt.RowLabel); err != nil { + f.Close() + return nil, err + } // Add to database's frame lookup. db.frames[name] = f diff --git a/db_test.go b/db_test.go index 5ce17478f..f7cfc906a 100644 --- a/db_test.go +++ b/db_test.go @@ -34,6 +34,25 @@ func TestDB_CreateFrameIfNotExists(t *testing.T) { } } +// Ensure database defaults the time quantum on new frames. +func TestDB_CreateFrame_TimeQuantum(t *testing.T) { + db := MustOpenDB() + defer db.Close() + + // Set database time quantum. + if err := db.SetTimeQuantum(pilosa.TimeQuantum("YM")); err != nil { + t.Fatal(err) + } + + // Create frame. + f, err := db.CreateFrame("f", pilosa.FrameOptions{}) + if err != nil { + t.Fatal(err) + } else if q := f.TimeQuantum(); q != pilosa.TimeQuantum("YM") { + t.Fatalf("unexpected frame time quantum: %s", q) + } +} + // Ensure database can delete a frame. func TestDB_DeleteFrame(t *testing.T) { db := MustOpenDB()