0

I have a program that is working in command line, but I'm trying to set up PyCharm to test its functionalities individually.

I must have configured something wrong, because whenever I try to read any data (whether it's a hive query or a csv), I get an error.

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

This seems to work, so I read my csv using pandas, and try to transform it into a spark Dataframe:

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

Here is my stack trace:

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)

There are no dates or time in the csv, so I don't understand what the respectSessionTimeZone relates to.

What could this error mean, and how could I solve it?

Laurent
  • 1,914
  • 2
  • 11
  • 25
  • There is some issue with the schema. Can you post an output of `latence.info()`? If it says something like `non-null object` then convert those columns to string and then try converting to Pyspark DF. – pissall Jun 19 '18 at 12:14
  • There is no missing data in my csv. ` 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` – Laurent Jun 19 '18 at 13:11
  • Convert you `PAYS` column to string if it's text or float/int if it's a number. – pissall Jun 20 '18 at 11:14

1 Answers1

0

So your latence.info() gives

<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

Convert 'PAYS' column to float/int if it's a number or else convert it to a string column. Then you'll be able to run

df = sqlContext.createDataFrame(latence)
pissall
  • 7,109
  • 2
  • 25
  • 45