[
https://issues.apache.org/jira/browse/CALCITE-7033?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17953147#comment-17953147
]
Yu Xu edited comment on CALCITE-7033 at 5/21/25 12:36 PM:
----------------------------------------------------------
Yes, you are right and I had debug it, then found VARCHAR type would return
maxPrecision for jdbc statement, maybe this is server behavior which not trim
the result:
SqlTypeFactoryImpl##leastRestrictiveSqlType
{code:java}
final int precision =
SqlTypeUtil.maxPrecision(resultType.getPrecision(),
type.getPrecision()); {code}
so maybe we can set max varchar length when we use VARCHAR type? [~vladsz83]
was (Author: JIRAUSER307770):
Yes you are right and I had debug it, then found VARCHAR type would return
maxPrecision for jdbc statement, maybe this is server behavior which not trim
the result:
SqlTypeFactoryImpl##leastRestrictiveSqlType
{code:java}
final int precision =
SqlTypeUtil.maxPrecision(resultType.getPrecision(),
type.getPrecision()); {code}
so maybe we can set max varchar length when we use VARCHAR type? [~vladsz83]
> Extended string literals on insert.
> -----------------------------------
>
> Key: CALCITE-7033
> URL: https://issues.apache.org/jira/browse/CALCITE-7033
> Project: Calcite
> Issue Type: Bug
> Affects Versions: 1.38.0, 1.39.0
> Reporter: Vladimir Steshin
> Priority: Minor
>
> Values of string literals might be extended with spaces to a shared least
> restrictive type on insert.
> Reproducer:
> {code:java}
> package org.apache.calcite.test;
> class ServerTest {
> @Test void testInsert() throws Exception {
> try (Connection c = connect(); Statement s = c.createStatement()) {
> s.execute("CREATE TABLE t (id INTEGER, name VARCHAR, ts TIMESTAMP)");
> s.executeUpdate("INSERT INTO t VALUES (5, 'name3', '2021-09-01
> 17:00:00'), (6, 'name11', '2021-12-01 18:00:00')");
> try (ResultSet r = s.executeQuery("select name from t")) {
> assertThat(r.next(), is(true));
> assertThat(r.getString(1), is("name3"));
> assertThat(r.next(), is(true));
> assertThat(r.getString(1), is("name11"));
> }
> }
> }
> } {code}
>
> Result:
> {code:java}
> java.lang.AssertionError:
> Expected: is "name3"
> but: was "name3 "{code}
>
> Value 'name3' is extended to 'name3 '.
>
> Appears {*}in v1.38{*}.
>
> This happens in _RelBuilder#_
> _setOp(boolean all, SqlKind kind, int n) -> convertLiteralTypes(...)_ because
> it takes shared least restrictive value type for both value sets. This value
> type becomes VARCHAR(6) for the string literals. Whereas one value is
> actually VARCHAR(5).
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)