2

我遇到了一個問題:導入多個250000 columns of float64以上的多個小型csv文件到Apache Spark 2.0作爲Google Dataproc集羣運行。有一些字符串列,但只對1作爲類標籤真正感興趣。如何將大量列數的csv文件導入到Apache Spark 2.0中

當我運行在pyspark以下

csvdata = spark.read.csv("gs://[bucket]/csv/*.csv", header=True,mode="DROPMALFORMED") 

我得到一個

File "/usr/lib/spark/python/lib/py4j-0.10.1-src.zip/py4j/protocol.py", line 312, in get_return_value py4j.protocol.Py4JJavaError: An error occurred while calling o53.csv. : com.univocity.parsers.common.TextParsingException: java.lang.ArrayIndexOutOfBoundsException - 20480 Hint: Number of columns processed may have exceeded limit of 20480 columns. Use settings.setMaxColumns(int) to define the maximum number of columns your input can have Ensure your configuration is correct, with delimiters, quotes and escape sequences that match the input format you are trying to parse Parser Configuration: CsvParserSettings:

  1. 在哪裏/我該如何設置最大列解析器使用機器學習 數據。
  2. 有沒有更好的方式來獲取數據以便與Apache mllib一起使用?

This question points定義一個要使用的數據框的類,但是可以定義這樣一個大類而不必創建210,000個條目嗎?

回答

6

使用option

spark.read.option("maxColumns", n).csv(...) 

其中n是列數。

+0

當我運行這個''ivysettings.xml文件沒有在HIVE_HOME或HIVE_CONF_DIR中找到,/ etc/hive/conf.dist/ivysettings.xml將被使用'數據被導入,但float64被檢測爲字符串根據到'df.printSchema()' – mobcdi

+0

警告是不相關的,並且預期字符串類型。除非你推斷(你不應該)或提供架構它使用字符串。 –

+0

可以很容易地將所有的float64識別爲mllib的特性? – mobcdi