Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ private static void assertBasic(SqlTypeName typeName) {
}
}

if (type.getSqlTypeName() == resultType.getSqlTypeName()
if (type.getSqlTypeName().getFamily() == resultType.getSqlTypeName().getFamily()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This may affect many more types than just TIMESTAMPs.

Copy link
Copy Markdown
Contributor Author

@snuyanzin snuyanzin May 31, 2026

Choose a reason for hiding this comment

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

can you elaborate on this please?
Asking since we are already inside this condition here

      } else if (SqlTypeUtil.isDatetime(type)) {
         ...
      }

https://github.com/snuyanzin/calcite/blob/16c2b1c3469f504bc540c9f12438778e2ca7b2d7/core/src/main/java/org/apache/calcite/sql/type/SqlTypeFactoryImpl.java#L550

&& type.getSqlTypeName().allowsPrec()
&& type.getPrecision() != resultType.getPrecision()) {
final int precision =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasToString;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand Down Expand Up @@ -172,6 +173,30 @@ class SqlTypeFactoryTest {
assertThat(leastRestrictive.getPrecision(), is(3));
}

/**
* Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-7567">
* LeastRetrictiveSqlType for TIMESTAMP, TIMESTAMP_LTZ might ignore precision</a>. */
@Test void testLeastRestrictiveForTimestampAndTimestampLtz() {
SqlTypeFixture f = new SqlTypeFixture();
RelDataType ltz0 =
f.typeFactory.createSqlType(SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE, 0);
RelDataType leastRestrictive =
f.typeFactory.leastRestrictive(Lists.newArrayList(ltz0, f.sqlTimestampPrec3));
assertThat(leastRestrictive, is(notNullValue()));
assertThat(leastRestrictive.getPrecision(), is(3));
}

@Test void testLeastRestrictiveForTimestampLtzAndTimestamp() {
SqlTypeFixture f = new SqlTypeFixture();
RelDataType ltz0 =
f.typeFactory.createSqlType(SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE, 0);
RelDataType leastRestrictive =
f.typeFactory.leastRestrictive(Lists.newArrayList(f.sqlTimestampPrec3, ltz0));
assertThat(leastRestrictive, is(notNullValue()));
assertThat(leastRestrictive.getPrecision(), is(3));
}

@Test void testLeastRestrictiveForTimestampAndDate() {
SqlTypeFixture f = new SqlTypeFixture();
RelDataType leastRestrictive =
Expand Down
Loading