अद्यतन: उदाहरण के लिए:
from pyspark.sql.functions import array, lit
df.where(df.a == array(*[lit(x) for x in ['list','of' , 'stuff']]))
मूल जवाब:
ठीक है, एक छोटा सा
वर्तमान संस्करण के साथ आप शाब्दिक के array
उपयोग कर सकते हैं ऐसा करने के लिए हैकी तरीका, जिसे पाइथन बैच नौकरी की आवश्यकता नहीं है, एस है इस तरह omething:
from pyspark.sql.functions import col, lit, size
from functools import reduce
from operator import and_
def array_equal(c, an_array):
same_size = size(c) == len(an_array) # Check if the same size
# Check if all items equal
same_items = reduce(
and_,
(c.getItem(i) == an_array[i] for i in range(len(an_array)))
)
return and_(same_size, same_items)
त्वरित परीक्षण:
df = sc.parallelize([
(1, ['list','of' , 'stuff']),
(2, ['foo', 'bar']),
(3, ['foobar']),
(4, ['list','of' , 'stuff', 'and', 'foo']),
(5, ['a', 'list','of' , 'stuff']),
]).toDF(['id', 'a'])
df.where(array_equal(col('a'), ['list','of' , 'stuff'])).show()
## +---+-----------------+
## | id| a|
## +---+-----------------+
## | 1|[list, of, stuff]|
## +---+-----------------+
कि हालांकि थोड़ा धीमा है? – Luke