- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我是 spark 的新手。我正在尝试开发一个使用 Spark 1.6 将 json 数据保存到 Hive 表的应用程序。这是我的代码:
val rdd = sc.parallelize(Seq(arr.toString)) //arr is the Json array
val dataframe = hiveContext.read.json(rdd)
dataframe.registerTempTable("RiskRecon_tmp")
hiveContext.sql("DROP TABLE IF EXISTS RiskRecon_TOES")
hiveContext.sql("CREATE TABLE RiskRecon_TOES as select * from RiskRecon_tmp")
当我运行它时,出现以下错误:
Exception in thread "main" java.lang.IllegalArgumentException: Wrong FS: file:/tmp/spark-2c2e53f5-6b5f-462a-afa2-53b8cf5e53f1/scratch_hive_2017-07-12_07-41-07_146_1120449530614050587-1, expected: hdfs://nameservice1
at org.apache.hadoop.fs.FileSystem.checkPath(FileSystem.java:660)
at org.apache.hadoop.fs.FileSystem.makeQualified(FileSystem.java:480)
at org.apache.hadoop.hive.ql.Context.getStagingDir(Context.java:229)
at org.apache.hadoop.hive.ql.Context.getExternalScratchDir(Context.java:359)
at org.apache.hadoop.hive.ql.Context.getExternalTmpPath(Context.java:437)
at org.apache.spark.sql.hive.execution.InsertIntoHiveTable.sideEffectResult$lzycompute(InsertIntoHiveTable.scala:132)
at org.apache.spark.sql.hive.execution.InsertIntoHiveTable.sideEffectResult(InsertIntoHiveTable.scala:127)
at org.apache.spark.sql.hive.execution.InsertIntoHiveTable.doExecute(InsertIntoHiveTable.scala:276)
at org.apache.spark.sql.execution.SparkPlan$$anonfun$execute$5.apply(SparkPlan.scala:132)
at org.apache.spark.sql.execution.SparkPlan$$anonfun$execute$5.apply(SparkPlan.scala:130)
at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:150)
at org.apache.spark.sql.execution.SparkPlan.execute(SparkPlan.scala:130)
at org.apache.spark.sql.execution.QueryExecution.toRdd$lzycompute(QueryExecution.scala:55)
at org.apache.spark.sql.execution.QueryExecution.toRdd(QueryExecution.scala:55)
at org.apache.spark.sql.hive.execution.CreateTableAsSelect.run(CreateTableAsSelect.scala:89)
at org.apache.spark.sql.execution.ExecutedCommand.sideEffectResult$lzycompute(commands.scala:58)
at org.apache.spark.sql.execution.ExecutedCommand.sideEffectResult(commands.scala:56)
at org.apache.spark.sql.execution.ExecutedCommand.doExecute(commands.scala:70)
at org.apache.spark.sql.execution.SparkPlan$$anonfun$execute$5.apply(SparkPlan.scala:132)
at org.apache.spark.sql.execution.SparkPlan$$anonfun$execute$5.apply(SparkPlan.scala:130)
at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:150)
at org.apache.spark.sql.execution.SparkPlan.execute(SparkPlan.scala:130)
at org.apache.spark.sql.execution.QueryExecution.toRdd$lzycompute(QueryExecution.scala:55)
at org.apache.spark.sql.execution.QueryExecution.toRdd(QueryExecution.scala:55)
at org.apache.spark.sql.DataFrame.<init>(DataFrame.scala:145)
at org.apache.spark.sql.DataFrame.<init>(DataFrame.scala:130)
at org.apache.spark.sql.DataFrame$.apply(DataFrame.scala:52)
at org.apache.spark.sql.SQLContext.sql(SQLContext.scala:817)
at test$.main(test.scala:25)
at test.main(test.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:731)
at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:181)
at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:206)
at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:121)
at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
它给了我 create table
语句的错误。
这个错误是什么意思?我这样做是正确的方式还是有更好的方法将数据框保存到表中?另外,如果这段代码有效,创建的表将是一个内部表?理想情况下,我需要一个外部表来存储我的数据。
如有任何帮助,我们将不胜感激。谢谢。
最佳答案
假设 df
包含存储为 dataframe
的 JSON 文件的数据:
val df = sqlContext.read.json(rdd)
然后您可以使用 saveAsTable
将其加载到您的配置单元表中。请注意,您要加载到的配置单元表应该已经存在于所需位置,因此您可以根据需要创建一个 EXTERNAL
表。并且您的 spark 用户有权将数据写入相应的文件夹。
df.write.mode("append").saveAsTable("database.table_name")
根据您的要求,您可以使用其他几种可用的写入模式,如 append
、overwrite
等。
关于java - 从数据帧 'java.lang.IllegalArgumentException: Wrong FS: file:/tmp/spark expected: hdfs://nameservice1' 创建 Hive 表时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45058246/
我正在尝试将我的Node.js项目迁移到Bun。我的项目在很多地方使用了‘fs’包。我发现了许多Bun迁移示例,它们将‘fs’包导入为‘node:FS’。但是,作为“文件系统”导入可以很好地工作,没有
我正在尝试将我的Node.js项目迁移到Bun。我的项目在很多地方使用了‘fs’包。我发现了许多Bun迁移示例,它们将‘fs’包导入为‘node:FS’。但是,作为“文件系统”导入可以很好地工作,没有
我正在使用 aws lambda。 我有一个 .p8 文件,用于发送 apns 通知。因为我不能使用相对或绝对路径,因为它没有服务器。我必须从 s3 url 读取它。为此我做了这个 let file
我相信以下所有命令都可用于将 hdfs 文件复制到本地文件系统。有什么区别/情境利弊。 (这里是 Hadoop 新手)。 hadoop fs -text /hdfs_dir/* >> /local_d
这是一个新手问题,但我有点困惑为什么需要 open 与 r 、 w 、 a 以及这些标志的所有变体。如果他/她想读取或写入文件而不是使用 open,难道不应该简单地使用 readFile 或 writ
我想在 JavaScript 中使用 import fs from 'fs'。这是一个示例: import fs from 'fs' var output = fs.readFileSync('som
我的公司正在执行 SVN 存储库迁移,我想避免两个存储库(目前都处于事件状态)之间的修订号重叠。 我的要求是将新存储库的修订强制为特定的修订号(例如:100.000)。 通过分析 FSFS 存储库,我
-put和-copyFromLocal被记录为相同,而大多数示例使用详细的变体-copyFromLocal。为什么? -get和-copyToLocal相同 最佳答案 copyFromLocal与pu
我正在调用 Google 云端硬盘的下载 API,然后我想使用 fs.writeFile 或 fs.writeFileSync 在本地写入下载的文件。这就是我正在做的事情: const wri
我正在学习一些教程,但无法理解为什么这一行“self.only_dirs.push(files[i]);”导致有关它“未定义”的错误。这肯定是一个变量范围问题,但我尝试过的都没有成功。我需要如何声明变
我是第一次尝试 phantomJS,我已经成功地从站点中提取了 som 数据,但是当我尝试将一些内容写入文件时,我收到错误:ReferenceError:找不到变量:fs 这是我的脚本 var pag
这是一个 Node 应用程序,运行 Express 服务器。我有一个包含文本文件的文件夹。我需要能够进入文件夹内的每个文件,并提取包含单词“SAVE”的行。 我被困在这一步了。 app.get('/l
我在 fs.chunks 中有 10 GB 的数据,我想删除不在 fs.files 上的所有文档。我已经删除了我不想要的 fs.files 中的每个条目,所以 fs.files 中的每个 id 都是我
我注意到官方 Node 文档对 fs.exists 的描述令人吃惊: "fs.exists() is an anachronism and exists only for historical rea
我用 require("fs").promises只是为了避免使用回调函数。 但是现在,我也想用fs.createReadstream使用 POST 请求附加文件。 我怎样才能做到这一点? 或者在这种
我正在使用 Electron 和 React 编写桌面应用程序。我想将一些信息存储在 JSON 文件中。我试过 web-fs 和 browserify-fs 来完成这个,但都没有按预期工作。我的设置如
其中哪一个更适合在 Node 服务器应用程序的文件管理器类型中处理文件读/写操作? 一个比另一个快吗?速度非常重要,因为该应用程序应该能够同时处理许多用户请求 最佳答案 流的独特之处在于,不是程序像传
我需要递归或不递归地遍历文件夹(给定 bool 参数)。我发现有 fs::recursive_directory_iterator() 和 fs::directory_iterator()。在 Jav
AFAICT,如果我正在编写一个库并使用 Promise.promisifyAll(fs);,这会修改 fs 模块(而不是返回修改后的复制)。因此,如果有人导入我的库,这也会对他们修改 fs 产生副作
我正在使用带有以下导入代码的 fs 模块 导入 fs = require('fs') 代码一直运行,直到在下面的 TypeScript 代码的第二行遇到此异常 const filePath = 'da
我是一名优秀的程序员,十分优秀!