Python Pyspark StructType 未定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30905515/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Pyspark StructType is not defined
提问by Joseph Seung Jae Dollar
I'm trying to struct a schema for db testing, and StructType apparently isn't working for some reason. I'm following a tut, and it doesn't import any extra module.
我正在尝试为 db 测试构建架构,而 StructType 显然由于某种原因无法正常工作。我正在关注 tut,它没有导入任何额外的模块。
<type 'exceptions.NameError'>, NameError("name 'StructType' is not defined",), <traceback object at 0x2b555f0>)
I'm on spark 1.4.0, and Ubuntu 12 if that has anything to do with the problem. How would I fix this problem? Thank you in advance.
我在 spark 1.4.0 和 Ubuntu 12 上,如果这与问题有关的话。我将如何解决这个问题?先感谢您。
采纳答案by zero323
Did you import StructType? If not
你进口了StructType吗?如果不
from pyspark.sql.types import StructType
should solve the problem.
应该可以解决问题。
回答by Ani Menon
from pyspark.sql.types import StructType
That would fix it but next you might get NameError: name 'IntegerType' is not definedor NameError: name 'StringType' is not defined..
那会解决它,但接下来你可能会得到NameError: name 'IntegerType' is not defined或NameError: name 'StringType' is not defined......
To avoid all of that just do:
为避免所有这些,只需执行以下操作:
from pyspark.sql.types import *
Alternatively import all the types you require one by one:
或者,一一导入您需要的所有类型:
from pyspark.sql.types import StructType, IntegerType, StringType
All Types: Apache Spark Data Types
所有类型:Apache Spark 数据类型

