在cloudera vm中读取教程csv文件时出现异常

ztmd8pv5  于 2021-05-29  发布在  Hadoop
关注(0)|答案(2)|浏览(346)

我正在尝试做一个cloudera虚拟机附带的spark教程。但是,即使我使用了正确的行尾编码,我也不能执行脚本,因为我得到了大量的错误。本教程是coursera大数据分析入门课程的一部分。作业可以在这里找到。
我就是这么做的。安装ipython外壳(如果尚未安装):

sudo easy_install ipython==1.2.1

打开/启动shell(使用1.2.0或1.4.0):

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

将线条端点设置为“窗样式”。这是因为该文件是windows编码的,并且在课程中说要这样做。如果你不这样做,你会得到其他错误。

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

正在尝试加载csv文件:

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')

但是得到一个很长的错误列表,它是这样开始的:

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)

完整的错误信息可以在这里看到。这是/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>

有什么办法解决这个问题吗?我想这是一个很常见的错误。但我还没找到解决办法。
还有一件事:有没有办法将这么长的错误消息转储到一个单独的日志文件中?

dgenwo3n

dgenwo3n1#

讨论摘要:执行以下命令解决了问题:

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 更多信息。

gmxoilav

gmxoilav2#

似乎有两个问题。首先,hive元存储在某些情况下处于脱机状态。第二,模式无法推断。因此,我手动创建了一个模式,并在加载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。首先,必须正确设置配置单元元存储:

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

然后,启动pythonshell,不要将行尾更改为windows编码。请记住,更改是持久的(会话不变)。因此,如果以前将其更改为windows样式,则需要将其重置为“\n”。然后加载inferschema设置为true的csv文件:

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')

相关问题