You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Ruben Q L (Jira)" <ji...@apache.org> on 2020/04/23 15:52:00 UTC

[jira] [Updated] (CALCITE-3953) SqlToRelConverter creates char literal with coercibility IMPLICIT

     [ https://issues.apache.org/jira/browse/CALCITE-3953?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ruben Q L updated CALCITE-3953:
-------------------------------
    Description: 
The problem can be reproduced with the following test (to be added in SqlToRelConverterTest):
{code:java}
  @Test void testLiteralCoercibility() {
    final String sql = "select * from dept where name = 'abc'";
    final RelNode rel = tester.convertSqlToRel(sql).rel;
    final List<LogicalFilter> filters = new ArrayList<>();
    final RelShuttleImpl visitor = new RelShuttleImpl() {
      @Override public RelNode visit(LogicalFilter filter) {
        filters.add(filter);
        return super.visit(filter);
      }
    };
    visitor.visit(rel);
    assertThat(filters.size(), is(1));
    assertThat(filters.get(0).getCondition(), instanceOf(RexCall.class));
    final RexCall call = (RexCall) filters.get(0).getCondition();
    final RexNode literal = call.getOperands().stream().filter(RexLiteral.class::isInstance).findFirst().orElse(null);
    assertThat (literal, notNullValue());
    assertThat (literal.getType().getCollation(), notNullValue());
    assertThat (literal.getType().getCollation().getCoercibility(), is(SqlCollation.Coercibility.COERCIBLE));
  }
{code}
Which fails with the message:
{code:java}
java.lang.AssertionError: 
Expected: is <COERCIBLE>
     but: was <IMPLICIT>
{code}
According to {{SqlCollation.Coercibility}} javadoc:
 _A character value expression consisting of a value other than a column (e.g., a host variable or a literal) has the coercibility characteristic Coercible, with the default collation for its character repertoire._

  was:
The problem can be reproduced with the following test (to be added in SqlToRelConverterTest):
{code:java}
  @Test void testLiteralCoercibility() {
    final String sql = "select * from dept where name = 'abc'";
    final RelNode rel = tester.convertSqlToRel(sql).rel;
    final List<LogicalFilter> filters = new ArrayList<>();
    final RelShuttleImpl visitor = new RelShuttleImpl() {
      @Override public RelNode visit(LogicalFilter filter) {
        filters.add(filter);
        return super.visit(filter);
      }
    };
    visitor.visit(rel);
    assertThat(filters.size(), is(1));
    assertThat(filters.get(0).getCondition(), instanceOf(RexCall.class));
    RexCall call = (RexCall) filters.get(0).getCondition();
    RexNode literal = call.getOperands().stream().filter(RexLiteral.class::isInstance).findFirst().orElse(null);
    assertThat (literal, notNullValue());
    assertThat (literal.getType().getCollation(), notNullValue());
    assertThat (literal.getType().getCollation().getCoercibility(), is(SqlCollation.Coercibility.COERCIBLE));
  }
{code}
Which fails with the message:
{code:java}
java.lang.AssertionError: 
Expected: is <COERCIBLE>
     but: was <IMPLICIT>
{code}
According to {{SqlCollation.Coercibility}} javadoc:
 _A character value expression consisting of a value other than a column (e.g., a host variable or a literal) has the coercibility characteristic Coercible, with the default collation for its character repertoire._


> SqlToRelConverter creates char literal with coercibility IMPLICIT
> -----------------------------------------------------------------
>
>                 Key: CALCITE-3953
>                 URL: https://issues.apache.org/jira/browse/CALCITE-3953
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.22.0
>            Reporter: Ruben Q L
>            Priority: Major
>
> The problem can be reproduced with the following test (to be added in SqlToRelConverterTest):
> {code:java}
>   @Test void testLiteralCoercibility() {
>     final String sql = "select * from dept where name = 'abc'";
>     final RelNode rel = tester.convertSqlToRel(sql).rel;
>     final List<LogicalFilter> filters = new ArrayList<>();
>     final RelShuttleImpl visitor = new RelShuttleImpl() {
>       @Override public RelNode visit(LogicalFilter filter) {
>         filters.add(filter);
>         return super.visit(filter);
>       }
>     };
>     visitor.visit(rel);
>     assertThat(filters.size(), is(1));
>     assertThat(filters.get(0).getCondition(), instanceOf(RexCall.class));
>     final RexCall call = (RexCall) filters.get(0).getCondition();
>     final RexNode literal = call.getOperands().stream().filter(RexLiteral.class::isInstance).findFirst().orElse(null);
>     assertThat (literal, notNullValue());
>     assertThat (literal.getType().getCollation(), notNullValue());
>     assertThat (literal.getType().getCollation().getCoercibility(), is(SqlCollation.Coercibility.COERCIBLE));
>   }
> {code}
> Which fails with the message:
> {code:java}
> java.lang.AssertionError: 
> Expected: is <COERCIBLE>
>      but: was <IMPLICIT>
> {code}
> According to {{SqlCollation.Coercibility}} javadoc:
>  _A character value expression consisting of a value other than a column (e.g., a host variable or a literal) has the coercibility characteristic Coercible, with the default collation for its character repertoire._



--
This message was sent by Atlassian Jira
(v8.3.4#803005)