questdb / questdb/questdb

Support fills for SAMPLE BY FROM-TO with empty record sets

Open
#4,861 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

New feature SQL
Dominant language
Java
Stars
17.3k
Forks
1.6k
Avg merge
5d 10h
Merged PRs (30d)
28

Description

Is your feature request related to a problem?

The SAMPLE BY FROM-TO feature added support for pre and post filling result sets, around existing records.

It also added support for fills with parallel sample by.

However, using the fill with no present records is not well supported.

Technically, it works with parallel sample by. Here's an example on demo:

select pickup_datetime, count() from trips
sample by 1M from '2030-01-01' to '2031-01-01' fill(null)

image

However, a version of this query runing with a sequential sample by will return nothing:

select pickup_datetime, count() from trips
sample by 1M from '2030-01-01' to '2031-01-01' fill(null)
align to calendar with offset '10:00'

image

This is because initTimestamps() and SampleByFillValueNotKeyedRecordCursor are short-circuit in the zero records case, and were not designed to return anything.

Describe the solution you'd like.

Ideally, we should support it for both the parallel and sequential cases, as a convenience syntax for generating timestamps.

Describe alternatives you've considered.

Using timestamp_sequence() i.e

select x, timestamp_floor('1d', timestamp_sequence(systimestamp(), 86400 * 1000000L))
from long_sequence(3)

image

This doesn't make it easy to handle calendar aligned cases.

Full Name:

Nick Woolmer

Affiliation:

QuestDB

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing initTimestamps() and SampleByFillValueNotKeyedRecordCursor, which the issue identifies as short-circuiting when there are no records. Reproduce the parallel and sequential SAMPLE BY FROM-TO queries with empty record ranges, then verify that both return the requested filled timestamps, including calendar alignment with an offset.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, sql
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.