Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IGNITE-23178 : Calcite. Least restrictive type priority DOUBLE over FLOAT #11520

Closed
wants to merge 8 commits into from

Conversation

Vladsz83
Copy link
Contributor

@Vladsz83 Vladsz83 commented Sep 9, 2024

Thank you for submitting the pull request to the Apache Ignite.

In order to streamline the review of the contribution
we ask you to ensure the following steps have been taken:

The Contribution Checklist

  • There is a single JIRA ticket related to the pull request.
  • The web-link to the pull request is attached to the JIRA ticket.
  • The JIRA ticket has the Patch Available state.
  • The pull request body describes changes that have been made.
    The description explains WHAT and WHY was made instead of HOW.
  • The pull request title is treated as the final commit message.
    The following pattern must be used: IGNITE-XXXX Change summary where XXXX - number of JIRA issue.
  • A reviewer has been mentioned through the JIRA comments
    (see the Maintainers list)
  • The pull request has been checked by the Teamcity Bot and
    the green visa attached to the JIRA ticket (see TC.Bot: Check PR)

Notes

If you need any help, please email [email protected] or ask anу advice on http://asf.slack.com #ignite channel.

@Vladsz83 Vladsz83 changed the title Calcite precisions IGNITE-23178 : Calcite. Least restrictive type priority DOUBLE over FLOAT Sep 10, 2024
Comment on lines 133 to 192
/** */
@Test
public void testMaxPrecision() {
assertEquals(STRING_PRECISION, typeSys.getMaxPrecision(SqlTypeName.CHAR));
assertEquals(STRING_PRECISION, typeSys.getMaxPrecision(SqlTypeName.VARCHAR));
assertEquals(STRING_PRECISION, typeSys.getMaxPrecision(SqlTypeName.BINARY));
assertEquals(STRING_PRECISION, typeSys.getMaxPrecision(SqlTypeName.VARBINARY));

assertEquals(3, typeSys.getMaxPrecision(SqlTypeName.TINYINT));
assertEquals(5, typeSys.getMaxPrecision(SqlTypeName.SMALLINT));
assertEquals(10, typeSys.getMaxPrecision(SqlTypeName.INTEGER));
assertEquals(19, typeSys.getMaxPrecision(SqlTypeName.BIGINT));
assertEquals(7, typeSys.getMaxPrecision(SqlTypeName.REAL));
assertEquals(15, typeSys.getMaxPrecision(SqlTypeName.FLOAT));
assertEquals(15, typeSys.getMaxPrecision(SqlTypeName.DOUBLE));
assertEquals(DECIMAL_PRECISION, typeSys.getMaxPrecision(SqlTypeName.DECIMAL));

assertEquals(0, typeSys.getMaxPrecision(SqlTypeName.DATE));
assertEquals(3, typeSys.getMaxPrecision(SqlTypeName.TIME));
assertEquals(3, typeSys.getMaxPrecision(SqlTypeName.TIME_WITH_LOCAL_TIME_ZONE));
assertEquals(3, typeSys.getMaxPrecision(SqlTypeName.TIMESTAMP));
assertEquals(3, typeSys.getMaxPrecision(SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE));
}

/** */
@Test
public void testDefaultPrecision() {
assertEquals(1, typeSys.getDefaultPrecision(SqlTypeName.CHAR));
assertEquals(RelDataType.PRECISION_NOT_SPECIFIED, typeSys.getDefaultPrecision(SqlTypeName.VARCHAR));
assertEquals(1, typeSys.getDefaultPrecision(SqlTypeName.BINARY));
assertEquals(RelDataType.PRECISION_NOT_SPECIFIED, typeSys.getDefaultPrecision(SqlTypeName.VARBINARY));

assertEquals(3, typeSys.getDefaultPrecision(SqlTypeName.TINYINT));
assertEquals(5, typeSys.getDefaultPrecision(SqlTypeName.SMALLINT));
assertEquals(10, typeSys.getDefaultPrecision(SqlTypeName.INTEGER));
assertEquals(19, typeSys.getDefaultPrecision(SqlTypeName.BIGINT));
assertEquals(7, typeSys.getDefaultPrecision(SqlTypeName.REAL));
assertEquals(15, typeSys.getDefaultPrecision(SqlTypeName.FLOAT));
assertEquals(15, typeSys.getDefaultPrecision(SqlTypeName.DOUBLE));
assertEquals(DECIMAL_PRECISION, typeSys.getDefaultPrecision(SqlTypeName.DECIMAL));

assertEquals(0, typeSys.getDefaultPrecision(SqlTypeName.DATE));
assertEquals(0, typeSys.getDefaultPrecision(SqlTypeName.TIME));
assertEquals(3, typeSys.getDefaultPrecision(SqlTypeName.TIME_WITH_LOCAL_TIME_ZONE));
assertEquals(3, typeSys.getDefaultPrecision(SqlTypeName.TIMESTAMP));
assertEquals(0, typeSys.getDefaultPrecision(SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE));
}


/** */
@Test
public void testMaxNumericPrecision() {
assertEquals(DECIMAL_PRECISION, typeSys.getMaxNumericPrecision());
}

/** */
@Test
public void testMaxNumericScale() {
assertEquals(DECIMAL_SCALE, typeSys.getMaxNumericScale());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need these tests? Values for max/default prcision are hardcoded in calcite and looks like we just compare one hardcoded value with another one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We manually implement several values. Like:

 @Override public int getMaxNumericScale() {
        return Short.MAX_VALUE;
    }

    /** {@inheritDoc} */
    @Override public int getMaxNumericPrecision() {
        return Short.MAX_VALUE;
    }

or

 @Override public int getDefaultPrecision(SqlTypeName typeName) {
        // Timestamps internally stored as millis, precision more than 3 is redundant. At the same time,
        // default Calcite precision 0 causes truncation when converting to TIMESTAMP without specifying precision.
        if (typeName == SqlTypeName.TIMESTAMP || typeName == SqlTypeName.TIME_WITH_LOCAL_TIME_ZONE)
            return 3;

        return super.getDefaultPrecision(typeName);
    }

It looks usefult to be sure that nothing would change. Or we can remove the tests. WDYT?

Copy link

sonarcloud bot commented Sep 24, 2024

@asfgit asfgit closed this in 3a789b6 Sep 24, 2024
@Vladsz83 Vladsz83 deleted the calcite-precisions branch September 24, 2024 19:21
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