GitHub user HeartSaVioR opened a pull request:

    https://github.com/apache/storm/pull/1709

    STORM-2116 [Storm SQL] Support 'CASE' statement

    NOTE: This patch is on top of STORM-2089 and STORM-2111, and STORM-2113.
    
    ```
    SELECT CASE WHEN NAME IN ('a', 'abc', 'abcde') THEN UPPER('a') 
    WHEN UPPER(NAME) = 'AB' THEN 'b' ELSE {fn CONCAT(NAME, '#')} END FROM FOO
    ```
    (`{fn CONCAT(a, b)}` is same to `a || b`. Please refer [SQL 
reference](http://calcite.apache.org/docs/reference.html) page on Calcite web 
site.)
    
    `CASE` statement in above sql statement is translated to Java code as
    
    ```
    import org.apache.storm.tuple.Values;
    java.lang.String t1 = null;
    // WHEN #0 THEN #1
    java.lang.Boolean t2 = Boolean.FALSE;
    java.lang.Boolean anyNull_t3 = Boolean.FALSE;
    // operand #0
    java.lang.String t5 = (java.lang.String)(_data.get(1));
    final java.lang.String t6 = (java.lang.String) "a";
    java.lang.Boolean t4 = 
org.apache.storm.sql.runtime.StormSqlFunctions.eq(t5,t6);
    final java.lang.Boolean t7 = t4;
    if ((t7 != null) && (t7)) { t2 = Boolean.TRUE; anyNull_t3 = Boolean.FALSE; }
    else {
    // updating null occurrence with operand #0
    if ((t7 == null) && !(anyNull_t3)) { anyNull_t3 = Boolean.TRUE; }
    // operand #1
    java.lang.String t9 = (java.lang.String)(_data.get(1));
    final java.lang.String t10 = (java.lang.String) "abc";
    java.lang.Boolean t8 = 
org.apache.storm.sql.runtime.StormSqlFunctions.eq(t9,t10);
    final java.lang.Boolean t11 = t8;
    if ((t11 != null) && (t11)) { t2 = Boolean.TRUE; anyNull_t3 = 
Boolean.FALSE; }
    else {
    // updating null occurrence with operand #1
    if ((t11 == null) && !(anyNull_t3)) { anyNull_t3 = Boolean.TRUE; }
    // operand #2
    java.lang.String t13 = (java.lang.String)(_data.get(1));
    final java.lang.String t14 = (java.lang.String) "abcde";
    java.lang.Boolean t12 = 
org.apache.storm.sql.runtime.StormSqlFunctions.eq(t13,t14);
    final java.lang.Boolean t15 = t12;
    if ((t15 != null) && (t15)) { t2 = Boolean.TRUE; anyNull_t3 = 
Boolean.FALSE; }
    else {
    // updating null occurrence with operand #2
    if ((t15 == null) && !(anyNull_t3)) { anyNull_t3 = Boolean.TRUE; }
    }}}
    t2 = anyNull_t3 ? ((java.lang.Boolean) null) : t2;
    final java.lang.String t17;
    if (false) {}
    else { t17 = org.apache.calcite.runtime.SqlFunctions.upper("a"); }
    final java.lang.String t16 = (java.lang.String) t17;
    if (t2 == true) { t1 = t16; }
    else {
    // WHEN #2 THEN #3
    final java.lang.String t20;
    java.lang.String t21 = (java.lang.String)(_data.get(1));
    if (false) {}
    else if (t21 == null) { t20 = null; }
    else { t20 = org.apache.calcite.runtime.SqlFunctions.upper(t21); }
    final java.lang.String t19 = (java.lang.String) t20;
    java.lang.Boolean t18 = 
org.apache.storm.sql.runtime.StormSqlFunctions.eq(t19,"AB");
    if (t18 == true) { t1 = "b"; }
    else {
    // ELSE
    final java.lang.String t23;
    java.lang.String t24 = (java.lang.String)(_data.get(1));
    if (false) {}
    else if (t24 == null) { t23 = null; }
    else { t23 = org.apache.calcite.runtime.SqlFunctions.concat(t24,"#"); }
    final java.lang.String t22 = (java.lang.String) t23;
    t1 = t22;
    }}
    
    return new Values(t1);
    ```
    
    @arunmahadevan Please take a look. Thanks.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/HeartSaVioR/storm STORM-2116

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/storm/pull/1709.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #1709
    
----
commit ce73a8b9fc4ee13620d07c1f621a36a7e327a872
Author: Jungtaek Lim <kabh...@gmail.com>
Date:   2016-09-13T02:40:13Z

    STORM-2089 Replace Consumer of ISqlTridentDataSource with SqlTridentConsumer
    
    * SqlTridentConsumer contains StateFactory and StateUpdater which is needed 
to store tuples to State via batch
    * Apply the change to storm-sql-kafka
    * move out JsonScheme and JsonSerializer to runtime
      * it will be used from other external sql modules
    * add javadoc to ISqlTridentDataSource

commit 3e050569e06276446e2bcec42dff80bfd659e8f4
Author: Jungtaek Lim <kabh...@gmail.com>
Date:   2016-09-22T06:38:44Z

    STORM-2111 [Storm SQL] support 'LIKE' and 'SIMILAR TO'
    
    * associate 'LIKE' and 'SIMILAR TO' to its implementation Calcite is 
providing
      * NOTE: SIMILAR TO takes SQL regex, not Java regex
    * add unit tests

commit 3e428ea4814d0a549a6e1101be26231623c8eb00
Author: Jungtaek Lim <kabh...@gmail.com>
Date:   2016-09-22T14:37:44Z

    STORM-2113 [Storm SQL] fix 'OR' and 'AND' operators handle more than 2 
operands
    
    * This fix makes 'IN' and 'NOT IN' working properly

commit 60b6b054148a76b62761c1e9fd78c78bb88d88f6
Author: Jungtaek Lim <kabh...@gmail.com>
Date:   2016-09-23T03:47:54Z

    STORM-2116 [Storm SQL] Support 'CASE' statement

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to