[ https://issues.apache.org/jira/browse/FLINK-5303?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15804949#comment-15804949 ]
ASF GitHub Bot commented on FLINK-5303: --------------------------------------- Github user twalthr commented on a diff in the pull request: https://github.com/apache/flink/pull/2976#discussion_r94969330 --- Diff: flink-libraries/flink-table/src/test/java/org/apache/flink/table/api/java/batch/sql/GroupingSetsTest.java --- @@ -0,0 +1,188 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.table.api.java.batch.sql; + +import org.apache.flink.api.common.functions.MapFunction; +import org.apache.flink.api.java.DataSet; +import org.apache.flink.api.java.ExecutionEnvironment; +import org.apache.flink.api.java.operators.MapOperator; +import org.apache.flink.api.java.tuple.Tuple3; +import org.apache.flink.table.api.Table; +import org.apache.flink.table.api.TableConfig; +import org.apache.flink.table.api.TableEnvironment; +import org.apache.flink.table.api.java.BatchTableEnvironment; +import org.apache.flink.test.javaApiOperators.util.CollectionDataSets; +import org.apache.flink.test.util.TestBaseUtils; +import org.apache.flink.types.Row; +import org.junit.Before; +import org.junit.Test; + +import java.util.Comparator; +import java.util.List; + +public class GroupingSetsTest { + + private final static String TABLE_NAME = "MyTable"; + private final static String TABLE_WITH_NULLS_NAME = "MyTableWithNulls"; + private BatchTableEnvironment tableEnv; + + @Before + public void setup() { + ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); + tableEnv = TableEnvironment.getTableEnvironment(env, new TableConfig()); + + DataSet<Tuple3<Integer, Long, String>> dataSet = CollectionDataSets.get3TupleDataSet(env); + tableEnv.registerDataSet(TABLE_NAME, dataSet); + + MapOperator<Tuple3<Integer, Long, String>, Tuple3<Integer, Long, String>> dataSetWithNulls = + dataSet.map(new MapFunction<Tuple3<Integer, Long, String>, Tuple3<Integer, Long, String>>() { + + @Override + public Tuple3<Integer, Long, String> map(Tuple3<Integer, Long, String> value) throws Exception { + if (value.f2.toLowerCase().contains("world")) { + value.f2 = null; + } + return value; + } + }); + tableEnv.registerDataSet(TABLE_WITH_NULLS_NAME, dataSetWithNulls); + } + + @Test + public void testGroupingSets() throws Exception { + String query = + "SELECT f1, f2, avg(f0) as a, GROUP_ID() as g FROM " + TABLE_NAME + + " GROUP BY GROUPING SETS (f1, f2)"; + + String expected = + "6,null,18,1\n5,null,13,1\n4,null,8,1\n3,null,5,1\n2,null,2,1\n1,null,1,1\n" + + "null,Luke Skywalker,6,2\nnull,I am fine.,5,2\nnull,Hi,1,2\n" + + "null,Hello world, how are you?,4,2\nnull,Hello world,3,2\nnull,Hello,2,2\n" + + "null,Comment#9,15,2\nnull,Comment#8,14,2\nnull,Comment#7,13,2\n" + + "null,Comment#6,12,2\nnull,Comment#5,11,2\nnull,Comment#4,10,2\n" + + "null,Comment#3,9,2\nnull,Comment#2,8,2\nnull,Comment#15,21,2\n" + + "null,Comment#14,20,2\nnull,Comment#13,19,2\nnull,Comment#12,18,2\n" + + "null,Comment#11,17,2\nnull,Comment#10,16,2\nnull,Comment#1,7,2"; + + checkSql(query, expected); + } + + @Test + public void testGroupingSetsWithNulls() throws Exception { --- End diff -- Can you add `GROUPING()` and `GROUPING_ID()` here too. Just to make sure that we don't compare two wrong results in the tests below. > Add CUBE/ROLLUP/GROUPING SETS operator in SQL > --------------------------------------------- > > Key: FLINK-5303 > URL: https://issues.apache.org/jira/browse/FLINK-5303 > Project: Flink > Issue Type: New Feature > Components: Documentation, Table API & SQL > Reporter: Alexander Chermenin > Assignee: Alexander Chermenin > > Add support for such operators as CUBE, ROLLUP and GROUPING SETS in SQL. -- This message was sent by Atlassian JIRA (v6.3.4#6332)