[
https://issues.apache.org/jira/browse/CALCITE-4713?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Zuozhi Wang updated CALCITE-4713:
---------------------------------
Description:
When using JavaTypeFactoryImpl, calling `leastRestrictive` with two
`JavaType(String)` types gives a wrong return type of `VARCHAR` (SqlType). The
expected return type should still be `JavaType(String)`
See the following test case:
{code:java}
@Test void testLeastRestrictiveWithWithJavaString() {
JavaTypeFactoryImpl javaTypeFactory = new JavaTypeFactoryImpl();
RelDataType javaStringType = javaTypeFactory.createJavaType(String.class);
// leastRestrictive of two same JavaType(String) types
RelDataType leastRestrictive = javaTypeFactory.leastRestrictive(
Arrays.asList(javaStringType, javaStringType));
// expect leastRestrictive to also be JavaType(String)
// but actual value is VARCHAR (BasicSqlType)
assertEquals(javaStringType, leastRestrictive);
}
{code}
We are currently investigating a fix of this issue.
JavaTypeFactoryImpl extends SqlTypeFactoryImpl, and the `leastRestrictive` is
not overridden. In `SqlTypeFactoryImpl`, `leastRestrictive` will first try to
treat the input types as sql types, and call `leastRestrictiveSqlType`,
therefore `JavaType(String)` is treated as SqlType `VARCHAR`.
One possible fix of this issue is to override the `leastRestrictive` function
in `JavaTypeFactoryImpl` to call `leastRestrictiveByCast` in SqlTypeFactoryImpl
instead.
{code:java}
// in JavaTypeFactoryImpl
// also need to change SqlTypeFactoryImpl#leastRestrictiveByCast from private
to protected
@Override
public @Nullable RelDataType leastRestrictive(List<RelDataType> types) {
return super.leastRestrictiveByCast(types);
}
{code}
was:
When using JavaTypeFactoryImpl, calling `leastRestrictive` with two
`JavaType(String)` types gives a wrong return type of `VARCHAR` (SqlType). The
expected return type should still be `JavaType(String)`
See the following test case:
{code:java}
@Test void testLeastRestrictiveWithWithJavaString() {
RelDataType javaStringType = TYPE_FACTORY.createJavaType(String.class);
// leastRestrictive of two same JavaType(String) types
RelDataType leastRestrictive = TYPE_FACTORY.leastRestrictive(
Arrays.asList(javaStringType, javaStringType));
// expect leastRestrictive to also be JavaType(String)
// but actual value is VARCHAR (BasicSqlType)
assertEquals(javaStringType, leastRestrictive);
}
{code}
We are currently investigating a fix of this issue.
JavaTypeFactoryImpl extends SqlTypeFactoryImpl, and the `leastRestrictive` is
not overridden. In `SqlTypeFactoryImpl`, `leastRestrictive` will first try to
treat the input types as sql types, and call `leastRestrictiveSqlType`,
therefore `JavaType(String)` is treated as SqlType `VARCHAR`.
One possible fix of this issue is to override the `leastRestrictive` function
in `JavaTypeFactoryImpl` to call `leastRestrictiveByCast` in SqlTypeFactoryImpl
instead.
{code:java}
// in JavaTypeFactoryImpl
// also need to change SqlTypeFactoryImpl#leastRestrictiveByCast from private
to protected
@Override
public @Nullable RelDataType leastRestrictive(List<RelDataType> types) {
return super.leastRestrictiveByCast(types);
}
{code}
> JavaTypeFactory#leastRestrictive returns wrong type for JavaType(String)
> ------------------------------------------------------------------------
>
> Key: CALCITE-4713
> URL: https://issues.apache.org/jira/browse/CALCITE-4713
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.27.0
> Reporter: Zuozhi Wang
> Priority: Minor
>
> When using JavaTypeFactoryImpl, calling `leastRestrictive` with two
> `JavaType(String)` types gives a wrong return type of `VARCHAR` (SqlType).
> The expected return type should still be `JavaType(String)`
> See the following test case:
> {code:java}
> @Test void testLeastRestrictiveWithWithJavaString() {
> JavaTypeFactoryImpl javaTypeFactory = new JavaTypeFactoryImpl();
> RelDataType javaStringType = javaTypeFactory.createJavaType(String.class);
> // leastRestrictive of two same JavaType(String) types
> RelDataType leastRestrictive = javaTypeFactory.leastRestrictive(
> Arrays.asList(javaStringType, javaStringType));
> // expect leastRestrictive to also be JavaType(String)
> // but actual value is VARCHAR (BasicSqlType)
> assertEquals(javaStringType, leastRestrictive);
> }
> {code}
> We are currently investigating a fix of this issue.
> JavaTypeFactoryImpl extends SqlTypeFactoryImpl, and the `leastRestrictive` is
> not overridden. In `SqlTypeFactoryImpl`, `leastRestrictive` will first try to
> treat the input types as sql types, and call `leastRestrictiveSqlType`,
> therefore `JavaType(String)` is treated as SqlType `VARCHAR`.
> One possible fix of this issue is to override the `leastRestrictive` function
> in `JavaTypeFactoryImpl` to call `leastRestrictiveByCast` in
> SqlTypeFactoryImpl instead.
> {code:java}
> // in JavaTypeFactoryImpl
> // also need to change SqlTypeFactoryImpl#leastRestrictiveByCast from
> private to protected
> @Override
> public @Nullable RelDataType leastRestrictive(List<RelDataType> types) {
> return super.leastRestrictiveByCast(types);
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)