65a9ac2ff4
### What changes were proposed in this pull request? This pr intends to support code generation for `HashAggregateExec` with filters. Quick benchmark results: ``` $ ./bin/spark-shell --master=local[1] --conf spark.driver.memory=8g --conf spark.sql.shuffle.partitions=1 -v scala> spark.range(100000000).selectExpr("id % 3 as k1", "id % 5 as k2", "rand() as v1", "rand() as v2").write.saveAsTable("t") scala> sql("SELECT k1, k2, AVG(v1) FILTER (WHERE v2 > 0.5) FROM t GROUP BY k1, k2").write.format("noop").mode("overwrite").save() >> Before this PR Elapsed time: 16.170697619s >> After this PR Elapsed time: 6.7825313s ``` The query above is compiled into code below; ``` ... /* 285 */ private void agg_doAggregate_avg_0(boolean agg_exprIsNull_2_0, org.apache.spark.sql.catalyst.InternalRow agg_unsafeRowAggBuffer_0, double agg_expr_2_0) throws java.io.IOException { /* 286 */ // evaluate aggregate function for avg /* 287 */ boolean agg_isNull_10 = true; /* 288 */ double agg_value_12 = -1.0; /* 289 */ boolean agg_isNull_11 = agg_unsafeRowAggBuffer_0.isNullAt(0); /* 290 */ double agg_value_13 = agg_isNull_11 ? /* 291 */ -1.0 : (agg_unsafeRowAggBuffer_0.getDouble(0)); /* 292 */ if (!agg_isNull_11) { /* 293 */ agg_agg_isNull_12_0 = true; /* 294 */ double agg_value_14 = -1.0; /* 295 */ do { /* 296 */ if (!agg_exprIsNull_2_0) { /* 297 */ agg_agg_isNull_12_0 = false; /* 298 */ agg_value_14 = agg_expr_2_0; /* 299 */ continue; /* 300 */ } /* 301 */ /* 302 */ if (!false) { /* 303 */ agg_agg_isNull_12_0 = false; /* 304 */ agg_value_14 = 0.0D; /* 305 */ continue; /* 306 */ } /* 307 */ /* 308 */ } while (false); /* 309 */ /* 310 */ agg_isNull_10 = false; // resultCode could change nullability. /* 311 */ /* 312 */ agg_value_12 = agg_value_13 + agg_value_14; /* 313 */ /* 314 */ } /* 315 */ boolean agg_isNull_15 = false; /* 316 */ long agg_value_17 = -1L; /* 317 */ if (!false && agg_exprIsNull_2_0) { /* 318 */ boolean agg_isNull_18 = agg_unsafeRowAggBuffer_0.isNullAt(1); /* 319 */ long agg_value_20 = agg_isNull_18 ? /* 320 */ -1L : (agg_unsafeRowAggBuffer_0.getLong(1)); /* 321 */ agg_isNull_15 = agg_isNull_18; /* 322 */ agg_value_17 = agg_value_20; /* 323 */ } else { /* 324 */ boolean agg_isNull_19 = true; /* 325 */ long agg_value_21 = -1L; /* 326 */ boolean agg_isNull_20 = agg_unsafeRowAggBuffer_0.isNullAt(1); /* 327 */ long agg_value_22 = agg_isNull_20 ? /* 328 */ -1L : (agg_unsafeRowAggBuffer_0.getLong(1)); /* 329 */ if (!agg_isNull_20) { /* 330 */ agg_isNull_19 = false; // resultCode could change nullability. /* 331 */ /* 332 */ agg_value_21 = agg_value_22 + 1L; /* 333 */ /* 334 */ } /* 335 */ agg_isNull_15 = agg_isNull_19; /* 336 */ agg_value_17 = agg_value_21; /* 337 */ } /* 338 */ // update unsafe row buffer /* 339 */ if (!agg_isNull_10) { /* 340 */ agg_unsafeRowAggBuffer_0.setDouble(0, agg_value_12); /* 341 */ } else { /* 342 */ agg_unsafeRowAggBuffer_0.setNullAt(0); /* 343 */ } /* 344 */ /* 345 */ if (!agg_isNull_15) { /* 346 */ agg_unsafeRowAggBuffer_0.setLong(1, agg_value_17); /* 347 */ } else { /* 348 */ agg_unsafeRowAggBuffer_0.setNullAt(1); /* 349 */ } /* 350 */ } ... ``` ### Why are the changes needed? For high performance. ### Does this PR introduce any user-facing change? No. ### How was this patch tested? Existing tests. Closes #27019 from maropu/AggregateFilterCodegen. Authored-by: Takeshi Yamamuro <yamamuro@apache.org> Signed-off-by: Dongjoon Hyun <dhyun@apple.com> |
||
---|---|---|
.github | ||
assembly | ||
bin | ||
binder | ||
build | ||
common | ||
conf | ||
core | ||
data | ||
dev | ||
docs | ||
examples | ||
external | ||
graphx | ||
hadoop-cloud | ||
launcher | ||
licenses | ||
licenses-binary | ||
mllib | ||
mllib-local | ||
project | ||
python | ||
R | ||
repl | ||
resource-managers | ||
sbin | ||
sql | ||
streaming | ||
tools | ||
.asf.yaml | ||
.gitattributes | ||
.gitignore | ||
.sbtopts | ||
appveyor.yml | ||
CONTRIBUTING.md | ||
LICENSE | ||
LICENSE-binary | ||
NOTICE | ||
NOTICE-binary | ||
pom.xml | ||
README.md | ||
scalastyle-config.xml |
Apache Spark
Spark is a unified analytics engine for large-scale data processing. It provides high-level APIs in Scala, Java, Python, and R, and an optimized engine that supports general computation graphs for data analysis. It also supports a rich set of higher-level tools including Spark SQL for SQL and DataFrames, MLlib for machine learning, GraphX for graph processing, and Structured Streaming for stream processing.
Online Documentation
You can find the latest Spark documentation, including a programming guide, on the project web page. This README file only contains basic setup instructions.
Building Spark
Spark is built using Apache Maven. To build Spark and its example programs, run:
./build/mvn -DskipTests clean package
(You do not need to do this if you downloaded a pre-built package.)
More detailed documentation is available from the project site, at "Building Spark".
For general development tips, including info on developing Spark using an IDE, see "Useful Developer Tools".
Interactive Scala Shell
The easiest way to start using Spark is through the Scala shell:
./bin/spark-shell
Try the following command, which should return 1,000,000,000:
scala> spark.range(1000 * 1000 * 1000).count()
Interactive Python Shell
Alternatively, if you prefer Python, you can use the Python shell:
./bin/pyspark
And run the following command, which should also return 1,000,000,000:
>>> spark.range(1000 * 1000 * 1000).count()
Example Programs
Spark also comes with several sample programs in the examples
directory.
To run one of them, use ./bin/run-example <class> [params]
. For example:
./bin/run-example SparkPi
will run the Pi example locally.
You can set the MASTER environment variable when running examples to submit
examples to a cluster. This can be a mesos:// or spark:// URL,
"yarn" to run on YARN, and "local" to run
locally with one thread, or "local[N]" to run locally with N threads. You
can also use an abbreviated class name if the class is in the examples
package. For instance:
MASTER=spark://host:7077 ./bin/run-example SparkPi
Many of the example programs print usage help if no params are given.
Running Tests
Testing first requires building Spark. Once Spark is built, tests can be run using:
./dev/run-tests
Please see the guidance on how to run tests for a module, or individual tests.
There is also a Kubernetes integration test, see resource-managers/kubernetes/integration-tests/README.md
A Note About Hadoop Versions
Spark uses the Hadoop core library to talk to HDFS and other Hadoop-supported storage systems. Because the protocols have changed in different versions of Hadoop, you must build Spark against the same version that your cluster runs.
Please refer to the build documentation at "Specifying the Hadoop Version and Enabling YARN" for detailed guidance on building for a particular distribution of Hadoop, including building for particular Hive and Hive Thriftserver distributions.
Configuration
Please refer to the Configuration Guide in the online documentation for an overview on how to configure Spark.
Contributing
Please review the Contribution to Spark guide for information on how to get started contributing to the project.