aboutsummaryrefslogtreecommitdiff
path: root/sql/core/src/test
diff options
context:
space:
mode:
authorpetermaxlee <petermaxlee@gmail.com>2016-07-11 13:28:34 +0800
committerWenchen Fan <wenchen@databricks.com>2016-07-11 13:28:34 +0800
commit82f0874453991510216779926d795b0a4e07e854 (patch)
tree7606c863e631a1fb7822ce38348cca8f87855513 /sql/core/src/test
parent52b5bb0b7fabe6cc949f514c548f9fbc6a4fa181 (diff)
downloadspark-82f0874453991510216779926d795b0a4e07e854.tar.gz
spark-82f0874453991510216779926d795b0a4e07e854.tar.bz2
spark-82f0874453991510216779926d795b0a4e07e854.zip
[SPARK-16318][SQL] Implement all remaining xpath functions
## What changes were proposed in this pull request? This patch implements all remaining xpath functions that Hive supports and not natively supported in Spark: xpath_int, xpath_short, xpath_long, xpath_float, xpath_double, xpath_string, and xpath. ## How was this patch tested? Added unit tests and end-to-end tests. Author: petermaxlee <petermaxlee@gmail.com> Closes #13991 from petermaxlee/SPARK-16318.
Diffstat (limited to 'sql/core/src/test')
-rw-r--r--sql/core/src/test/scala/org/apache/spark/sql/XPathFunctionsSuite.scala62
-rw-r--r--sql/core/src/test/scala/org/apache/spark/sql/XmlFunctionsSuite.scala32
2 files changed, 62 insertions, 32 deletions
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/XPathFunctionsSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/XPathFunctionsSuite.scala
new file mode 100644
index 0000000000..1d33e7970b
--- /dev/null
+++ b/sql/core/src/test/scala/org/apache/spark/sql/XPathFunctionsSuite.scala
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql
+
+import org.apache.spark.sql.test.SharedSQLContext
+
+/**
+ * End-to-end tests for xpath expressions.
+ */
+class XPathFunctionsSuite extends QueryTest with SharedSQLContext {
+ import testImplicits._
+
+ test("xpath_boolean") {
+ val df = Seq("<a><b>b</b></a>").toDF("xml")
+ checkAnswer(df.selectExpr("xpath_boolean(xml, 'a/b')"), Row(true))
+ }
+
+ test("xpath_short, xpath_int, xpath_long") {
+ val df = Seq("<a><b>1</b><b>2</b></a>").toDF("xml")
+ checkAnswer(
+ df.selectExpr(
+ "xpath_short(xml, 'sum(a/b)')",
+ "xpath_int(xml, 'sum(a/b)')",
+ "xpath_long(xml, 'sum(a/b)')"),
+ Row(3.toShort, 3, 3L))
+ }
+
+ test("xpath_float, xpath_double, xpath_number") {
+ val df = Seq("<a><b>1.0</b><b>2.1</b></a>").toDF("xml")
+ checkAnswer(
+ df.selectExpr(
+ "xpath_float(xml, 'sum(a/b)')",
+ "xpath_double(xml, 'sum(a/b)')",
+ "xpath_number(xml, 'sum(a/b)')"),
+ Row(3.1.toFloat, 3.1, 3.1))
+ }
+
+ test("xpath_string") {
+ val df = Seq("<a><b>b</b><c>cc</c></a>").toDF("xml")
+ checkAnswer(df.selectExpr("xpath_string(xml, 'a/c')"), Row("cc"))
+ }
+
+ test("xpath") {
+ val df = Seq("<a><b>b1</b><b>b2</b><b>b3</b><c>c1</c><c>c2</c></a>").toDF("xml")
+ checkAnswer(df.selectExpr("xpath(xml, 'a/*/text()')"), Row(Seq("b1", "b2", "b3", "c1", "c2")))
+ }
+}
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/XmlFunctionsSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/XmlFunctionsSuite.scala
deleted file mode 100644
index 532d48cc26..0000000000
--- a/sql/core/src/test/scala/org/apache/spark/sql/XmlFunctionsSuite.scala
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.spark.sql
-
-import org.apache.spark.sql.test.SharedSQLContext
-
-/**
- * End-to-end tests for XML expressions.
- */
-class XmlFunctionsSuite extends QueryTest with SharedSQLContext {
- import testImplicits._
-
- test("xpath_boolean") {
- val df = Seq("<a><b>b</b></a>" -> "a/b").toDF("xml", "path")
- checkAnswer(df.selectExpr("xpath_boolean(xml, path)"), Row(true))
- }
-}