我需要解析一个JSON schema文件,以创建一个pyspark.sql.types.StructType
。我找到了一个Scala库,可以帮助我完成这个任务。所以我会像这样调用它:
f = open('path/to/schema.json')
js = f.read()
conv = dspark.sparkContext._jvm.org.zalando.spark.jsonschema.SchemaConverter
schema = conv.convertContent(js)
但是当我尝试使用它来构建一个类似这样的
DataFrame
时:spark.read.format("json").schema(schema)
我得到了以下错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/Cellar/apache-spark/2.1.0/libexec/python/pyspark/sql/readwriter.py", line 103, in schema
raise TypeError("schema should be StructType")
TypeError: schema should be StructType
如果我打印类型:
print type(schema)
我得到:
<class 'py4j.java_gateway.JavaObject'>
如何将值包装为Python的StructType
?