AnalysisException在数据模式中发现重复的列

时间:2019-04-04 12:13:12

标签: python apache-spark dataframe pyspark jupyter-notebook

我正在Jupyter Notebook中运行PySpark,试图加载许多大的JSON文件。我以前只用一个文件(大小为11 GB)测试了相同的脚本,并且没有任何问题。

我的Python脚本:

---------------------------------------------------------------------------
Py4JJavaError                             Traceback (most recent call last)
/opt/cloudera/parcels/SPARK2/lib/spark2/python/pyspark/sql/utils.py in deco(*a, **kw)
     62         try:
---> 63             return f(*a, **kw)
     64         except py4j.protocol.Py4JJavaError as e:

/opt/cloudera/parcels/SPARK2/lib/spark2/python/lib/py4j-0.10.6-src.zip/py4j/protocol.py in get_return_value(answer, gateway_client, target_id, name)
    319                     "An error occurred while calling {0}{1}{2}.\n".
--> 320                     format(target_id, ".", name), value)
    321             else:

Py4JJavaError: An error occurred while calling o6192.json.
: org.apache.spark.sql.AnalysisException: Found duplicate column(s) in the data schema: `result`, `lts`, `paris_id`;
    at org.apache.spark.sql.util.SchemaUtils$.checkColumnNameDuplication(SchemaUtils.scala:85)
    at org.apache.spark.sql.util.SchemaUtils$.checkColumnNameDuplication(SchemaUtils.scala:67)
    at org.apache.spark.sql.execution.datasources.DataSource.resolveRelation(DataSource.scala:421)
    at org.apache.spark.sql.DataFrameReader.loadV1Source(DataFrameReader.scala:239)
    at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:227)
    at org.apache.spark.sql.DataFrameReader.json(DataFrameReader.scala:397)
    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:282)
    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:748)


During handling of the above exception, another exception occurred:

AnalysisException                         Traceback (most recent call last)
<ipython-input-21-99870ac0546e> in <module>()
     67 print("LOADING JSON DF")
     68 start_time_json = time.time()
---> 69 jsonDF = sqlContext.read.json(top_directory + "traceroute*")
     70 print("SUCCESS")
     71 print("Time elapsed: " + str(time.time() - start_time_json) + " seconds")

/opt/cloudera/parcels/SPARK2/lib/spark2/python/pyspark/sql/readwriter.py in json(self, path, schema, primitivesAsString, prefersDecimal, allowComments, allowUnquotedFieldNames, allowSingleQuotes, allowNumericLeadingZero, allowBackslashEscapingAnyCharacter, mode, columnNameOfCorruptRecord, dateFormat, timestampFormat, multiLine, allowUnquotedControlChars)
    259             path = [path]
    260         if type(path) == list:
--> 261             return self._df(self._jreader.json(self._spark._sc._jvm.PythonUtils.toSeq(path)))
    262         elif isinstance(path, RDD):
    263             def func(iterator):

/opt/cloudera/parcels/SPARK2/lib/spark2/python/lib/py4j-0.10.6-src.zip/py4j/java_gateway.py in __call__(self, *args)
   1158         answer = self.gateway_client.send_command(command)
   1159         return_value = get_return_value(
-> 1160             answer, self.gateway_client, self.target_id, self.name)
   1161 
   1162         for temp_arg in temp_args:

/opt/cloudera/parcels/SPARK2/lib/spark2/python/pyspark/sql/utils.py in deco(*a, **kw)
     67                                              e.java_exception.getStackTrace()))
     68             if s.startswith('org.apache.spark.sql.AnalysisException: '):
---> 69                 raise AnalysisException(s.split(': ', 1)[1], stackTrace)
     70             if s.startswith('org.apache.spark.sql.catalyst.analysis'):
     71                 raise AnalysisException(s.split(': ', 1)[1], stackTrace)

AnalysisException: 'Found duplicate column(s) in the data schema: `result`, `lts`, `paris_id`;'

然后我得到这个错误:

App.tsx

这是一个对象的JSON模式:https://pastebin.com/W6nHuJuL

为什么说这些列中有重复项?从我发布的JSON中可以看到,没有重复。

0 个答案:

没有答案