Skip to content

Conversation

@xuzifu666
Copy link
Member

return TimeUnitRange.MONTH;
default:
return TimeUnitRange.DAY;
return unit;
Copy link
Member Author

Choose a reason for hiding this comment

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

The modification here is to enable the test class RexInterpreter to support time units such as HOUR/MINUTE/SECOND, otherwise here would not support such as HOUR/MINUTE/SECOND time unit. Since this class is only for testing, I think the modification is acceptable.

Copy link
Member

Choose a reason for hiding this comment

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

  public static int unixTimestampExtract(TimeUnitRange range,
      long timestamp) {
    return unixTimeExtract(range,
        (int) Math.floorMod(timestamp, MILLIS_PER_DAY));
  }

I noticed a piece of code that requires the input to be in days. It seems that modifying it in this way may not be appropriate. I understand that this is not intended for testing purposes, but rather serves constant folding.

if (inner == TimeUnit.QUARTER) {
return outer == TimeUnit.YEAR;
}
if (outer == TimeUnit.WEEK && inner != TimeUnit.YEAR && inner != TimeUnit.MONTH) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This change is because the order of WEEK is after YEAR/MONTH/DAY/HOUR/MINUTE/SECOND in TimeUnit, so the inner and outer cases are handled separately.

Copy link
Member

Choose a reason for hiding this comment

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

Although this is very old code, I still don't understand why the inner layer processing requires an additional check on the outer layer's type—including the case where inner == TimeUnit.QUARTER.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes,I also noticed this historical code. Since there were no issues involving it, I didn't modify it, and this shouldn't cause any problems.

}

/** Test case for simplifier of ceil/floor. */
/** Test case for
Copy link
Member Author

Choose a reason for hiding this comment

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

With the PR SELECT floor(floor(\"hire_date\" TO DAY) TO WEEK) FROM \"employee\" would simplify to SELECT FLOOR(\"hire_date\" TO WEEK)\nFROM \"foodmart\".\"employee\"

@sonarqubecloud
Copy link

return TimeUnitRange.MONTH;
default:
return TimeUnitRange.DAY;
return unit;
Copy link
Member

Choose a reason for hiding this comment

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

  public static int unixTimestampExtract(TimeUnitRange range,
      long timestamp) {
    return unixTimeExtract(range,
        (int) Math.floorMod(timestamp, MILLIS_PER_DAY));
  }

I noticed a piece of code that requires the input to be in days. It seems that modifying it in this way may not be appropriate. I understand that this is not intended for testing purposes, but rather serves constant folding.

if (inner == TimeUnit.QUARTER) {
return outer == TimeUnit.YEAR;
}
if (outer == TimeUnit.WEEK && inner != TimeUnit.YEAR && inner != TimeUnit.MONTH) {
Copy link
Member

Choose a reason for hiding this comment

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

Although this is very old code, I still don't understand why the inner layer processing requires an additional check on the outer layer's type—including the case where inner == TimeUnit.QUARTER.

* <a href="https://issues.apache.org/jira/browse/CALCITE-2178">[CALCITE-2178]
* Extend expression simplifier to work on datetime CEIL/FLOOR functions</a>,
* <a href="https://issues.apache.org/jira/browse/CALCITE-7304">[CALCITE-7304]
* Floor/Ceil can not simplify with WEEK TimeUnit</a>. */
Copy link
Member

Choose a reason for hiding this comment

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

As I mentioned earlier regarding a potential issue, I think we may need an actual execution result to verify its correctness.

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.

2 participants