[ 
https://issues.apache.org/jira/browse/CALCITE-4754?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17418369#comment-17418369
 ] 

Javier Rivas Rodriguez commented on CALCITE-4754:
-------------------------------------------------

Hi [~julianhyde], I have opened a [draft 
PR|https://github.com/apache/calcite/pull/2532] with several commits as 
suggested, to work on these changes.

I have left _supportsIsTrueInsideCaseWhen_ as it was temporarily. I think  I'm 
not able to completely understand the changes you are requesting and I'd need 
some help clarifying them. At the moment in a filter operation, the IS TRUE 
operator is added 
[here|https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java#L5733]
 tracking it to CALCITE-1042 and it gets carried over to the CASE (WHEN 
transformation. There are also 
[tests|https://github.com/apache/calcite/blob/master/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java#L224-L254]
 in the codebase verifying it is added. That is what led me to think that I 
could add the option of removing it based on the dialect.

As I have mentioned earlier, I'm keen to get some more directions on how to 
approach the problem if this is not the right angle and make those changes.

> Invalid Redshift SQL when executing a PIVOT query
> -------------------------------------------------
>
>                 Key: CALCITE-4754
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4754
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.27.0
>            Reporter: Javier Rivas Rodriguez
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.28.0
>
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> Given a Calcite connection to Redshift
> When running a query like the one below
> {code:java}
> SELECT * 
> FROM 
>   (SELECT field1, field2, field3 
>    FROM my_table) 
> PIVOT SUM(field1) FOR field2 IN (val1, val2){code}
> The SQL produced is something like
> {code:java}
> SELECT 
>   field3, 
>   SUM(field1) FILTER (WHERE field2 = val1), 
>   SUM(field1) FILTER (WHERE field2 = val2)
> FROM my_table
> GROUP BY field3{code}
> This SQL transformation is not accepted by Redshift
> The expected result would be something like
> {code:java}
> SELECT 
>  field3, 
>  SUM(CASE WHEN field2 = val1 THEN field1 ELSE NULL END), 
>  SUM(CASE WHEN field2 = val2 THEN field1 ELSE NULL END)
> FROM my_table
> GROUP BY field3
> {code}



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

Reply via email to