Hello, all Contributors to apache calcite:
        I am facing a throny issue on calcite-1.38.0, when use the sql 
following:

        ```sql```
        Select string_10_fun
        from (
                select string_10_fun
                from (
                        select string_10_fun
                        from (
                                select string_10_fun
                                from (
                                        select char_length(string_10) as 
string_10_fun
                                        from table
                                        order by double_01
                                )
                        )
                        order by string_10_fun
                )
                order by string_10_fun
        )
        order by string_10_fun
        ```

        At this point, the query executed to Druid generates a result, which 
column name is string_10_fun, is valued type DruidType.Long, However, in the  
method where the physical plan is generated, the sort function’s parameter 
string_10, as the same name as char_length(string_10), is defined as an integer 
type ( which definition is in 
core/org/apache/calcite/sql/fun/SqlStdOperatorTable.java). Since Java does not 
allow automatic conversion from a higher precision type long to a lower type 
integer, the result returned by Druid(type long) cannot be used as a valid 
parameter to sort and causing an error.
        To fix this question, I  tried to change the 
SqlStdOperatorTable.char_length to ReturnTypes.BIGINT_NULLABLE, but it will 
cause a series of new question, such as function lpad and function road. Both 
of them are supported to use Type integer as the second parameter but not long. 
If the result of char_length need to be used as lpad or rpad. It will also 
causing errors.

        I was wonder that if there are any solution could help solving this 
thorny issue.

        Thanks for your reading!

Reply via email to