从pyspark中的列名列表中得出structtype架构
在Pyspark中,我不想进行编码定义定义,我想从下面的变量中得出架构。
mySchema=[("id","IntegerType()", True),
("name","StringType()", True),
("InsertDate","TimestampType()", True)
]
result = mySchema.map(lambda l: StructField(l[0],l[1],l[2]))
如何实现此逻辑以从myschema
生成structTypeschema
?
预期输出:
structTypeSchema = StructType(fields=[
StructField("id", IntegerType(), True),
StructField("name", StringType(), True),
StructField("InsertDate",TimestampType(), True)])
In PySpark, I don't want to hardcode the schema definition, I want to derive the schema from below variable.
mySchema=[("id","IntegerType()", True),
("name","StringType()", True),
("InsertDate","TimestampType()", True)
]
result = mySchema.map(lambda l: StructField(l[0],l[1],l[2]))
How do I achieve this logic to generate the structTypeSchema
from mySchema
?
Expected output:
structTypeSchema = StructType(fields=[
StructField("id", IntegerType(), True),
StructField("name", StringType(), True),
StructField("InsertDate",TimestampType(), True)])
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
continue
You can try something along these lines:
or