Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-10417][SQL] Iterating through Column results in infinite loop #8574

Closed
wants to merge 2 commits into from
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
3 changes: 3 additions & 0 deletions python/pyspark/sql/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ def __getattr__(self, item):
raise AttributeError(item)
return self.getField(item)

def __iter__(self):
raise TypeError("Column is not iterable")

# string methods
rlike = _bin_op("rlike")
like = _bin_op("like")
Expand Down
9 changes: 9 additions & 0 deletions python/pyspark/sql/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,15 @@ def test_with_column_with_existing_name(self):
keys = self.df.withColumn("key", self.df.key).select("key").collect()
self.assertEqual([r.key for r in keys], list(range(100)))

# regression test for SPARK-10417
def test_column_iterator(self):

def foo():
for x in self.df.key:
break

self.assertRaises(TypeError, foo)


class HiveContextSQLTests(ReusedPySparkTestCase):

Expand Down