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)",