如何使用spark远程将数据写入配置单元表?

xj3cbfub  于 2021-06-01  发布在  Hadoop
关注(0)|答案(0)|浏览(232)

我是hadoop世界的新手。我已经在我的windows机器上安装了spark2.3.1,并在同一台机器上安装了cloudera-insidevm。我正在用sparkshell做一些Dataframe形式的数据转换。现在我想把这些数据放到hive中,hive在cloudera中使用spark。我在google上搜索了一下,并做了以下步骤。
1) 复制了/etc/hive/conf中的所有文件并粘贴到我的windows中的spark/conf。
2) 在windows spark/conf中打开“hive site.xml”并更改属性,如下所示。

  1. <configuration>
  2. <property>
  3. <name>hive.metastore.uris</name>
  4. <value>thrift://MyclouderaIP:9083</value>
  5. </property>
  6. <property>

3) 将主机条目放入windows系统c:\windows\system32\drivers\etc\hosts
示例:myclouderaip quickstart.cloudera
4) 在clouderavmopen“/etc/hive/conf/hdfs site.xml”中,更改如下属性

  1. <property>
  2. <name>dfs.client.use.datanode.hostname</name>
  3. <value>true</value>
  4. </property>

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

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

错误:

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

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

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

错误:

  1. org.apache.hadoop.ipc.RemoteException(java.io.IOException):
  2. 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
  3. could only be replicated to 0 nodes instead of minReplication (=1).
  4. There are 1 datanode(s) running and 1 node(s) are excluded in this operation.

有人能帮帮我吗。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题