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
Original file line number Diff line number Diff line change
Expand Up @@ -1508,8 +1508,10 @@ class SparkConnectPlanner(val session: SparkSession) {
maxRecordsPerBatch,
maxBatchSize,
timeZoneId)
assert(batches.size == 1)
batches.next()
assert(batches.hasNext)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry for the late reply but how is this code different to the existing one?

val bytes = batches.next()
bytes

Is the same as

batches.next()

The asserts in between don't count as they don't have side effects.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The batches is an iterator, so batches.size consumes all the data in the iterator to calculate the size.
Then batches.next() would return an empty data? Usually it should throw an Exception, though.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see thank you. My understanding with iterators was that non rewindable iterators simply do not have a size method.

But something new learned.

val bytes = batches.next()
assert(!batches.hasNext, s"remaining batches: ${batches.size}")
bytes
}

// To avoid explicit handling of the result on the client, we build the expected input
Expand Down
6 changes: 6 additions & 0 deletions python/pyspark/sql/tests/connect/test_connect_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2876,6 +2876,12 @@ def test_unsupported_io_functions(self):
with self.assertRaises(NotImplementedError):
getattr(df.write, f)()

def test_sql_with_command(self):
# SPARK-42705: spark.sql should return values from the command.
self.assertEqual(
self.connect.sql("show functions").collect(), self.spark.sql("show functions").collect()
)


@unittest.skipIf(not should_test_connect, connect_requirement_message)
class ClientTests(unittest.TestCase):
Expand Down