GitHub user HyukjinKwon opened a pull request:
https://github.com/apache/spark/pull/16703
[SPARK-12970][DOCS] Fix the example in SturctType APIs for Scala and Java
## What changes were proposed in this pull request?
This PR fixes both,
javadoc8 break
```
[error]
.../spark/sql/hive/target/java/org/apache/spark/sql/hive/FindHiveSerdeTable.java:3:
error: reference not found
[error] * Replaces {@link SimpleCatalogRelation} with {@link
MetastoreRelation} if its table provider is hive.
```
and the example in `StructType` as a self-contained example as below:
```scala
import org.apache.spark.sql._
import org.apache.spark.sql.types._
val struct =
StructType(
StructField("a", IntegerType, true) ::
StructField("b", LongType, false) ::
StructField("c", BooleanType, false) :: Nil)
// Extract a single StructField.
val singleField = struct("b")
// singleField: StructField = StructField(b,LongType,false)
// If this struct does not have a field called "d", it throws an exception.
struct("d")
// java.lang.IllegalArgumentException: Field "d" does not exist.
// ...
// Extract multiple StructFields. Field names are provided in a set.
// A StructType object will be returned.
val twoFields = struct(Set("b", "c"))
// twoFields: StructType =
// StructType(StructField(b,LongType,false),
StructField(c,BooleanType,false))
// Any names without matching fields will be ignored.
// For the case shown below, "d" will be ignored and
// it is treated as struct(Set("b", "c")).
struct(Set("b", "c", "d"))
// java.lang.IllegalArgumentException: Field "d" does not exist.
// ...
```
```scala
import org.apache.spark.sql._
import org.apache.spark.sql.types._
val innerStruct =
StructType(
StructField("f1", IntegerType, true) ::
StructField("f2", LongType, false) ::
StructField("f3", BooleanType, false) :: Nil)
val struct = StructType(
StructField("a", innerStruct, true) :: Nil)
// Create a Row with the schema defined by struct
val row = Row(Row(1, 2, true))
```
Also, now when the column is missing, it throws an exception rather than
ignoring.
## How was this patch tested?
Manually via `sbt unidoc`.
- Scaladoc
<img width="658" alt="2017-01-26 12 02 46"
src="https://cloud.githubusercontent.com/assets/6477701/22295599/d417a3cc-e35a-11e6-8533-7d904640c834.png">
<img width="444" alt="2017-01-25 11 48 09"
src="https://cloud.githubusercontent.com/assets/6477701/22295140/314e1eb0-e359-11e6-943c-c11c26087113.png">
- Javadoc
<img width="713" alt="2017-01-26 12 02 38"
src="https://cloud.githubusercontent.com/assets/6477701/22295605/deea817a-e35a-11e6-93c5-48a9029024cc.png">
<img width="444" alt="2017-01-25 11 47 58"
src="https://cloud.githubusercontent.com/assets/6477701/22295169/4eb4a140-e359-11e6-82c0-690519c9f4b9.png">
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/HyukjinKwon/spark SPARK-12970
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/spark/pull/16703.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #16703
----
commit 2e9bec8c8b3676967ae6b292bfa1c2396416b15e
Author: hyukjinkwon <[email protected]>
Date: 2017-01-25T14:37:45Z
Fix the example in SturctType APIs for Scala and Java
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]