opensearch-project / opensearch-project/sql

[FEATURE] Add new data type: `PERIOD`

Open
#862 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement field types support SQL
Dominant language
Java
Stars
176
Forks
229
Avg merge
2d 21h
Merged PRs (30d)
43

Description

Is your feature request related to a problem?

MySQL has no such type, at least visible to user, but having a such type we can simplify processing few datetime functions.

... number in YYMMDD, YYMMDDhhmmss, YYYYMMDD, or YYYYMMDDhhmmss format. If the argument includes a time part, it may optionally include a fractional seconds part.

See PERIOD_ADD/PERIOD_DIFF functions in MySQL docs for reference.
The proposed solution would help fixing NOW() + 0 issue, see discussion in #754 and https://github.com/Bit-Quill/opensearch-project-sql/pull/92.

What solution would you like?

A new data type PERIOD

  1. Responsible for parsing and formatting
  2. Couldn't be casted to numeric types
  3. Expose a numeric type for user
  4. Has operators + and - overloaded with integers.

This will also simplify UNIX_TIMESTAMP implementation (#835) https://github.com/opensearch-project/sql/blob/e04d6f886aa57ee4fdd8e632127bb5d8a339113f/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunction.java#L915-L938

Other functions affected: all listed in #754, EXTRACT, UTC_DATE, UTC_TIME and UTC_TIMESTAMP (link).

What alternatives have you considered?

Keep using numeric type.

Do you have any additional context?

#855
#722
#835

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 with core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunction.java, especially the UNIX_TIMESTAMP implementation referenced in the issue. Read the linked MySQL PERIOD_ADD and PERIOD_DIFF documentation and review issues #754, #835, #855, and #722 for affected behavior. Done means a PERIOD type supports parsing and formatting, exposes a numeric value without numeric casts, and defines integer + and - operators.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, sql
Domain
database
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.