Pyspark读取数据-java.util.NoSuchElementException:spark.sql.execution.pandas.respectSessionTimeZone

时间:2018-06-19 12:02:20

标签: python pyspark apache-spark-sql py4j apache-spark-2.1.1

我有一个在命令行中运行的程序,但是我试图设置PyCharm以单独测试其功能。

我肯定配置有误,因为每当我尝试读取任何数据(无论是配置单元查询还是csv)时,都会收到错误消息。

sc = SparkContext(conf=SparkConf())
sqlContext = HiveContext(sc)

这似乎可行,所以我使用熊猫阅读了我的csv,并尝试将其转换为spark数据框:

latence = pd.read_csv("data/latence.csv")
sqlContext.createDataFrame(latence)

这是我的堆栈跟踪:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/appl/4C/demdet_dev/tools/venv/lib/python2.7/site-packages/pyspark/sql/context.py", line 302, in createDataFrame
    return self.sparkSession.createDataFrame(data, schema, samplingRatio, verifySchema)
  File "/appl/4C/demdet_dev/tools/venv/lib/python2.7/site-packages/pyspark/sql/session.py", line 646, in createDataFrame
    if self.conf.get("spark.sql.execution.pandas.respectSessionTimeZone").lower() \
  File "/appl/4C/demdet_dev/tools/venv/lib/python2.7/site-packages/pyspark/sql/conf.py", line 46, in get
    return self._jconf.get(key)
  File "/appl/4C/demdet_dev/tools/venv/lib/python2.7/site-packages/py4j/java_gateway.py", line 1160, in __call__
    answer, self.gateway_client, self.target_id, self.name)
  File "/appl/4C/demdet_dev/tools/venv/lib/python2.7/site-packages/pyspark/sql/utils.py", line 63, in deco
    return f(*a, **kw)
  File "/appl/4C/demdet_dev/tools/venv/lib/python2.7/site-packages/py4j/protocol.py", line 320, in get_return_value
    format(target_id, ".", name), value)
Py4JJavaError: An error occurred while calling o239.get.
: java.util.NoSuchElementException: spark.sql.execution.pandas.respectSessionTimeZone
    at org.apache.spark.sql.internal.SQLConf$$anonfun$getConfString$2.apply(SQLConf.scala:900)
    at org.apache.spark.sql.internal.SQLConf$$anonfun$getConfString$2.apply(SQLConf.scala:900)
    at scala.Option.getOrElse(Option.scala:121)
    at org.apache.spark.sql.internal.SQLConf.getConfString(SQLConf.scala:900)
    at org.apache.spark.sql.RuntimeConfig.get(RuntimeConfig.scala:74)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
    at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
    at py4j.Gateway.invoke(Gateway.java:280)
    at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
    at py4j.commands.CallCommand.execute(CallCommand.java:79)
    at py4j.GatewayConnection.run(GatewayConnection.java:214)
    at java.lang.Thread.run(Thread.java:745)

csv中没有日期或时间,因此我不了解respectSessionTimeZone的含义。

此错误是什么意思,我该如何解决?

1 个答案:

答案 0 :(得分:1)

所以您的latence.info()给出了

<class 'pandas.core.frame.DataFrame'> 
RangeIndex: 153 entries, 0 to 152 
Data columns (total 2 columns): 
PAYS 152 non-null object 
median 152 non-null float64 
dtypes: float64(1), object(1) 
memory usage: 2.5+ KB

如果“ PAYS”列是数字,则将其转换为float / int,否则将其转换为字符串列。然后您就可以运行

df = sqlContext.createDataFrame(latence)