Skip to content

Commit 9981bc2

Browse files
authored
Merge pull request #55 from marklogic/feature/count-comment
Added comment to clarify the "count" label
2 parents fb4deb9 + 7eeccaf commit 9981bc2

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/main/java/com/marklogic/spark/reader/PlanUtil.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,27 @@ public abstract class PlanUtil {
4242
private final static ObjectMapper objectMapper = new ObjectMapper();
4343

4444
static ObjectNode buildGroupByCount() {
45-
return newOperation("group-by", args -> args
46-
.add(objectMapper.nullNode())
47-
.addObject().put("ns", "op").put("fn", "count").putArray("args").add("count").add(objectMapper.nullNode()));
45+
return newOperation("group-by", args -> {
46+
args.add(objectMapper.nullNode());
47+
addCountArg(args);
48+
});
4849
}
4950

5051
static ObjectNode buildGroupByCount(String columnName) {
5152
return newOperation("group-by", args -> {
5253
populateSchemaCol(args.addObject(), columnName);
53-
// Using "null" is the equivalent of "count(*)" - it counts rows, not values.
54-
args.addObject().put("ns", "op").put("fn", "count").putArray("args").add("count").add(objectMapper.nullNode());
54+
addCountArg(args);
5555
});
5656
}
5757

58+
private static void addCountArg(ArrayNode args) {
59+
args.addObject().put("ns", "op").put("fn", "count").putArray("args")
60+
// "count" is used as the column name as that's what Spark uses when the operation is not pushed down.
61+
.add("count")
62+
// Using "null" is the equivalent of "count(*)" - it counts rows, not values.
63+
.add(objectMapper.nullNode());
64+
}
65+
5866
static ObjectNode buildLimit(int limit) {
5967
return newOperation("limit", args -> args.add(limit));
6068
}

0 commit comments

Comments
 (0)