Skip to content
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
Next Next commit
[SPARK-10417][SQL] Iterating through Column results in infinite loop
  • Loading branch information
0x0FFF committed Sep 2, 2015
commit ea2e9d4e5e1abf7c4913ad33cb89424f444b80b7
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