Skip to content

Commit 219a49c

Browse files
amaliujiazhengruifeng
authored andcommitted
[SPARK-40980][CONNECT][TEST] Support session.sql in Connect DSL
### What changes were proposed in this pull request? This PR adds `def sql(sqlText: String)` to DSL and test the SQL proto with SparkSession/DataFrame. ### Why are the changes needed? Improve testing coverage. ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? UT Closes apache#38459 from amaliujia/SPARK-40980. Authored-by: Rui Wang <[email protected]> Signed-off-by: Ruifeng Zheng <[email protected]>
1 parent 968463b commit 219a49c

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

connector/connect/src/main/scala/org/apache/spark/sql/connect/dsl/package.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ package object dsl {
198198
}
199199
Relation.newBuilder().setRange(range).build()
200200
}
201+
202+
def sql(sqlText: String): Relation = {
203+
Relation.newBuilder().setSql(SQL.newBuilder().setQuery(sqlText)).build()
204+
}
201205
}
202206

203207
implicit class DslLogicalPlan(val logicalPlan: Relation) {

connector/connect/src/test/scala/org/apache/spark/sql/connect/planner/SparkConnectProtoSuite.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ class SparkConnectProtoSuite extends PlanTest with SparkConnectPlanTest {
230230
spark.range(2, 10, 10, 100).toDF())
231231
}
232232

233+
test("Test Session.sql") {
234+
comparePlans(connect.sql("SELECT 1"), spark.sql("SELECT 1"))
235+
}
236+
233237
private def createLocalRelationProtoByQualifiedAttributes(
234238
attrs: Seq[proto.Expression.QualifiedAttribute]): proto.Relation = {
235239
val localRelationBuilder = proto.LocalRelation.newBuilder()

0 commit comments

Comments
 (0)