You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by ja...@apache.org on 2023/11/02 04:42:33 UTC
(pinot) branch master updated: Fix NPE for IN clause on constant STRING dictionary (#11930)
This is an automated email from the ASF dual-hosted git repository.
jackie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git
The following commit(s) were added to refs/heads/master by this push:
new fee11d6dc5 Fix NPE for IN clause on constant STRING dictionary (#11930)
fee11d6dc5 is described below
commit fee11d6dc5678600c021a5993ead4b9c5102c76c
Author: Xiaotian (Jackie) Jiang <17...@users.noreply.github.com>
AuthorDate: Wed Nov 1 21:42:27 2023 -0700
Fix NPE for IN clause on constant STRING dictionary (#11930)
---
.../tests/OfflineClusterIntegrationTest.java | 24 ++++++++++++++++++++--
.../readers/ConstantValueStringDictionary.java | 17 +++++++++++++++
2 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/OfflineClusterIntegrationTest.java b/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/OfflineClusterIntegrationTest.java
index 68c36234b2..e20ad0c9fd 100644
--- a/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/OfflineClusterIntegrationTest.java
+++ b/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/OfflineClusterIntegrationTest.java
@@ -1767,21 +1767,41 @@ public class OfflineClusterIntegrationTest extends BaseClusterIntegrationTestSet
public void testInBuiltVirtualColumns(boolean useMultiStageQueryEngine)
throws Exception {
setUseMultiStageQueryEngine(useMultiStageQueryEngine);
- String query = "SELECT $docId, $hostName, $segmentName FROM mytable";
+
+ String query = "SELECT $docId, $hostName, $segmentName FROM mytable LIMIT 10";
JsonNode response = postQuery(query);
JsonNode resultTable = response.get("resultTable");
JsonNode dataSchema = resultTable.get("dataSchema");
assertEquals(dataSchema.get("columnNames").toString(), "[\"$docId\",\"$hostName\",\"$segmentName\"]");
assertEquals(dataSchema.get("columnDataTypes").toString(), "[\"INT\",\"STRING\",\"STRING\"]");
JsonNode rows = resultTable.get("rows");
+ assertEquals(rows.size(), 10);
String expectedHostName = NetUtils.getHostnameOrAddress();
String expectedSegmentNamePrefix = "mytable_";
for (int i = 0; i < 10; i++) {
JsonNode row = rows.get(i);
assertEquals(row.get(0).asInt(), i);
assertEquals(row.get(1).asText(), expectedHostName);
- assertTrue(row.get(2).asText().startsWith(expectedSegmentNamePrefix));
+ String segmentName = row.get(2).asText();
+ assertTrue(segmentName.startsWith(expectedSegmentNamePrefix));
}
+
+ // Collect all segment names
+ query = "SELECT DISTINCT $segmentName FROM mytable LIMIT 10000";
+ response = postQuery(query);
+ rows = response.get("resultTable").get("rows");
+ int numSegments = rows.size();
+ List<String> segmentNames = new ArrayList<>(numSegments);
+ for (int i = 0; i < numSegments; i++) {
+ segmentNames.add(rows.get(i).get(0).asText());
+ }
+ // Test IN clause on $segmentName
+ Collections.shuffle(segmentNames);
+ int numSegmentsToQuery = RANDOM.nextInt(numSegments) + 1;
+ query = "SELECT COUNT(*) FROM mytable WHERE $segmentName IN ('" + String.join("','",
+ segmentNames.subList(0, numSegmentsToQuery)) + "')";
+ response = postQuery(query);
+ assertEquals(response.get("numSegmentsMatched").asInt(), numSegmentsToQuery);
}
@Test(dataProvider = "useBothQueryEngines")
diff --git a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/readers/ConstantValueStringDictionary.java b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/readers/ConstantValueStringDictionary.java
index 76cecaeecf..270a8905d2 100644
--- a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/readers/ConstantValueStringDictionary.java
+++ b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/readers/ConstantValueStringDictionary.java
@@ -18,7 +18,10 @@
*/
package org.apache.pinot.segment.local.segment.index.readers;
+import it.unimi.dsi.fastutil.ints.IntSet;
import java.math.BigDecimal;
+import java.util.Collections;
+import java.util.List;
import org.apache.pinot.spi.data.FieldSpec.DataType;
import static java.nio.charset.StandardCharsets.UTF_8;
@@ -113,4 +116,18 @@ public class ConstantValueStringDictionary extends BaseImmutableDictionary {
public byte[] getBytesValue(int dictId) {
return _bytes;
}
+
+ @Override
+ public void getDictIds(List<String> values, IntSet dictIds) {
+ if (values.contains(_value)) {
+ dictIds.add(0);
+ }
+ }
+
+ @Override
+ public void getDictIds(List<String> sortedValues, IntSet dictIds, SortedBatchLookupAlgorithm algorithm) {
+ if (Collections.binarySearch(sortedValues, _value) >= 0) {
+ dictIds.add(0);
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org