0

I'm trying to do a Spark tutorial that comes with the Cloudera Virtual Machine. But even though I'm using the correct line-ending encoding, I can not execute the scripts, because I get tons of errors. The tutorial is part of the Coursera Introduction to Big Data Analytics course. The assignment can be found here.

So here's what I did. Install the IPython shell (if not yet done):

sudo easy_install ipython==1.2.1

Open/Start the shell (either with 1.2.0 or 1.4.0):

PYSPARK_DRIVER_PYTHON=ipython pyspark --packages com.databricks:spark-csv_2.10:1.2.0

Set the line-endings to windows style. This is because the file is in windows-encoding and it's said in the course to do so. If you don't do this, you'll get other errors.

sc._jsc.hadoopConfiguration().set('textinputformat.record.delimiter','\r\n')

Trying to load the CSV file:

yelp_df = sqlCtx.load(source='com.databricks.spark.csv',header = 'true',inferSchema = 'true',path = 'file:///usr/lib/hue/apps/search/examples/collections/solr_configs_yelp_demo/index_data.csv')

But getting a very long list of errors, which starts like this:

Py4JJavaError: An error occurred while calling o23.load.: java.lang.RuntimeException: 
Unable to instantiate 
org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient at 
org.apache.hadoop.hive.ql.session.SessionState.start(SessionState.java:472)

The full error message can be seen here. And this is the /etc/hive/conf/hive-site.xml

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>

<configuration>

  <!-- Hive Configuration can either be stored in this file or in the hadoop configuration files  -->
  <!-- that are implied by Hadoop setup variables.                                                -->
  <!-- Aside from Hadoop setup variables - this file is provided as a convenience so that Hive    -->
  <!-- users do not have to edit hadoop configuration files (that may be managed as a centralized -->
  <!-- resource).                                                                                 -->

  <!-- Hive Execution Parameters -->

  <property>
    <name>javax.jdo.option.ConnectionURL</name>
    <value>jdbc:mysql://127.0.0.1/metastore?createDatabaseIfNotExist=true</value>
    <description>JDBC connect string for a JDBC metastore</description>
  </property>

  <property>
    <name>javax.jdo.option.ConnectionDriverName</name>
    <value>com.mysql.jdbc.Driver</value>
    <description>Driver class name for a JDBC metastore</description>
  </property>

  <property>
    <name>javax.jdo.option.ConnectionUserName</name>
    <value>hive</value>
  </property>

  <property>
    <name>javax.jdo.option.ConnectionPassword</name>
    <value>cloudera</value>
  </property>

  <property>
    <name>hive.hwi.war.file</name>
    <value>/usr/lib/hive/lib/hive-hwi-0.8.1-cdh4.0.0.jar</value>
    <description>This is the WAR file with the jsp content for Hive Web Interface</description>
  </property>

  <property>
    <name>datanucleus.fixedDatastore</name>
    <value>true</value>
  </property>

  <property>
    <name>datanucleus.autoCreateSchema</name>
    <value>false</value>
  </property>

  <property>
    <name>hive.metastore.uris</name>
    <value>thrift://127.0.0.1:9083</value>
    <description>IP address (or fully-qualified domain name) and port of the metastore host</description>
  </property>
</configuration>

Any help or idea how to solve that? I guess it's a pretty common error. But I couldn't find any solution, yet.

One more thing: is there a way to dump such long error messages into a separate log-file?

4

2 回答 2

0

讨论总结:执行以下命令解决了这个问题:

sudo cp /etc/hive/conf.dist/hive-site.xml /usr/lib/spark/conf/

有关更多信息,请参阅https://www.coursera.org/learn/bigdata-analytics/supplement/tyH3p/setup-pyspark-for-dataframes

于 2016-05-02T10:58:55.777 回答
0

似乎有两个问题。首先,hive-metastore 在某些情况下是离线的。其次,无法推断模式。因此,我手动创建了一个模式,并在加载 CSV 文件时将其添加为参数。无论如何,我很想知道这是否适用于 schemaInfer=true。

这是我的手动定义模式的版本。因此,请确保 hive 已启动:

sudo service hive-metastore restart

然后,查看 CSV 文件的第一部分以了解其结构。我使用了这个命令行:

head /usr/lib/hue/apps/search/examples/collections/solr_configs_yelp_demo/index_data.csv

现在,打开 python shell。请参阅原始帖子以了解如何执行此操作。然后定义架构:

from pyspark.sql.types import *
schema = StructType([
    StructField("business_id", StringType(), True),
    StructField("cool", IntegerType(), True),
    StructField("date", StringType(), True),
    StructField("funny", IntegerType(), True),
    StructField("id", StringType(), True),
    StructField("stars", IntegerType(), True),
    StructField("text", StringType(), True),
    StructField("type", StringType(), True),
    StructField("useful", IntegerType(), True),
    StructField("user_id", StringType(), True),
    StructField("name", StringType(), True),
    StructField("full_address", StringType(), True),
    StructField("latitude", DoubleType(), True),
    StructField("longitude", DoubleType(), True),
    StructField("neighborhood", StringType(), True),
    StructField("open", StringType(), True),
    StructField("review_count", IntegerType(), True),
    StructField("state", StringType(), True)])

然后通过指定架构来加载 CSV 文件。请注意,无需设置 windows 行尾:

yelp_df = sqlCtx.load(source='com.databricks.spark.csv',
header = 'true',
schema = schema,
path = 'file:///usr/lib/hue/apps/search/examples/collections/solr_configs_yelp_demo/index_data.csv')

在数据集上执行的任何方法的结果。我试着计数,效果很好。

yelp_df.count()

感谢@yaron 的帮助,我们可以弄清楚如何使用 inferSchema 加载 CSV。首先,您必须正确设置 hive-metastore:

sudo cp /etc/hive/conf.dist/hive-site.xml /usr/lib/spark/conf/

然后,启动 Python shell 并且不要将行尾更改为 Windows 编码。请记住,更改是持久的(会话不变)。因此,如果您之前将其更改为 Windows 样式,则需要将其重置为 '\n'。然后加载 CSV 文件,并将 inferSchema 设置为 true:

yelp_df = sqlCtx.load(source='com.databricks.spark.csv',
header = 'true',
inferSchema = 'true',
path = 'file:///usr/lib/hue/apps/search/examples/collections/solr_configs_yelp_demo/index_data.csv')
于 2016-05-01T21:24:12.617 回答