You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by su...@apache.org on 2016/11/18 02:33:32 UTC

kylin git commit: update count distinct blog, and add window function blog

Repository: kylin
Updated Branches:
  refs/heads/document d53612282 -> 1a3a45586


update count distinct blog, and add window function blog


Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/1a3a4558
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/1a3a4558
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/1a3a4558

Branch: refs/heads/document
Commit: 1a3a455860ae60ff2ea62690805a64e66db5e452
Parents: d536122
Author: sunyerui <su...@gmail.com>
Authored: Fri Nov 18 10:32:50 2016 +0800
Committer: sunyerui <su...@gmail.com>
Committed: Fri Nov 18 10:32:50 2016 +0800

----------------------------------------------------------------------
 .../blog/2016-08-01-count-distinct-in-kylin.md  | 20 ++++---
 .../_posts/blog/2016-11-16-window-function.md   | 62 ++++++++++++++++++++
 2 files changed, 74 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kylin/blob/1a3a4558/website/_posts/blog/2016-08-01-count-distinct-in-kylin.md
----------------------------------------------------------------------
diff --git a/website/_posts/blog/2016-08-01-count-distinct-in-kylin.md b/website/_posts/blog/2016-08-01-count-distinct-in-kylin.md
index 105cd2e..e95695f 100644
--- a/website/_posts/blog/2016-08-01-count-distinct-in-kylin.md
+++ b/website/_posts/blog/2016-08-01-count-distinct-in-kylin.md
@@ -40,18 +40,22 @@ Current version (v1.5.3) has no GUI for defining global dictionary yet, you need
 
 The `column` means the column which to be encoded, the `builder` specifies the dictionary builder, only `org.apache.kylin.dict.GlobalDictionaryBuilder` is available for now.
 The 'reuse` is used to optimize the dict of more than one columns based on one dataset, please refer the next section 'Example' for more details.
+
+Higher version (v1.5.4 or above) provided GUI for global dictionary definetion, the 'Advanced Dictionaries' part in step 'Advanced Setting' of cube designer.
+
 The global dictionay cannot be used for dimension encoding for now, that means if one column is used for both dimension and count distinct measure in one cube, its dimension encoding should be others instead of dict.
 
 ## Example
 Here's some example data:
-| DT           | USER\_ID | FLAG1 | FLAG2 | USER\_ID\_FLAG1 | USER\_ID\_FLAG2 |
-| :----------: | :------: | :---: | :---: | :-------------: | :-------------: |
-| 2016-06-08   | AAA      | 1     | 1     | AAA             | AAA             |
-| 2016-06-08   | BBB      | 1     | 1     | BBB             | BBB             |
-| 2016-06-08   | CCC      | 0     | 1     | NULL            | CCC             |
-| 2016-06-09   | AAA      | 0     | 1     | NULL            | AAA             |
-| 2016-06-09   | CCC      | 1     | 0     | CCC             | NULL            |
-| 2016-06-10   | BBB      | 0     | 1     | NULL            | BBB             |
+
+| DT          | USER\_ID | FLAG1 | FLAG2 | USER\_ID\_FLAG1 | USER\_ID\_FLAG2 |
+| :---------- | :------: | :---: | :---: | :-------------: | :-------------: |
+| 2016-06-08  | AAA      | 1     | 1     | AAA             | AAA             |
+| 2016-06-08  | BBB      | 1     | 1     | BBB             | BBB             |
+| 2016-06-08  | CCC      | 0     | 1     | NULL            | CCC             |
+| 2016-06-09  | AAA      | 0     | 1     | NULL            | AAA             |
+| 2016-06-09  | CCC      | 1     | 0     | CCC             | NULL            |
+| 2016-06-10  | BBB      | 0     | 1     | NULL            | BBB             |
 
 There's basic columns `DT`, `USER_ID`, `FLAG1`, `FLAG2`, and condition columns `USER_ID_FLAG1=if(FLAG1=1,USER_ID,null)`, `USER_ID_FLAG2=if(FLAG2=1,USER_ID,null)`. Supposed the cube is builded by day, has 3 segments.
 

http://git-wip-us.apache.org/repos/asf/kylin/blob/1a3a4558/website/_posts/blog/2016-11-16-window-function.md
----------------------------------------------------------------------
diff --git a/website/_posts/blog/2016-11-16-window-function.md b/website/_posts/blog/2016-11-16-window-function.md
new file mode 100644
index 0000000..82286ca
--- /dev/null
+++ b/website/_posts/blog/2016-11-16-window-function.md
@@ -0,0 +1,62 @@
+---
+layout: post-blog
+title:  Use Window Function and Grouping Sets in Apache Kylin
+date:   2016-11-16 23:30:00
+author: Yerui Sun 
+categories: blog
+---
+
+Since v.1.5.4
+
+## Background
+We've provided window function and grouping sets in Apache Kylin, to support more complicate query, keeping SQL statements simple and clearly. Here's the article about HOW TO use them.
+
+## Window Function
+Window function give us the ability to partition, order and aggregate on the query result sets. We can use window function to meet complicated query requirements with much more simple SQL statements. 
+The window function syntax of Apache Kylin can be found in [calcite reference](http://calcite.apache.org/docs/reference.html#window-functions), and is similar with [Hive window function](https://cwiki.apache.org/confluence/display/Hive/LanguageManual+WindowingAndAnalytics).
+Here's some examples:
+
+```
+sum(col) over()
+count(col) over(partition by col2)
+row_number() over(partition by col order by col2)
+first_value(col) over(partition by col2 order by col3 rows 2 preceding)
+lag(col, 5, 0) over(partition by col2, order by col3 range 3 preceding 6 following)
+```
+
+## Grouping Sets
+Sometimes we want aggregate data by different keys in one SQL statements. This is possible with the grouping sets feature.
+Here's example, suppose we execute one query and get result as below:
+
+```
+select dim1, dim2, sum(col) as metric1 from table group by dim1, dim2
+```
+
+| dim1 | dim2 | metric1 |
+| :--- | :--: | :-----: |
+| A    | AA   | 10      |
+| A    | BB   | 20      |
+| B    | AA   | 15      |
+| B    | BB   | 30      |
+
+If we also want to see the result with dim2 rolled up, we can rewrite the sql and get result as below:
+
+```
+select dim1,
+case grouping(dim2) when 1 then 'ALL' else dim2 end,
+sum(col) as metric1
+from table
+group by grouping sets((dim1, dim2), (dim1))
+```
+
+| dim1 | dim2 | metric1 |
+| :--- | :--: | :-----: |
+| A    | ALL  | 30      |
+| A    | AA   | 10      |
+| A    | BB   | 20      |
+| B    | ALL  | 45      |
+| B    | AA   | 15      |
+| B    | BB   | 30      |
+
+Apache Kylin support cube/rollup/grouping sets, and grouping functions can be found [here](http://calcite.apache.org/docs/reference.html#grouping-functions). It's also similar with [Hive grouping sets](https://cwiki.apache.org/confluence/display/Hive/Enhanced+Aggregation%2C+Cube%2C+Grouping+and+Rollup).
+