You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by we...@apache.org on 2018/02/15 09:13:15 UTC
spark git commit: [SPARK-23359][SQL] Adds an alias 'names' of
'fieldNames' in Scala's StructType
Repository: spark
Updated Branches:
refs/heads/master 7539ae59d -> ed8647609
[SPARK-23359][SQL] Adds an alias 'names' of 'fieldNames' in Scala's StructType
## What changes were proposed in this pull request?
This PR proposes to add an alias 'names' of 'fieldNames' in Scala. Please see the discussion in [SPARK-20090](https://issues.apache.org/jira/browse/SPARK-20090).
## How was this patch tested?
Unit tests added in `DataTypeSuite.scala`.
Author: hyukjinkwon <gu...@gmail.com>
Closes #20545 from HyukjinKwon/SPARK-23359.
Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/ed864760
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/ed864760
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/ed864760
Branch: refs/heads/master
Commit: ed8647609883fcef16be5d24c2cb4ebda25bd6f0
Parents: 7539ae5
Author: hyukjinkwon <gu...@gmail.com>
Authored: Thu Feb 15 17:13:05 2018 +0800
Committer: Wenchen Fan <we...@databricks.com>
Committed: Thu Feb 15 17:13:05 2018 +0800
----------------------------------------------------------------------
.../main/scala/org/apache/spark/sql/types/StructType.scala | 7 +++++++
.../scala/org/apache/spark/sql/types/DataTypeSuite.scala | 8 ++++++++
2 files changed, 15 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/spark/blob/ed864760/sql/catalyst/src/main/scala/org/apache/spark/sql/types/StructType.scala
----------------------------------------------------------------------
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/types/StructType.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/types/StructType.scala
index e3b0969..d5011c3 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/types/StructType.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/types/StructType.scala
@@ -104,6 +104,13 @@ case class StructType(fields: Array[StructField]) extends DataType with Seq[Stru
/** Returns all field names in an array. */
def fieldNames: Array[String] = fields.map(_.name)
+ /**
+ * Returns all field names in an array. This is an alias of `fieldNames`.
+ *
+ * @since 2.4.0
+ */
+ def names: Array[String] = fieldNames
+
private lazy val fieldNamesSet: Set[String] = fieldNames.toSet
private lazy val nameToField: Map[String, StructField] = fields.map(f => f.name -> f).toMap
private lazy val nameToIndex: Map[String, Int] = fieldNames.zipWithIndex.toMap
http://git-wip-us.apache.org/repos/asf/spark/blob/ed864760/sql/catalyst/src/test/scala/org/apache/spark/sql/types/DataTypeSuite.scala
----------------------------------------------------------------------
diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/types/DataTypeSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/types/DataTypeSuite.scala
index 8e2b32c..5a86f40 100644
--- a/sql/catalyst/src/test/scala/org/apache/spark/sql/types/DataTypeSuite.scala
+++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/types/DataTypeSuite.scala
@@ -134,6 +134,14 @@ class DataTypeSuite extends SparkFunSuite {
assert(mapped === expected)
}
+ test("fieldNames and names returns field names") {
+ val struct = StructType(
+ StructField("a", LongType) :: StructField("b", FloatType) :: Nil)
+
+ assert(struct.fieldNames === Seq("a", "b"))
+ assert(struct.names === Seq("a", "b"))
+ }
+
test("merge where right contains type conflict") {
val left = StructType(
StructField("a", LongType) ::
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org