KazydubB commented on a change in pull request #1641: DRILL-4858:
REPEATED_COUNT on an array of maps and an array of arrays is not implemented
URL: https://github.com/apache/drill/pull/1641#discussion_r257185009
##########
File path:
exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestNewSimpleRepeatedFunctions.java
##########
@@ -17,36 +17,161 @@
*/
package org.apache.drill.exec.fn.impl;
-import org.apache.drill.test.BaseTestQuery;
import org.apache.drill.categories.SqlFunctionTest;
+import org.apache.drill.test.ClusterFixture;
+import org.apache.drill.test.ClusterTest;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+
@Category(SqlFunctionTest.class)
-public class TestNewSimpleRepeatedFunctions extends BaseTestQuery {
+public class TestNewSimpleRepeatedFunctions extends ClusterTest {
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ startCluster(ClusterFixture.builder(dirTestWatcher));
+ }
+
@Test
public void testRepeatedContainsForWildCards() throws Exception {
- testBuilder().
- sqlQuery("select repeated_contains(topping, 'Choc*') from
cp.`testRepeatedWrite.json`")
- .ordered()
- .baselineColumns("EXPR$0")
- .baselineValues(true)
- .baselineValues(true)
- .baselineValues(true)
- .baselineValues(true)
- .baselineValues(false)
- .build().run();
-
- testBuilder().
- sqlQuery("select repeated_contains(topping, 'Pow*') from
cp.`testRepeatedWrite.json`")
- .ordered()
- .baselineColumns("EXPR$0")
- .baselineValues(true)
- .baselineValues(false)
- .baselineValues(false)
- .baselineValues(true)
- .baselineValues(false)
- .build().run();
+ testBuilder()
+ .sqlQuery("select repeated_contains(topping, 'Choc*') from
cp.`testRepeatedWrite.json`")
+ .ordered()
+ .baselineColumns("EXPR$0")
+ .baselineValuesForSingleColumn(true, true, true, true, false)
+ .go();
+
+ testBuilder()
+ .sqlQuery("select repeated_contains(topping, 'Pow*') from
cp.`testRepeatedWrite.json`")
+ .ordered()
+ .baselineColumns("EXPR$0")
+ .baselineValuesForSingleColumn(true, false, false, true, false)
+ .go();
+ }
+
+ @Test
+ public void testRepeatedCountRepeatedMap() throws Exception {
+ // Contents of the generated file:
+ /*
+ {"mapArray": [{"field1": 1, "field2": "val1"}, {"field1": 2}]}
+ {"mapArray": [{"field1": 1}, {"field1": 2}]}
+ {"mapArray": [{"field2": "val2"}, {"field1": 2}, {"field1": 2}]}
+ {"mapArray": []}
+ {"mapArray": [{"field1": 1, "field2": "val3"}]}
+ {"mapArray": [{"field1": 1, "field2": "val4"}, {"field1": 2}, {"field1":
2}, {"field2": "val1"}, {"field1": 2}]}
+ {"mapArray": [{"field1": 1, "field2": "val3"}, {"field1": 2}]}
+ */
+ String fileName = "repeated_count_map.json";
+ try (BufferedWriter writer = new BufferedWriter(new FileWriter(
+ new File(dirTestWatcher.getRootDir(), fileName)))) {
+ String[] arrayElements = {
+ "{\"field1\": 1, \"field2\": \"val1\"}, {\"field1\": 2}",
+ "{\"field1\": 1}, {\"field1\": 2}",
+ "{\"field2\": \"val2\"}, {\"field1\": 2}, {\"field1\": 2}",
+ "",
+ "{\"field1\": 1, \"field2\": \"val3\"}",
+ "{\"field1\": 1, \"field2\": \"val4\"}, {\"field1\": 2},
{\"field1\": 2}, {\"field2\": \"val1\"}, {\"field1\": 2}",
+ "{\"field1\": 1, \"field2\": \"val3\"}, {\"field1\": 2}"
+ };
+ for (String value : arrayElements) {
+ String entry = String.format("{\"mapArray\": [%s]}\n", value);
+ writer.write(entry);
+ }
+ }
+
+ String selectQuery = "select repeated_count(mapArray) from dfs.`%s`";
+ testBuilder()
+ .sqlQuery(selectQuery, fileName)
+ .ordered()
+ .baselineColumns("EXPR$0")
+ .baselineValuesForSingleColumn(2, 2, 3, 0, 1, 5, 2)
+ .go();
+
+ testBuilder()
+ .sqlQuery(selectQuery + " where repeated_count(mapArray) > 2",
fileName)
+ .ordered()
+ .baselineColumns("EXPR$0")
+ .baselineValuesForSingleColumn(3, 5)
+ .go();
+
+ testBuilder()
+ .sqlQuery(selectQuery + " group by 1", fileName)
+ .unOrdered()
+ .baselineColumns("EXPR$0")
+ .baselineValuesForSingleColumn(2, 3, 0, 1, 5)
+ .go();
+
+ testBuilder()
+ .sqlQuery(selectQuery + " group by 1 having repeated_count(mapArray) <
3", fileName)
+ .unOrdered()
+ .baselineColumns("EXPR$0")
+ .baselineValuesForSingleColumn(2, 0, 1)
+ .go();
+ }
+
+ @Test
+ public void testRepeatedCountRepeatedList() throws Exception {
+ // Contents of the generated file:
+ /*
+ {"id": 1, "array": [[1, 2], [1, 3], [2, 3]]}
+ {"id": 2, "array": []}
+ {"id": 3, "array": [[2, 3], [1, 3, 4]]}
+ {"id": 4, "array": [[1], [2], [3, 4], [5], [6]]}
+ {"id": 5, "array": [[1, 2, 3], [4, 5], [6], [7], [8, 9], [2, 3], [2, 3],
[2, 3], [2]]}
+ {"id": 6, "array": [[1, 2], [3], [4], [5]]}
+ {"id": 7, "array": []}
+ {"id": 8, "array": [[1], [2], [3]]}
+ */
+ String fileName = "repeated_count_list.json";
+ try (BufferedWriter writer = new BufferedWriter(new FileWriter(
+ new File(dirTestWatcher.getRootDir(), fileName)))) {
+ String[] arrayElements = {
+ "[1, 2], [1, 3], [2, 3]",
+ "",
+ "[2, 3], [1, 3, 4]",
+ "[1], [2], [3, 4], [5], [6]",
+ "[1, 2, 3], [4, 5], [6], [7], [8, 9], [2, 3], [2, 3], [2, 3], [2]",
+ "[1, 2], [3], [4], [5]",
+ "",
+ "[1], [2], [3]"};
+ int elementId = 1;
+ for (String value : arrayElements) {
+ String entry = String.format("{\"id\": %d, \"array\": [%s]}\n",
elementId++, value);
+ writer.write(entry);
+ }
+ }
Review comment:
Added file generation because thought it will be used only for one test.
Created datasource file instead.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services