beam-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Anton Kedin (JIRA)" <j...@apache.org>
Subject [jira] [Created] (BEAM-3548) [SQL][Java] Fluid query builder
Date Fri, 26 Jan 2018 23:58:00 GMT
Anton Kedin created BEAM-3548:
---------------------------------

             Summary: [SQL][Java] Fluid query builder
                 Key: BEAM-3548
                 URL: https://issues.apache.org/jira/browse/BEAM-3548
             Project: Beam
          Issue Type: New Feature
          Components: dsl-sql
            Reporter: Anton Kedin


Create a fluid query builder.

 

*Problem*:

SQL queries as java strings are very hard to read and debug. See examples below.

 

*Solution*:

Fluid query builder, along the lines of:
{code:java}
QueryTransform query = 
  QueryBuilder
    .from(pcollection)
    .where(e -> e.id == 3)
    .groupBy(e -> e.name)
    .select();{code}
 

*Examples:*
{code:java|title=BeamSqlAggregationTest.java}
    String sql = "select f_int2, count(*) as getFieldCount, "
        + "sum(f_long) as sum1, avg(f_long) as avg1, max(f_long) as max1, min(f_long) as min1,
"
        + "sum(f_short) as sum2, avg(f_short) as avg2, max(f_short) as max2, min(f_short)
as min2, "
        + "sum(f_byte) as sum3, avg(f_byte) as avg3, max(f_byte) as max3, min(f_byte) as min3,
"
        + "sum(f_float) as sum4, avg(f_float) as avg4, max(f_float) as max4, min(f_float)
as min4, "
        + "sum(f_double) as sum5, avg(f_double) as avg5, "
        + "max(f_double) as max5, min(f_double) as min5, "
        + "max(f_timestamp) as max6, min(f_timestamp) as min6, "
        + "var_pop(f_double) as varpop1, var_samp(f_double) as varsamp1, "
        + "var_pop(f_int) as varpop2, var_samp(f_int) as varsamp2 "
        + "FROM TABLE_A group by f_int2";
{code}
or
{code:java|title=BeamSetOperatorRelBaseTest.java}
    String sql = "SELECT "
        + " order_id, site_id, count(*) as cnt "
        + "FROM ORDER_DETAILS GROUP BY order_id, site_id"
        + ", TUMBLE(order_time, INTERVAL '1' HOUR) "
        + " UNION SELECT "
        + " order_id, site_id, count(*) as cnt "
        + "FROM ORDER_DETAILS GROUP BY order_id, site_id"
        + ", TUMBLE(order_time, INTERVAL '2' HOUR) ";
{code}
or
{code:java|title=BeamSqlCliTest.java}
    cli.execute(
        "create table person (\n"
        + "id int COMMENT 'id', \n"
        + "name varchar(31) COMMENT 'name', \n"
        + "age int COMMENT 'age') \n"
        + "TYPE 'text' \n"
        + "COMMENT '' LOCATION 'text://home/admin/orders'"
    );
{code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message