From 9f6d489be85ca59fd39feab81dd16b6f0d0fa3f4 Mon Sep 17 00:00:00 2001 From: Yuce Tekol Date: Mon, 14 Jan 2019 14:39:08 +0300 Subject: [PATCH 1/4] fixes #1823. Updates tests and docs for row range --- docs/query-language.md | 9 ++++----- executor.go | 5 ++--- executor_test.go | 16 +++++++++++++++- pql/pqlpeg_test.go | 8 ++++++++ 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/docs/query-language.md b/docs/query-language.md index 5eb4ef2d6..73e1cab7d 100644 --- a/docs/query-language.md +++ b/docs/query-language.md @@ -341,13 +341,12 @@ Row(stargazer=1) **Spec:** ``` -Row(=, , ) +Row(=, from=, to=) ``` **Description:** -Similar to `Row`, but only returns bits which were set with timestamps -between the given `start` (first) and `end` (second) timestamps. +Similar to `Row`, but only returns bits which were set with timestamps between the given `from` (inclusive) and `to` (exclusive) timestamps. Both `from` and `to` parameters are optional. The default for `to` timestamp is current time + 1 day. If a later end timestamp is required, specify it explicitly. **Result Type:** object with attrs and bits @@ -356,7 +355,7 @@ between the given `start` (first) and `end` (second) timestamps. Query all columns with a bit set in row 1 of a field (repositories that a user has starred), within a date range: ```request -Row(stargazer=1, 2010-01-01T00:00, 2017-03-02T03:00) +Row(stargazer=1, from='2010-01-01T00:00', to='2017-03-02T03:00') ``` ```response {{"attrs":{},"columns":[10]} @@ -836,7 +835,7 @@ GroupBy(, [RowsCall...], limit=, filter=) GroupBy returns the count of the intersection of every combination of rows taking one row each from the specified `Rows` calls. It returns only those -combinations for which the count is greater than 0. +combinations for which the count is greater than 0. The optional `filter` argument takes any type of `Row` query (e.g. Row, Union, Intersect, etc.) which will be intersected with each result prior to returning diff --git a/executor.go b/executor.go index b9f7c31ca..f68fec726 100644 --- a/executor.go +++ b/executor.go @@ -1253,9 +1253,8 @@ func (e *executor) executeRowShard(ctx context.Context, index string, c *pql.Cal // Set maximum "to" value if only "from" is set. We don't need to worry // about setting the minimum "from" since it is the zero value if omitted. if toTime.IsZero() { - // This is the maximum comparable time.Time value. - // https://stackoverflow.com/a/32620397 - toTime = time.Unix(1<<63-62135596801, 999999999) + // Set the end timestamp to current time + 1 day, in order to account for timezone differences. + toTime = time.Now().AddDate(0, 0, 1) } // Union bitmaps across all time-based views. diff --git a/executor_test.go b/executor_test.go index 19f39dc7f..034208485 100644 --- a/executor_test.go +++ b/executor_test.go @@ -1493,6 +1493,8 @@ func TestExecutor_Execute_Row_Range(t *testing.T) { Set(2, f=10, 2001-01-01T00:00)` readQueries := []string{ `Row(f=1, from=1999-12-31T00:00, to=2002-01-01T03:00)`, + `Row(f=1, from=1999-12-31T00:00)`, + `Row(f=1, to=2002-01-01T02:00)`, `Clear( 2, f=1)`, `Row(f=1, from=1999-12-31T00:00, to=2002-01-01T03:00)`, } @@ -1505,8 +1507,20 @@ func TestExecutor_Execute_Row_Range(t *testing.T) { } }) + t.Run("From", func(t *testing.T) { + if columns := responses[1].Results[0].(*pilosa.Row).Columns(); !reflect.DeepEqual(columns, []uint64{2, 3, 4, 5, 6, 7}) { + t.Fatalf("unexpected columns: %+v", columns) + } + }) + + t.Run("To", func(t *testing.T) { + if columns := responses[2].Results[0].(*pilosa.Row).Columns(); !reflect.DeepEqual(columns, []uint64{2, 3, 4, 5, 6}) { + t.Fatalf("unexpected columns: %+v", columns) + } + }) + t.Run("Clear", func(t *testing.T) { - if columns := responses[2].Results[0].(*pilosa.Row).Columns(); !reflect.DeepEqual(columns, []uint64{3, 4, 5, 6, 7}) { + if columns := responses[4].Results[0].(*pilosa.Row).Columns(); !reflect.DeepEqual(columns, []uint64{3, 4, 5, 6, 7}) { t.Fatalf("unexpected columns: %+v", columns) } }) diff --git a/pql/pqlpeg_test.go b/pql/pqlpeg_test.go index 3785bb713..54f73b809 100644 --- a/pql/pqlpeg_test.go +++ b/pql/pqlpeg_test.go @@ -248,6 +248,14 @@ func TestPEGWorking(t *testing.T) { name: "RangeTimeQuotes", input: `Row(a=4, from='2010-07-04T00:00', to="2010-08-04T00:00")`, ncalls: 1}, + { + name: "RangeTimeFromQuotes", + input: `Row(a=4, from='2010-07-04T00:00')`, + ncalls: 1}, + { + name: "RangeTimeToQuotes", + input: `Row(a=4, to="2010-08-04T00:00")`, + ncalls: 1}, { name: "Dashed Frame", input: "Set(1, my-frame=9)", From 600b39e4e575e76bc18224f8ba4cac9480be3459 Mon Sep 17 00:00:00 2001 From: Yuce Tekol Date: Mon, 14 Jan 2019 23:40:31 +0300 Subject: [PATCH 2/4] updates row range test with a timestamp > the default end timestamp --- executor_test.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/executor_test.go b/executor_test.go index 034208485..e8472bbe4 100644 --- a/executor_test.go +++ b/executor_test.go @@ -1480,17 +1480,21 @@ func TestExecutor_Execute_Sum(t *testing.T) { // Ensure a range query can be executed. func TestExecutor_Execute_Row_Range(t *testing.T) { t.Run("RowIDColumnID", func(t *testing.T) { - writeQuery := ` + // Create a timestamp just out of the current date + 1 day timestamp (default end timestamp). + nextDayExclusive := time.Now().AddDate(0, 0, 1).Add(1 * time.Second) + + writeQuery := fmt.Sprintf(` Set(2, f=1, 1999-12-31T00:00) Set(3, f=1, 2000-01-01T00:00) Set(4, f=1, 2000-01-02T00:00) Set(5, f=1, 2000-02-01T00:00) Set(6, f=1, 2001-01-01T00:00) Set(7, f=1, 2002-01-01T02:00) + Set(8, f=1, %s) Set(2, f=1, 1999-12-30T00:00) Set(2, f=1, 2002-02-01T00:00) - Set(2, f=10, 2001-01-01T00:00)` + Set(2, f=10, 2001-01-01T00:00)`, nextDayExclusive.Format("2006-01-02T15:04")) readQueries := []string{ `Row(f=1, from=1999-12-31T00:00, to=2002-01-01T03:00)`, `Row(f=1, from=1999-12-31T00:00)`, From d75e9eb772e9a39d3a22b00e3683a1a5972ef2a4 Mon Sep 17 00:00:00 2001 From: Yuce Tekol Date: Mon, 14 Jan 2019 23:45:58 +0300 Subject: [PATCH 3/4] updated row range test --- executor_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executor_test.go b/executor_test.go index e8472bbe4..19a660b50 100644 --- a/executor_test.go +++ b/executor_test.go @@ -1481,7 +1481,7 @@ func TestExecutor_Execute_Sum(t *testing.T) { func TestExecutor_Execute_Row_Range(t *testing.T) { t.Run("RowIDColumnID", func(t *testing.T) { // Create a timestamp just out of the current date + 1 day timestamp (default end timestamp). - nextDayExclusive := time.Now().AddDate(0, 0, 1).Add(1 * time.Second) + nextDayExclusive := time.Now().AddDate(0, 0, 1).Add(1 * time.Hour) writeQuery := fmt.Sprintf(` Set(2, f=1, 1999-12-31T00:00) From 76de81dacffb36e113dfb66d99a7faa87b9c09b4 Mon Sep 17 00:00:00 2001 From: Yuce Tekol Date: Mon, 14 Jan 2019 23:46:34 +0300 Subject: [PATCH 4/4] updated row range test --- executor_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executor_test.go b/executor_test.go index 19a660b50..0d42af8c5 100644 --- a/executor_test.go +++ b/executor_test.go @@ -1481,7 +1481,7 @@ func TestExecutor_Execute_Sum(t *testing.T) { func TestExecutor_Execute_Row_Range(t *testing.T) { t.Run("RowIDColumnID", func(t *testing.T) { // Create a timestamp just out of the current date + 1 day timestamp (default end timestamp). - nextDayExclusive := time.Now().AddDate(0, 0, 1).Add(1 * time.Hour) + nextDayExclusive := time.Now().AddDate(0, 0, 2) writeQuery := fmt.Sprintf(` Set(2, f=1, 1999-12-31T00:00)