Skip to content
This repository has been archived by the owner on Jul 25, 2023. It is now read-only.

[BSE-524] Support Quarter Interval #137

Open
wants to merge 3 commits into
base: bodo-calcite-1.30.0-dev
Choose a base branch
from

Conversation

pintaoz2
Copy link

@pintaoz2 pintaoz2 commented Jun 5, 2023

Support INTERVAL_QUARTER

@pintaoz2 pintaoz2 marked this pull request as ready for review June 6, 2023 20:21
@pintaoz2 pintaoz2 requested review from allai5 and keatoooon June 6, 2023 20:21
Copy link

@keatoooon keatoooon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fine to me, I think we should loop Johnathan in on this though.

@jsternberg
Copy link

jsternberg commented Jul 19, 2023

This is likely the wrong way to implement this. We should not add an additional type. If you notice, in order to implement this feature, we would have to modify 19 files in the fork which is not going to be maintainable. I see that TimeUnit.QUARTER is already defined and usable so we can use that. Otherwise, the new type isn't used anywhere in a meaningful way and a quarter is the exact same as 3 months.

You can very likely just simplify this entire thing by using INTERVAL_MONTH for the type and otherwise keep the interval parsing code identically.

Comment on lines +1211 to +1213
case QUARTER:
return evaluateIntervalLiteralAsQuarter(typeSystem, sign, value, value0,
pos);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice how this section, which is the only one that was required to implement this, uses TimeUnit.QUARTER and does not use INTERVAL_QUARTER at all.

case "qtr":
case "qtrs":
case "quarters":
unit = TimeUnit.QUARTER;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we see TimeUnit.QUARTER being used.

Comment on lines +437 to +440
if (intervalQualifier.timeUnitRange.toString().equals("QUARTER")) {
long monthsInQuarter = 3;
return ret[0] * ret[2] * monthsInQuarter;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not use toString() to perform comparisons. You already have an enum. Just compare the enum. TimeUnitRange.QUARTER exists.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looked into this further and this entire area isn't needed. Since one quarter is 3 months, just perform that translation before calling fillIntervalValueArray.

Comment on lines +78 to +79
INTERVAL_QUARTER(PrecScale.NO_NO, false, Types.OTHER,
SqlTypeFamily.INTERVAL_YEAR_MONTH),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just use INTERVAL_MONTH. There's no meaningful difference between how these are used.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants