Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ jobs:
run: |
curl -LO https://dist.apache.org/repos/dist/dev/spark/v4.0.0-rc4-bin/spark-4.0.0-bin-hadoop3.tgz
tar xvfz spark-4.0.0-bin-hadoop3.tgz
cd spark-4.0.0-bin-hadoop3/sbin
mv spark-4.0.0-bin-hadoop3 /tmp/spark
cd /tmp/spark/sbin
./start-connect-server.sh
cd ../..
cd -
swift test --no-parallel

integration-test-token:
Expand All @@ -114,9 +115,10 @@ jobs:
run: |
curl -LO https://dist.apache.org/repos/dist/dev/spark/v4.0.0-rc4-bin/spark-4.0.0-bin-hadoop3.tgz
tar xvfz spark-4.0.0-bin-hadoop3.tgz
cd spark-4.0.0-bin-hadoop3/sbin
mv spark-4.0.0-bin-hadoop3 /tmp/spark
cd /tmp/spark/sbin
./start-connect-server.sh
cd ../..
cd -
swift test --no-parallel

integration-test-mac-spark3:
Expand All @@ -135,7 +137,8 @@ jobs:
run: |
curl -LO https://downloads.apache.org/spark/spark-3.5.5/spark-3.5.5-bin-hadoop3.tgz
tar xvfz spark-3.5.5-bin-hadoop3.tgz
cd spark-3.5.5-bin-hadoop3/sbin
mv spark-3.5.5-bin-hadoop3 /tmp/spark
cd /tmp/spark/sbin
./start-connect-server.sh --packages org.apache.spark:spark-connect_2.12:3.5.5
cd ../..
cd -
swift test --no-parallel
6 changes: 5 additions & 1 deletion Tests/SparkConnectTests/Resources/queries/binary.sql.answer
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
[abc]
+----------+
| abc|
+----------+
|[61 62 63]|
+----------+
5 changes: 4 additions & 1 deletion Tests/SparkConnectTests/Resources/queries/cache.sql.answer
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@

++
||
++
++
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@

++
||
++
++
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@

++
||
++
++
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@

++
||
++
++
6 changes: 5 additions & 1 deletion Tests/SparkConnectTests/Resources/queries/date.sql.answer
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
[2025-03-15 00:00:00 +0000]
+-----------------+
|DATE '2025-03-15'|
+-----------------+
| 2025-03-15|
+-----------------+
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
[Catalog Name,spark_catalog]
[Namespace Name,default]
[Comment,default database]
[Location,*]
[Owner,*]
+--------------+----------------------------------------+
| info_name| info_value|
+--------------+----------------------------------------+
| Catalog Name| spark_catalog|
|Namespace Name| default|
| Comment| default database|
| Location|*|
| Owner| *|
+--------------+----------------------------------------+
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[Function: abs]
[Class: org.apache.spark.sql.catalyst.expressions.Abs]
[Usage: abs(expr) - Returns the absolute value of the numeric or interval value.]
+-------------------------------------------------------------------------------+
| function_desc|
+-------------------------------------------------------------------------------+
| Function: abs|
| Class: org.apache.spark.sql.catalyst.expressions.Abs|
|Usage: abs(expr) - Returns the absolute value of the numeric or interval value.|
+-------------------------------------------------------------------------------+
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[id,int,null]
[name,string,null]
[salary,double,null]
+--------+---------+-------+
|col_name|data_type|comment|
+--------+---------+-------+
| id| int| NULL|
| name| string| NULL|
| salary| double| NULL|
+--------+---------+-------+
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
[col,int,null]
+--------+---------+-------+
|col_name|data_type|comment|
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Column names are checked like this.

+--------+---------+-------+
| col| int| NULL|
+--------+---------+-------+
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@

++
||
++
++
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@

