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

itxiangkui updated CALCITE-5173:
--------------------------------
    Description: 
when i defined a table 

+"implements {color:#4c9aff}ProjectableFilterableTable{color}, 
TranslatableTable"+

then the sql 
{code:java}
select count(1) from `database`.`table` where c1 is not null; {code}
may trigger a error like 
{code:java}
java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.String
        at Baz$1.apply(janino650997550716152417.java:51)
        at Baz$1.apply(janino650997550716152417.java)
        at 
org.apache.calcite.adapter.enumerable.BasicAggregateLambdaFactory$AccumulatorAdderSeq.apply(BasicAggregateLambdaFactory.java:81)
        at 
org.apache.calcite.linq4j.EnumerableDefaults.aggregate(EnumerableDefaults.java:133)
        at 
org.apache.calcite.linq4j.DefaultEnumerable.aggregate(DefaultEnumerable.java:107)
        at Baz.bind(janino650997550716152417.java:68)
        at 
org.apache.calcite.jdbc.CalcitePrepare$CalciteSignature.enumerable(CalcitePrepare.java:363)
        at 
org.apache.calcite.jdbc.CalciteConnectionImpl.enumerable(CalciteConnectionImpl.java:323)
 {code}
 

the janino code like 
{code:java}
public org.apache.calcite.linq4j.Enumerable bind(final 
org.apache.calcite.DataContext root) {
  final org.apache.calcite.rel.RelNode v1stashed = 
(org.apache.calcite.rel.RelNode) root.get("v1stashed");
  final org.apache.calcite.interpreter.Interpreter interpreter = new 
org.apache.calcite.interpreter.Interpreter(
    root,
    v1stashed);
  java.util.List accumulatorAdders = new java.util.LinkedList();
  accumulatorAdders.add(new org.apache.calcite.linq4j.function.Function2() {
    public Record1_0 apply(Record1_0 acc, String in) {
      acc.f0++;
      return acc;
    }
    public Record1_0 apply(Object acc, Object in) {
      return apply(
        (Record1_0) acc,
        (String) in);
    }
  }
  );
  org.apache.calcite.adapter.enumerable.AggregateLambdaFactory lambdaFactory = 
new org.apache.calcite.adapter.enumerable.BasicAggregateLambdaFactory(
    new org.apache.calcite.linq4j.function.Function0() {
      public Object apply() {
        long COUNTa0s0;
        COUNTa0s0 = 0L;
        Record1_0 record0;
        record0 = new Record1_0();
        record0.f0 = COUNTa0s0;
        return record0;
      }
    }
,
    accumulatorAdders);
  return 
org.apache.calcite.linq4j.Linq4j.singletonEnumerable(org.apache.calcite.runtime.Enumerables.slice0(interpreter).aggregate(lambdaFactory.accumulatorInitializer().apply(),
 lambdaFactory.accumulatorAdder(), lambdaFactory.singleGroupResultSelector(new 
org.apache.calcite.linq4j.function.Function1() {
      public long apply(Record1_0 acc) {
        return acc.f0;
      }
      public Object apply(Object acc) {
        return apply(
          (Record1_0) acc);
      }
    }
    )));
}
public Class getElementType() {
  return long.class;
}
 {code}
 

and when you define a table 

+"implements {color:#4c9aff}FilterableTable{color}, TranslatableTable"+

it will be ok!

  was:When


> ProjectableFilterableTable may provoke DefaultEnumerable “java.lang.Long 
> cannot be cast to java.lang.String” erro
> -----------------------------------------------------------------------------------------------------------------
>
>                 Key: CALCITE-5173
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5173
>             Project: Calcite
>          Issue Type: Bug
>          Components: core, jdbc-adapter
>    Affects Versions: 1.30.0
>            Reporter: itxiangkui
>            Priority: Major
>
> when i defined a table 
> +"implements {color:#4c9aff}ProjectableFilterableTable{color}, 
> TranslatableTable"+
> then the sql 
> {code:java}
> select count(1) from `database`.`table` where c1 is not null; {code}
> may trigger a error like 
> {code:java}
> java.lang.ClassCastException: java.lang.Long cannot be cast to 
> java.lang.String
>         at Baz$1.apply(janino650997550716152417.java:51)
>         at Baz$1.apply(janino650997550716152417.java)
>         at 
> org.apache.calcite.adapter.enumerable.BasicAggregateLambdaFactory$AccumulatorAdderSeq.apply(BasicAggregateLambdaFactory.java:81)
>         at 
> org.apache.calcite.linq4j.EnumerableDefaults.aggregate(EnumerableDefaults.java:133)
>         at 
> org.apache.calcite.linq4j.DefaultEnumerable.aggregate(DefaultEnumerable.java:107)
>         at Baz.bind(janino650997550716152417.java:68)
>         at 
> org.apache.calcite.jdbc.CalcitePrepare$CalciteSignature.enumerable(CalcitePrepare.java:363)
>         at 
> org.apache.calcite.jdbc.CalciteConnectionImpl.enumerable(CalciteConnectionImpl.java:323)
>  {code}
>  
> the janino code like 
> {code:java}
> public org.apache.calcite.linq4j.Enumerable bind(final 
> org.apache.calcite.DataContext root) {
>   final org.apache.calcite.rel.RelNode v1stashed = 
> (org.apache.calcite.rel.RelNode) root.get("v1stashed");
>   final org.apache.calcite.interpreter.Interpreter interpreter = new 
> org.apache.calcite.interpreter.Interpreter(
>     root,
>     v1stashed);
>   java.util.List accumulatorAdders = new java.util.LinkedList();
>   accumulatorAdders.add(new org.apache.calcite.linq4j.function.Function2() {
>     public Record1_0 apply(Record1_0 acc, String in) {
>       acc.f0++;
>       return acc;
>     }
>     public Record1_0 apply(Object acc, Object in) {
>       return apply(
>         (Record1_0) acc,
>         (String) in);
>     }
>   }
>   );
>   org.apache.calcite.adapter.enumerable.AggregateLambdaFactory lambdaFactory 
> = new org.apache.calcite.adapter.enumerable.BasicAggregateLambdaFactory(
>     new org.apache.calcite.linq4j.function.Function0() {
>       public Object apply() {
>         long COUNTa0s0;
>         COUNTa0s0 = 0L;
>         Record1_0 record0;
>         record0 = new Record1_0();
>         record0.f0 = COUNTa0s0;
>         return record0;
>       }
>     }
> ,
>     accumulatorAdders);
>   return 
> org.apache.calcite.linq4j.Linq4j.singletonEnumerable(org.apache.calcite.runtime.Enumerables.slice0(interpreter).aggregate(lambdaFactory.accumulatorInitializer().apply(),
>  lambdaFactory.accumulatorAdder(), 
> lambdaFactory.singleGroupResultSelector(new 
> org.apache.calcite.linq4j.function.Function1() {
>       public long apply(Record1_0 acc) {
>         return acc.f0;
>       }
>       public Object apply(Object acc) {
>         return apply(
>           (Record1_0) acc);
>       }
>     }
>     )));
> }
> public Class getElementType() {
>   return long.class;
> }
>  {code}
>  
> and when you define a table 
> +"implements {color:#4c9aff}FilterableTable{color}, TranslatableTable"+
> it will be ok!



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to