Apache Spark - A unified analytics engine for large-scale data processing
 
 
 
 
 
 
Go to file
Bruce Robbins 497d17f38a [SPARK-39496][SQL] Handle null struct in `Inline.eval`
Change `Inline.eval` to return a row of null values rather than a null row in the case of a null input struct.

Consider the following query:
```
set spark.sql.codegen.wholeStage=false;
select inline(array(named_struct('a', 1, 'b', 2), null));
```
This query fails with a `NullPointerException`:
```
22/06/16 15:10:06 ERROR Executor: Exception in task 0.0 in stage 0.0 (TID 0)
java.lang.NullPointerException
	at org.apache.spark.sql.catalyst.expressions.GeneratedClass$SpecificUnsafeProjection.apply(Unknown Source)
	at org.apache.spark.sql.execution.GenerateExec.$anonfun$doExecute$11(GenerateExec.scala:122)
```
(In Spark 3.1.3, you don't need to set `spark.sql.codegen.wholeStage` to false to reproduce the error, since Spark 3.1.3 has no codegen path for `Inline`).

This query fails regardless of the setting of `spark.sql.codegen.wholeStage`:
```
val dfWide = (Seq((1))
  .toDF("col0")
  .selectExpr(Seq.tabulate(99)(x => s"$x as col${x + 1}"): _*))

val df = (dfWide
  .selectExpr("*", "array(named_struct('a', 1, 'b', 2), null) as struct_array"))

df.selectExpr("*", "inline(struct_array)").collect
```
It fails with
```
22/06/16 15:18:55 ERROR Executor: Exception in task 0.0 in stage 0.0 (TID 0)/ 1]
java.lang.NullPointerException
	at org.apache.spark.sql.catalyst.expressions.JoinedRow.isNullAt(JoinedRow.scala:80)
	at org.apache.spark.sql.catalyst.expressions.GeneratedClass$SpecificUnsafeProjection.writeFields_0_8$(Unknown Source)
```
When `Inline.eval` returns a null row in the collection, GenerateExec gets a NullPointerException either when joining the null row with required child output, or projecting the null row.

This PR avoids producing the null row and produces a row of null values instead:
```
spark-sql> set spark.sql.codegen.wholeStage=false;
spark.sql.codegen.wholeStage	false
Time taken: 3.095 seconds, Fetched 1 row(s)
spark-sql> select inline(array(named_struct('a', 1, 'b', 2), null));
1	2
NULL	NULL
Time taken: 1.214 seconds, Fetched 2 row(s)
spark-sql>
```

No.

New unit test.

Closes #36903 from bersprockets/inline_eval_null_struct_issue.

Authored-by: Bruce Robbins <bersprockets@gmail.com>
Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
(cherry picked from commit c4d5390dd0)
Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
2022-06-18 09:27:07 +09:00
.github [SPARK-39421][PYTHON][DOCS] Pin the docutils version <0.18 in documentation build 2022-06-09 14:27:39 +09:00
.idea [SPARK-35223] Add IssueNavigationLink 2021-04-26 21:51:21 +08:00
R Preparing development version 3.2.2-SNAPSHOT 2022-01-20 05:03:17 +00:00
assembly Preparing development version 3.2.2-SNAPSHOT 2022-01-20 05:03:17 +00:00
bin [SPARK-38563][PYTHON] Upgrade to Py4J 0.10.9.5 2022-03-18 14:04:11 +09:00
binder [SPARK-37624][PYTHON][DOCS] Suppress warnings for live pandas-on-Spark quickstart notebooks 2021-12-13 19:22:00 +09:00
build [SPARK-36856][BUILD] Get correct JAVA_HOME for macOS 2021-09-28 17:27:18 +08:00
common [SPARK-33206][CORE][3.2] Fix shuffle index cache weight calculation for small index files 2022-03-02 12:24:16 -08:00
conf [SPARK-35143][SQL][SHELL] Add default log level config for spark-sql 2021-04-23 14:26:19 +09:00
core [SPARK-39505][UI] Escape log content rendered in UI 2022-06-17 13:32:14 -05:00
data [SPARK-22666][ML][SQL] Spark datasource for image format 2018-09-05 11:59:00 -07:00
dev [SPARK-39421][PYTHON][DOCS] Pin the docutils version <0.18 in documentation build 2022-06-09 14:27:39 +09:00
docs [MINOR][ML][DOCS] Fix sql data types link in the ml-pipeline page 2022-05-23 07:46:50 -07:00
examples Preparing development version 3.2.2-SNAPSHOT 2022-01-20 05:03:17 +00:00
external [SPARK-38236][SQL][3.2][3.1] Check if table location is absolute by "new Path(locationUri).isAbsolute" in create/alter table 2022-02-24 15:07:38 +08:00
graphx Preparing development version 3.2.2-SNAPSHOT 2022-01-20 05:03:17 +00:00
hadoop-cloud Preparing development version 3.2.2-SNAPSHOT 2022-01-20 05:03:17 +00:00
launcher Preparing development version 3.2.2-SNAPSHOT 2022-01-20 05:03:17 +00:00
licenses [SPARK-32435][PYTHON] Remove heapq3 port from Python 3 2020-07-27 20:10:13 +09:00
licenses-binary [SPARK-35150][ML] Accelerate fallback BLAS with dev.ludovic.netlib 2021-04-27 14:00:59 -05:00
mllib [SPARK-38816][ML][DOCS] Fix comment about choice of initial factors in ALS 2022-04-18 08:55:12 +09:00
mllib-local Preparing development version 3.2.2-SNAPSHOT 2022-01-20 05:03:17 +00:00
project [SPARK-38081][K8S][TESTS] Support `cloud`-backend in K8s IT with SBT 2022-03-02 12:40:04 -08:00
python [SPARK-39373][SPARK-39273][SPARK-39252][PYTHON][3.2] Recover branch-3.2 build broken by and 2022-06-03 21:52:11 +09:00
repl Preparing development version 3.2.2-SNAPSHOT 2022-01-20 05:03:17 +00:00
resource-managers [SPARK-38652][K8S] `uploadFileUri` should preserve file scheme 2022-03-30 08:27:06 -07:00
sbin [SPARK-38563][PYTHON] Upgrade to Py4J 0.10.9.5 2022-03-18 14:04:11 +09:00
sql [SPARK-39496][SQL] Handle null struct in `Inline.eval` 2022-06-18 09:27:07 +09:00
streaming Preparing development version 3.2.2-SNAPSHOT 2022-01-20 05:03:17 +00:00
tools Preparing development version 3.2.2-SNAPSHOT 2022-01-20 05:03:17 +00:00
.asf.yaml [MINOR][INFRA] Update a broken link in .asf.yml 2021-01-16 13:42:27 -08:00
.gitattributes [SPARK-30653][INFRA][SQL] EOL character enforcement for java/scala/xml/py/R files 2020-01-27 10:20:51 -08:00
.gitignore [SPARK-36092][INFRA][BUILD][PYTHON] Migrate to GitHub Actions with Codecov from Jenkins 2021-08-01 21:38:39 +09:00
CONTRIBUTING.md [MINOR][DOCS] Tighten up some key links to the project and download pages to use HTTPS 2019-05-21 10:56:42 -07:00
LICENSE [SPARK-32435][PYTHON] Remove heapq3 port from Python 3 2020-07-27 20:10:13 +09:00
LICENSE-binary [SPARK-35295][ML] Replace fully com.github.fommil.netlib by dev.ludovic.netlib:2.0 2021-05-12 08:59:36 -05:00
NOTICE [SPARK-29674][CORE] Update dropwizard metrics to 4.1.x for JDK 9+ 2019-11-03 15:13:06 -08:00
NOTICE-binary [SPARK-29674][CORE] Update dropwizard metrics to 4.1.x for JDK 9+ 2019-11-03 15:13:06 -08:00
README.md [SPARK-36092][INFRA][BUILD][PYTHON] Migrate to GitHub Actions with Codecov from Jenkins 2021-08-01 21:38:39 +09:00
appveyor.yml [SPARK-33757][INFRA][R][FOLLOWUP] Provide more simple solution 2020-12-13 17:27:39 -08:00
pom.xml [SPARK-39183][BUILD] Upgrade Apache Xerces Java to 2.12.2 2022-05-16 18:10:28 -05:00
scalastyle-config.xml [SPARK-35894][BUILD] Introduce new style enforce to not import scala.collection.Seq/IndexedSeq 2021-06-26 09:41:16 +09:00

README.md

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.

https://spark.apache.org/

GitHub Action Build Jenkins Build AppVeyor Build PySpark Coverage

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.