Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace explode with explode_outer #404

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private Dataset<Row> updateBloomFilter(Dataset<Row> dataset) {

private Dataset<Row> estimateSize(Dataset<Row> dataset) {
return dataset
.select(functions.col("partition"), functions.explode(functions.col(inputCol)).as("token"))
.select(functions.col("partition"), functions.explode_outer(functions.col(inputCol)).as("token"))
.groupBy("partition")
.agg(functions.approxCountDistinct("token").as(outputCol));
}
Expand Down
28 changes: 28 additions & 0 deletions src/test/java/com/teragrep/pth10/BloomFilterOperationsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,34 @@ public void estimateTest() {
);
}

@Test
@DisabledIfSystemProperty(
named = "skipSparkTest",
matches = "true"
)
public void testEstimateOnEmptyArray() {
streamingTestUtil
.performDPLTest(
// index_Empty _raw = "" so tokenizer step will produce an empty array
"index=index_Empty earliest=2020-01-01T00:00:00z latest=2023-01-01T00:00:00z | teragrep exec tokenizer | teragrep exec bloom estimate",
testFile, ds -> {
Assertions
.assertEquals("[partition, estimate(tokens)]", Arrays.toString(ds.columns()), "Batch handler dataset contained an unexpected column arrangement !");
List<Integer> results = ds
.select("estimate(tokens)")
.collectAsList()
.stream()
.map(r -> Integer.parseInt(r.get(0).toString()))
.collect(Collectors.toList());

// assert that a row is produced and not an empty dataframe
Assertions.assertEquals(1, results.size());
// assert that estimate is 0 and not empty or null
Assertions.assertEquals(0, results.get(0));
}
);
}

@Test
@DisabledIfSystemProperty(
named = "skipSparkTest",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
{"_time": "2022-09-06 09:00:00.000", "id": 1, "_raw": "one", "index": "index_A", "sourcetype": "stream1", "host": "host", "source": "127.0.0.0", "partition": "1", "offset": 1}
{"_time": "2022-09-06 09:00:00.000", "id": 2, "_raw": "one.two", "index": "index_A", "sourcetype": "stream1", "host": "host", "source": "127.0.0.0", "partition": "2", "offset": 1}
{"_time": "2022-09-06 09:00:00.000", "id": 2, "_raw": "one.two", "index": "index_A", "sourcetype": "stream1", "host": "host", "source": "127.0.0.0", "partition": "2", "offset": 1}
{"_time": "2022-09-06 09:00:00.000", "id": 3, "_raw": "", "index": "index_Empty", "sourcetype": "stream1", "host": "host", "source": "127.0.0.0", "partition": "3", "offset": 1}