This is an automated email from the ASF dual-hosted git repository.

nehapawar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git


The following commit(s) were added to refs/heads/master by this push:
     new 41f7ef5  Include trailing empty string in group key split (#5449)
41f7ef5 is described below

commit 41f7ef575109ab940bd26dc3e8077a12c4373a8b
Author: Neha Pawar <[email protected]>
AuthorDate: Tue May 26 15:50:39 2020 -0700

    Include trailing empty string in group key split (#5449)
---
 .../operator/CombineGroupByOrderByOperator.java    |  2 +-
 .../aggregation/groupby/GroupKeyGenerator.java     |  8 +++
 .../query/aggregation/groupby/GroupKeyTest.java    | 66 ++++++++++++++++++++++
 3 files changed, 75 insertions(+), 1 deletion(-)

diff --git 
a/pinot-core/src/main/java/org/apache/pinot/core/operator/CombineGroupByOrderByOperator.java
 
b/pinot-core/src/main/java/org/apache/pinot/core/operator/CombineGroupByOrderByOperator.java
index 610218a..8ec1841 100644
--- 
a/pinot-core/src/main/java/org/apache/pinot/core/operator/CombineGroupByOrderByOperator.java
+++ 
b/pinot-core/src/main/java/org/apache/pinot/core/operator/CombineGroupByOrderByOperator.java
@@ -169,7 +169,7 @@ public class CombineGroupByOrderByOperator extends 
BaseOperator<IntermediateResu
                 Object[] columns = new Object[numColumns];
                 int columnIndex = 0;
                 GroupKeyGenerator.GroupKey groupKey = groupKeyIterator.next();
-                String[] stringKey = 
groupKey._stringKey.split(GroupKeyGenerator.DELIMITER);
+                String[] stringKey = groupKey.getKeys();
                 Object[] objectKey = new Object[numGroupBy];
                 for (int i = 0; i < stringKey.length; i++) {
                   Object convertedKey = 
converterFunctions[i].apply(stringKey[i]);
diff --git 
a/pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/groupby/GroupKeyGenerator.java
 
b/pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/groupby/GroupKeyGenerator.java
index a2a1524..3f1afbe 100644
--- 
a/pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/groupby/GroupKeyGenerator.java
+++ 
b/pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/groupby/GroupKeyGenerator.java
@@ -79,5 +79,13 @@ public interface GroupKeyGenerator {
   class GroupKey {
     public int _groupId;
     public String _stringKey;
+
+    /**
+     * Returns the group key as an array
+     */
+    public String[] getKeys() {
+      // Set limit to -1 to prevent removing trailing empty strings
+      return _stringKey.split(GroupKeyGenerator.DELIMITER, -1);
+    }
   }
 }
diff --git 
a/pinot-core/src/test/java/org/apache/pinot/query/aggregation/groupby/GroupKeyTest.java
 
b/pinot-core/src/test/java/org/apache/pinot/query/aggregation/groupby/GroupKeyTest.java
new file mode 100644
index 0000000..207729d
--- /dev/null
+++ 
b/pinot-core/src/test/java/org/apache/pinot/query/aggregation/groupby/GroupKeyTest.java
@@ -0,0 +1,66 @@
+/**
+ * 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.pinot.query.aggregation.groupby;
+
+import org.apache.pinot.core.query.aggregation.groupby.GroupKeyGenerator;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+public class GroupKeyTest {
+
+  @Test
+  public void testGetKeys() {
+    GroupKeyGenerator.GroupKey groupKey = new GroupKeyGenerator.GroupKey();
+    groupKey._stringKey = "foo\tbar\t";
+    String[] keys = groupKey.getKeys();
+    Assert.assertEquals(keys.length, 3);
+    Assert.assertEquals(keys, new String[]{"foo", "bar", ""});
+
+    groupKey._stringKey = "foo\t\tbar";
+    keys = groupKey.getKeys();
+    Assert.assertEquals(keys.length, 3);
+    Assert.assertEquals(keys, new String[]{"foo", "", "bar"});
+
+    groupKey._stringKey = "\tfoo\tbar";
+    keys = groupKey.getKeys();
+    Assert.assertEquals(keys.length, 3);
+    Assert.assertEquals(keys, new String[]{"", "foo", "bar"});
+
+    groupKey._stringKey = "foo\t\t";
+    keys = groupKey.getKeys();
+    Assert.assertEquals(keys.length, 3);
+    Assert.assertEquals(keys, new String[]{"foo", "", ""});
+
+    groupKey._stringKey = "\t\t";
+    keys = groupKey.getKeys();
+    Assert.assertEquals(keys.length, 3);
+    Assert.assertEquals(keys, new String[]{"", "", ""});
+
+    groupKey._stringKey = "";
+    keys = groupKey.getKeys();
+    Assert.assertEquals(keys.length, 1);
+    Assert.assertEquals(keys, new String[]{""});
+
+    groupKey._stringKey = "\t";
+    keys = groupKey.getKeys();
+    Assert.assertEquals(keys.length, 2);
+    Assert.assertEquals(keys, new String[]{"", ""});
+  }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to