You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by "Valeriy Trofimov (JIRA)" <ji...@apache.org> on 2019/04/03 00:19:00 UTC

[jira] [Created] (CALCITE-2974) Timestamp conversion performance can be improved

Valeriy Trofimov created CALCITE-2974:
-----------------------------------------

             Summary: Timestamp conversion performance can be improved
                 Key: CALCITE-2974
                 URL: https://issues.apache.org/jira/browse/CALCITE-2974
             Project: Calcite
          Issue Type: Improvement
          Components: core
    Affects Versions: 1.19.0
            Reporter: Valeriy Trofimov
             Fix For: next


RexSimplify.simplifyCast() is slow when converting a string to SQL Timestamp value. The slowness is caused this line:
{code:java}
executor.reduce(rexBuilder, ImmutableList.of(e), reducedValues);
{code}
Debugging this code line with my team showed that for timestamp conversion it loads a pre-compiled conversion code, which makes it slow. My team proposes to replace this line with the following code that greately improves performance:
{code:java}
if (typeName == SqlTypeName.CHAR && e.getType().getSqlTypeName() == SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE) {
    if (literal.getValue() instanceof NlsString) {
        String timestampStr = ((NlsString) literal.getValue()).getValue();
        Long timestampLong = SqlFunctions.toTimestampWithLocalTimeZone(timestampStr);
        reducedValues.add(rexBuilder.makeLiteral(timestampLong, e.getType(), true));
    }
}

if (reducedValues.isEmpty()) {
    executor.reduce(rexBuilder, ImmutableList.of(e), reducedValues);
}
{code}
Let us know if we can submit a pull request with this code change or if we've missed anything. Do you know the reason behind using a pre-compiled code for timestamp conversion?



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)