Skip to content

feat(sql): add some nanos function and fix cast for date#6247

Merged
bluestreak01 merged 14 commits intomasterfrom
victor_nano_fix
Oct 14, 2025
Merged

feat(sql): add some nanos function and fix cast for date#6247
bluestreak01 merged 14 commits intomasterfrom
victor_nano_fix

Conversation

@kafka1991
Copy link
Copy Markdown
Collaborator

@kafka1991 kafka1991 commented Oct 9, 2025

This PR adds some nanos timestamp functions for ease of use and introduces MillsTimestampDriver for better consistency between Date and Timestamp dataType:

  • Add now_ns() - Returns current timestamp with nanos
  • extract() function now supports extracting nanos from timestamps
  • Add rnd_timestamp_ns() - Generates random timestamps with nanos
  • Add timestamp_sequence_ns() function - Generates timestamp sequences with nanos
  • Introduce MillsTimestampDriver - New driver implementation for ColumnType.Date that maintains consistency with Timestamp logic. Since Date type is not supported as a designated timestamp, some timestamp-specific functions are not implemented and will throw UnsupportedOperationException

Breaking Changs 💥

  • rnd_timestamp() now only returns timestamp_micro precision (previously could return different precisions)

  • timestamp_sequence() now only returns timestamp_micro precision and no longer considers the first argument's type for timestampType determination

Close #6245 and #6224

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Oct 9, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch victor_nano_fix

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@bluestreak01
Copy link
Copy Markdown
Member

hey @nwoolmer would you mind documenting these please?

@glasstiger
Copy link
Copy Markdown
Contributor

[PR Coverage check]

😍 pass : 812 / 958 (84.76%)

file detail

path covered line new line coverage
🔵 io/questdb/std/datetime/nanotime/Nanos.java 13 28 46.43%
🔵 io/questdb/griffin/engine/functions/bind/BindVariableServiceImpl.java 1 2 50.00%
🔵 io/questdb/std/datetime/millitime/Dates.java 35 60 58.33%
🔵 io/questdb/std/datetime/millitime/DateFormatUtils.java 2 3 66.67%
🔵 io/questdb/griffin/engine/functions/date/NowNanoFunctionFactory.java 11 14 78.57%
🔵 io/questdb/griffin/engine/functions/rnd/RndTimestampNanoFunctionFactory.java 11 13 84.62%
🔵 io/questdb/cairo/MillsTimestampDriver.java 382 450 84.89%
🔵 io/questdb/cairo/ColumnTypeConverter.java 36 41 87.80%
🔵 io/questdb/std/datetime/microtime/Micros.java 24 27 88.89%
🔵 io/questdb/griffin/engine/functions/date/TimestampSequenceNanoFunctionFactory.java 9 10 90.00%
🔵 io/questdb/griffin/engine/functions/date/TimestampSequenceFunctionFactory.java 11 12 91.67%
🔵 io/questdb/cairo/NanosTimestampDriver.java 123 135 91.11%
🔵 io/questdb/cairo/MicrosTimestampDriver.java 126 135 93.33%
🔵 io/questdb/griffin/engine/functions/cast/CastStrToDateFunctionFactory.java 1 1 100.00%
🔵 io/questdb/griffin/engine/functions/cast/CastVarcharToDateFunctionFactory.java 1 1 100.00%
🔵 io/questdb/griffin/FunctionParser.java 1 1 100.00%
🔵 io/questdb/griffin/engine/functions/date/ExtractFromTimestampFunctionFactory.java 6 6 100.00%
🔵 io/questdb/griffin/engine/functions/StrFunction.java 1 1 100.00%
🔵 io/questdb/griffin/engine/functions/date/TimestampDiffFunctionFactory.java 4 4 100.00%
🔵 io/questdb/griffin/engine/functions/rnd/RndTimestampFunctionFactory.java 7 7 100.00%
🔵 io/questdb/griffin/engine/functions/VarcharFunction.java 1 1 100.00%
🔵 io/questdb/griffin/SqlKeywords.java 1 1 100.00%
🔵 io/questdb/griffin/RecordToRowCopierUtils.java 1 1 100.00%
🔵 io/questdb/griffin/engine/functions/json/JsonExtractFunction.java 2 2 100.00%
🔵 io/questdb/griffin/SqlUtil.java 2 2 100.00%

@bluestreak01 bluestreak01 merged commit fc057a5 into master Oct 14, 2025
35 checks passed
@bluestreak01 bluestreak01 deleted the victor_nano_fix branch October 14, 2025 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

date truncation behaviour inconsistent with nanos

3 participants