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 1 commit
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
4 changes: 4 additions & 0 deletions python/pyspark/sql/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ def __getattr__(self, item):
raise AttributeError(item)
return self.getField(item)

def __iter__(self):
raise TypeError('%s.%s object is not iterable' % (self.__module__,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think "Column is not iterable" is a good enough error message.

self.__class__.__name__))

# string methods
rlike = _bin_op("rlike")
like = _bin_op("like")
Expand Down
10 changes: 10 additions & 0 deletions python/pyspark/sql/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,16 @@ 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):
# Catch exception raised during improper construction
try:
for x in self.df.key:
break
self.assertEqual(0, 1)
except TypeError:
self.assertEqual(1, 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

you can use assertRaises to test the exception case.



class HiveContextSQLTests(ReusedPySparkTestCase):

Expand Down