++
||
++
++
27 changes: 5 additions & 22 deletions Tests/SparkConnectTests/Resources/queries/explain.sql.answer
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
[== Parsed Logical Plan ==
'Aggregate ['k], ['k, unresolvedalias('sum('v))]
+- SubqueryAlias t
+- LocalRelation [k#, v#]

== Analyzed Logical Plan ==
k: int, sum(v): bigint
Aggregate [k#], [k#, sum(v#) AS sum(v)#]
+- SubqueryAlias t
+- LocalRelation [k#, v#]

== Optimized Logical Plan ==
Aggregate [k#], [k#, sum(v#) AS sum(v)#]
+- LocalRelation [k#, v#]

== Physical Plan ==
AdaptiveSparkPlan isFinalPlan=false
+- HashAggregate(keys=[k#], functions=[sum(v#)], output=[k#, sum(v)#])
+- Exchange hashpartitioning(k#, 200), ENSURE_REQUIREMENTS, [plan_id=]
+- HashAggregate(keys=[k#], functions=[partial_sum(v#)], output=[k#, sum#])
+- LocalTableScan [k#, v#]
]
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| plan|
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|== Parsed Logical Plan ==\n'Aggregate ['k], ['k, unresolvedalias('sum('v))]\n+- SubqueryAlias t\n +- LocalRelation [k#, v#]\n\n== Analyzed Logical Plan ==\nk: int, sum(v): bigint\nAggregate [k#], [k#, sum(v#) AS sum(v)#]\n+- SubqueryAlias t\n +- LocalRelation [k#, v#]\n\n== Optimized Logical Plan ==\nAggregate [k#], [k#, sum(v#) AS sum(v)#]\n+- LocalRelation [k#, v#]\n\n== Physical Plan ==\nAdaptiveSparkPlan isFinalPlan=false\n+- HashAggregate(keys=[k#], functions=[sum(v#)], output=[k#, sum(v)#])\n +- Exchange hashpartitioning(k#, 200), ENSURE_REQUIREMENTS, [plan_id=]\n +- HashAggregate(keys=[k#], functions=[partial_sum(v#)], output=[k#, sum#])\n +- LocalTableScan [k#, v#]\n|
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
[1.0,-2.0,3.0,-4.0,inf,nan,inf,nan]
+---+----+---+----+--------+---+--------+---+
|1.0|-2.0|3.0|-4.0| inf|NaN| inf|NaN|
+---+----+---+----+--------+---+--------+---+
|1.0|-2.0|3.0|-4.0|Infinity|NaN|Infinity|NaN|
+---+----+---+----+--------+---+--------+---+
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
[127,-128,32767,-32768,2147483647,-2147483648,9223372036854775807,-9223372036854775808]
+---+----+-----+------+----------+-----------+-------------------+--------------------+
|127|-128|32767|-32768|2147483647|-2147483648|9223372036854775807|-9223372036854775808|
+---+----+-----+------+----------+-----------+-------------------+--------------------+
|127|-128|32767|-32768|2147483647|-2147483648|9223372036854775807|-9223372036854775808|
+---+----+-----+------+----------+-----------+-------------------+--------------------+
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
[0,0]
[1,2]
+---+------+
|col|result|
+---+------+
| 0| 0|
| 1| 2|
+---+------+
6 changes: 5 additions & 1 deletion Tests/SparkConnectTests/Resources/queries/select.sql.answer
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
[1]
+---+
| 1|
+---+
| 1|
+---+
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
[default]
+---------+
|namespace|
+---------+
| default|
+---------+
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
[,testcache,true]
+---------+---------+-----------+
|namespace|tableName|isTemporary|
+---------+---------+-----------+
| |testcache| true|
+---------+---------+-----------+
6 changes: 5 additions & 1 deletion Tests/SparkConnectTests/Resources/queries/string.sql.answer
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
[abc,def]
+---+---+
|abc|def|
+---+---+
|abc|def|
+---+---+
6 changes: 5 additions & 1 deletion Tests/SparkConnectTests/Resources/queries/struct.sql.answer
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
[{1},{2,{3}}]
+---------+--------------------+
|struct(1)|struct(2, struct(3))|
+---------+--------------------+
| {1}| {2, {3}}|
+---------+--------------------+
5 changes: 4 additions & 1 deletion Tests/SparkConnectTests/Resources/queries/uncache.sql.answer
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@

++
||
++
++
24 changes: 20 additions & 4 deletions Tests/SparkConnectTests/SQLTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import Foundation
import Testing

import SparkConnect
@testable import SparkConnect

/// A test suite for various SQL statements.
struct SQLTests {
Expand Down Expand Up @@ -49,6 +49,10 @@ struct SQLTests {
return str.replacing(regexOwner, with: "*")
}

private func normalize(_ str: String) -> String {
return str.replacing(/[-]+/, with: "-").replacing(/[ ]+/, with: " ")
}

@Test
func testRemoveID() {
#expect(removeID("123") == "123")
Expand All @@ -69,6 +73,12 @@ struct SQLTests {
#expect(removeOwner("185") == "*")
}

@Test
func testNormalize() {
#expect(normalize("+------+------------------+") == "+-+-+")
#expect(normalize("+ + +") == "+ + +")
}

let queriesForSpark4Only: [String] = [
"create_scala_function.sql",
"create_table_function.sql",
Expand All @@ -80,6 +90,7 @@ struct SQLTests {
@Test
func runAll() async throws {
let spark = try await SparkSession.builder.getOrCreate()
let MAX = Int32.max
for name in try! fm.contentsOfDirectory(atPath: path).sorted() {
guard name.hasSuffix(".sql") else { continue }
print(name)
Expand All @@ -89,13 +100,18 @@ struct SQLTests {
}

let sql = try String(contentsOf: URL(fileURLWithPath: "\(path)/\(name)"), encoding: .utf8)
let answer = cleanUp(try await spark.sql(sql).collect().map { $0.toString() }.joined(separator: "\n"))
let result = try await spark.sql(sql).showString(MAX, MAX, false).collect()[0].get(0) as! String
let answer = cleanUp(result.trimmingCharacters(in: .whitespacesAndNewlines))
if (regenerateGoldenFiles) {
let path = "\(FileManager.default.currentDirectoryPath)/Tests/SparkConnectTests/Resources/queries/\(name).answer"
fm.createFile(atPath: path, contents: (answer + "\n").data(using: .utf8)!, attributes: nil)
fm.createFile(atPath: path, contents: answer.data(using: .utf8)!, attributes: nil)
} else {
let expected = cleanUp(try String(contentsOf: URL(fileURLWithPath: "\(path)/\(name).answer"), encoding: .utf8))
#expect(answer == expected.trimmingCharacters(in: .whitespacesAndNewlines))
.trimmingCharacters(in: .whitespacesAndNewlines)
if (answer != expected) {
print("Try to compare normalized result.")
#expect(normalize(answer) == normalize(expected))
}
}
}
await spark.stop()
Expand Down
Loading