sjwiesman commented on pull request #13:
URL: https://github.com/apache/flink-playgrounds/pull/13#issuecomment-642819898


   For reference, the user will go through three iterations implementing the 
report:
   
   A first naive version:
   
   ```java
   public static Table report(Table rows) {
       return rows.select(
               $("account_id"),
               $("transaction_time").floor(TimeIntervalUnit.HOUR).as("log_ts"),
               $("amount"))
           .groupBy($("account_id"), $("log_ts"))
           .select(
               $("account_id"),
               $("log_ts"),
               $("amount").sum().as("amount"));
   }
   ```
   
   Then with a UDF
   
   ```java
   
   public class MyFloor extends ScalarFunction {
   
       public @DataTypeHint("TIMESTAMP(3)") LocalDateTime eval(
           @DataTypeHint("TIMESTAMP(3)") LocalDateTime timestamp) {
   
           return timestamp.truncatedTo(ChronoUnit.HOURS);
       }
   }
   
   public static Table report(Table rows) {
       return rows.select(
               $("account_id"),
               call(MyFloor.class, $("transaction_time")).as("log_ts"),
               $("amount"))
           .groupBy($("account_id"), $("log_ts"))
           .select(
               $("account_id"),
               $("log_ts"),
               $("amount").sum().as("amount"));
   }
   ```
   
   And finally with proper windows
   
   ```java
   public static Table report(Table rows) {
       return 
rows.window(Tumble.over(lit(1).hour()).on($("transaction_time")).as("log_ts"))
           .groupBy($("account_id"), $("log_ts"))
           .select(
               $("account_id"),
               $("log_ts").start().as("log_ts"),
               $("amount").sum().as("amount"));
   }
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to