hvanhovell commented on code in PR #40160:
URL: https://github.com/apache/spark/pull/40160#discussion_r1118950348
##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/SparkSession.scala:
##########
@@ -89,8 +90,29 @@ class SparkSession(
@Experimental
def sql(sqlText: String, args: java.util.Map[String, String]): DataFrame =
newDataset {
builder =>
- builder
- .setSql(proto.SQL.newBuilder().setQuery(sqlText).putAllArgs(args))
+ // Send the SQL once to the server and then check the output.
+ val cmd = newCommand(b =>
+
b.setSqlCommand(proto.SqlCommand.newBuilder().setSql(sqlText).putAllArgs(args)))
+ val plan = proto.Plan.newBuilder().setCommand(cmd)
+ val response = client.execute(plan.build())
+ val (data, isSqlCommand) =
+ response.asScala.foldLeft((Seq[ByteString](), false))((acc, resp) =>
+ if (resp.hasSqlCommandResult) {
+ (acc._1, resp.getSqlCommandResult.getIsCommand)
+ } else if (resp.hasArrowBatch) {
+ (acc._1 ++ Seq(resp.getArrowBatch.getData), acc._2)
+ } else {
+ acc
+ })
+
+ // Handle the result behavior
+ if (isSqlCommand) {
+ assert(data.size <= 1)
Review Comment:
We always send one batch right? Even if it is empty, you should always get
the schema.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]