@@ -118,7 +118,7 @@ down the following operations to MarkLogic:
118
118
- ` filter ` and ` where `
119
119
- ` groupBy ` when followed by ` count `
120
120
- ` limit `
121
- - ` orderBy `
121
+ - ` orderBy ` and ` sort `
122
122
123
123
For each of the above operations, the user's Optic query is enhanced to include the associated Optic function.
124
124
Note that if multiple partitions are used to perform the ` read ` operation, each
@@ -127,7 +127,42 @@ from each partition and re-apply the function calls as necessary to ensure that
127
127
128
128
If either ` count ` or ` groupBy ` and ` count ` are pushed down, the connector will make a single request to MarkLogic to
129
129
resolve the query (thus ignoring the number of partitions and batch size that may have been configured; see below
130
- for more information on these options), ensuring that a single count or set of counts is returned to Spark.
130
+ for more information on these options), ensuring that a single count or set of counts is returned to Spark.
131
+
132
+ In the following example, every operation after ` load() ` is pushed down to MarkLogic, thereby resulting in far fewer
133
+ rows being returned to Spark and far less work having to be done by Spark:
134
+
135
+ ```
136
+ spark.read.format("com.marklogic.spark") \
137
+ .option("spark.marklogic.client.uri", "spark-example-user:password@localhost:8020") \
138
+ .option("spark.marklogic.read.opticQuery", "op.fromView('example', 'employee', '')") \
139
+ .load() \
140
+ .filter("HiredDate < '2020-01-01'") \
141
+ .groupBy("State", "Department") \
142
+ .count() \
143
+ .orderBy("State", "count") \
144
+ .limit(10) \
145
+ .show()
146
+ ```
147
+
148
+ The following results are returned:
149
+
150
+ ```
151
+ +-----+-----------+-----+
152
+ |State| Department|count|
153
+ +-----+-----------+-----+
154
+ | AL| Marketing| 1|
155
+ | AL| Training| 1|
156
+ | AL| R&D| 4|
157
+ | AL| Sales| 4|
158
+ | AR| Sales| 1|
159
+ | AR| Marketing| 3|
160
+ | AR| R&D| 9|
161
+ | AZ| Training| 1|
162
+ | AZ|Engineering| 2|
163
+ | AZ| R&D| 2|
164
+ +-----+-----------+-----+
165
+ ```
131
166
132
167
## Tuning performance
133
168
0 commit comments