diff options
-rwxr-xr-x[-rw-r--r--] | sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/Metadata.scala | 3 | ||||
-rwxr-xr-x[-rw-r--r--] | sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/MetadataSuite.scala | 13 |
2 files changed, 16 insertions, 0 deletions
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/Metadata.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/Metadata.scala index 2f2082fa3c..8172733e94 100644..100755 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/Metadata.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/Metadata.scala @@ -34,6 +34,9 @@ import org.json4s.jackson.JsonMethods._ */ sealed class Metadata private[util] (private[util] val map: Map[String, Any]) extends Serializable { + /** Tests whether this Metadata contains a binding for a key. */ + def contains(key: String): Boolean = map.contains(key) + /** Gets a Long. */ def getLong(key: String): Long = get(key) diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/MetadataSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/MetadataSuite.scala index 0063d31666..f005b7df21 100644..100755 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/MetadataSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/MetadataSuite.scala @@ -56,17 +56,30 @@ class MetadataSuite extends FunSuite { .build() test("metadata builder and getters") { + assert(age.contains("summary") === false) + assert(age.contains("index") === true) assert(age.getLong("index") === 1L) + assert(age.contains("average") === true) assert(age.getDouble("average") === 45.0) + assert(age.contains("categorical") === true) assert(age.getBoolean("categorical") === false) + assert(age.contains("name") === true) assert(age.getString("name") === "age") + assert(metadata.contains("purpose") === true) assert(metadata.getString("purpose") === "ml") + assert(metadata.contains("isBase") === true) assert(metadata.getBoolean("isBase") === false) + assert(metadata.contains("summary") === true) assert(metadata.getMetadata("summary") === summary) + assert(metadata.contains("long[]") === true) assert(metadata.getLongArray("long[]").toSeq === Seq(0L, 1L)) + assert(metadata.contains("double[]") === true) assert(metadata.getDoubleArray("double[]").toSeq === Seq(3.0, 4.0)) + assert(metadata.contains("boolean[]") === true) assert(metadata.getBooleanArray("boolean[]").toSeq === Seq(true, false)) + assert(gender.contains("categories") === true) assert(gender.getStringArray("categories").toSeq === Seq("male", "female")) + assert(metadata.contains("features") === true) assert(metadata.getMetadataArray("features").toSeq === Seq(age, gender)) } |