首页 > 解决方案 > 如何远程使用 Spark 将数据写入配置单元表?

问题描述

我是hadoop世界的新手。我已经在我的 windows 机器上安装了 spark 2.3.1,并在同一台机器的 vm 中安装了 cloudera。我正在使用 spark shell 以数据框的形式进行一些数据转换。现在我想把这些数据放到cloudera中使用spark的hive中。我已经用谷歌搜索并执行了以下步骤。

1) 复制 /etc/hive/conf 中的所有文件并粘贴到我的 windows 中的 spark/conf 中。

2) 在 windows spark/conf 中打开“hive-site.xml”并更改属性如下。

<configuration>
  <property>
    <name>hive.metastore.uris</name>
    <value>thrift://MyclouderaIP:9083</value>
  </property>
  <property>

3) 将主机条目放入窗口系统 C:\Windows\System32\drivers\etc\hosts

示例:MyclouderaIP quickstart.cloudera

4)在cloudera vm中打开“/etc/hive/conf/hdfs-site.xml”并改变如下属性

<property>
    <name>dfs.client.use.datanode.hostname</name>
    <value>true</value>
  </property>

完成所有步骤后,我面临以下问题。

scala> val Main = sc.textFile("D:\\Windows\\CompanyData.txt")

scala> Main.collect

错误 :

java.lang.IllegalArgumentException: Pathname /D:/Windows/CompanyData.txt from hdfs://quickstart.cloudera:8020/D:/Windows/CompanyData.txt is not a valid DFS filename.
  at org.apache.hadoop.hdfs.DistributedFileSystem.getPathName(DistributedFileSystem.java:197)
  at org.apache.hadoop.hdfs.DistributedFileSystem.access$000(DistributedFileSystem.java:106)
  at org.apache.hadoop.hdfs.DistributedFileSystem$22.doCall(DistributedFileSystem.java:1305)
  at org.apache.hadoop.hdfs.DistributedFileSystem$22.doCall(DistributedFileSystem.java:1301)
  at org.apache.hadoop.fs.FileSystemLinkResolver.resolve(FileSystemLinkResolver.java:81)
  at org.apache.hadoop.hdfs.DistributedFileSystem.getFileStatus(DistributedFileSystem.java:1317)

我已经从 spark/conf 中删除了“core-site.xml”,它可以在 windows 中读取文本文件。但是 saprk 在插入记录时无法与 cloudera 通信。

scala> import org.apache.spark.sql.hive.HiveContext
scala> val sqlContext = new org.apache.spark.sql.hive.HiveContext(sc)
scala> sqlContext.sql("insert into TestTable select 1")

错误:

org.apache.hadoop.ipc.RemoteException(java.io.IOException): 
File /user/hive/warehouse/TestTable/.hive-staging_hive_2018-10-17_00-03-48_369_2112774544260501723-1/-ext-10000/_temporary/0/_temporary/attempt_20181017000351_0000_m_000000_0/part-00000-8fcba81b-8a51-48a6-9c47-ac5f1c9dafdb-c000 
could only be replicated to 0 nodes instead of minReplication (=1).  
There are 1 datanode(s) running and 1 node(s) are excluded in this operation.

请有人帮助我。

标签: apache-sparkhadoophiveapache-spark-sql

解决方案


推荐阅读