SPARK Structured Streaming 中是否存在关于 StructField 的错误
Is there a bug about StructField in SPARK Structured Streaming
当我尝试这个时:
cfg = SparkConf().setAppName('MyApp')
spark = SparkSession.builder.config(conf=cfg).getOrCreate()
lines = spark.readStream.load(format='socket', host='localhost', port=9999,
schema=StructType(StructField('value', StringType, True)))
words = lines.groupBy('value').count()
query = words.writeStream.format('console').outputMode("complete").start()
query.awaitTermination()
然后我得到一些错误:
AssertionError: dataType should be DataType
然后我在 ./pyspark/sql/types.py 的第 403 行搜索源代码:
assert isinstance(dataType, DataType), "dataType should be DataType"
但是StringType基于AtomicType不是 DataType
class StringType(AtomicType):
"""String data type.
"""
__metaclass__ = DataTypeSingleton
所以有错吗?
在Python中DataTypes
不作为单例使用。创建 StructField
时,您必须使用一个实例。另外 StructType
需要一系列 StructField
:
StructType([StructField('value', StringType(), True)])
然而,这在这里完全没有意义。 TextSocketSource
的架构,带有架构参数。
当我尝试这个时:
cfg = SparkConf().setAppName('MyApp')
spark = SparkSession.builder.config(conf=cfg).getOrCreate()
lines = spark.readStream.load(format='socket', host='localhost', port=9999,
schema=StructType(StructField('value', StringType, True)))
words = lines.groupBy('value').count()
query = words.writeStream.format('console').outputMode("complete").start()
query.awaitTermination()
然后我得到一些错误:
AssertionError: dataType should be DataType
然后我在 ./pyspark/sql/types.py 的第 403 行搜索源代码:
assert isinstance(dataType, DataType), "dataType should be DataType"
但是StringType基于AtomicType不是 DataType
class StringType(AtomicType):
"""String data type.
"""
__metaclass__ = DataTypeSingleton
所以有错吗?
在Python中DataTypes
不作为单例使用。创建 StructField
时,您必须使用一个实例。另外 StructType
需要一系列 StructField
:
StructType([StructField('value', StringType(), True)])
然而,这在这里完全没有意义。 TextSocketSource