scala - 从 Scala (shark-shell) 访问 Shark 表 (Hive)

标签 scala hive apache-spark shark-sql

我有 shark-0.8.0,它在 hive-0.9.0 上运行。我可以通过调用 shark 在 Hive 上编程。我创建了几个表并加载了数据。

现在,我正在尝试使用 Scala 访问这些表中的数据。我使用 shark-shell 调用了 Scala shell。但是当我尝试选择时,我得到一个错误,指出该表不存在。

scala> val artists = sc.sql2rdd("select artist from default.lastfm")

Hive history file=/tmp/hduser2/hive_job_log_hduser2_201405091617_1513149542.txt
151.738: [GC 317312K->83626K(1005568K), 0.0975990 secs]
151.836: [Full GC 83626K->76005K(1005568K), 0.4523880 secs]
152.313: [GC 80536K->76140K(1005568K), 0.0030990 secs]
152.316: [Full GC 76140K->62214K(1005568K), 0.1716240 secs]
FAILED: Error in semantic analysis: Line 1:19 Table not found 'lastfm'
shark.api.QueryExecutionException: FAILED: Error in semantic analysis: Line 1:19 Table not found 'lastfm'
    at shark.SharkDriver.tableRdd(SharkDriver.scala:149)
    at shark.SharkContext.sql2rdd(SharkContext.scala:100)
    at <init>(<console>:17)
    at <init>(<console>:22)
    at <init>(<console>:24)
    at <init>(<console>:26)
    at <init>(<console>:28)
    at <init>(<console>:30)
    at <init>(<console>:32)
    at .<init>(<console>:36)
    at .<clinit>(<console>)
    at .<init>(<console>:11)
    at .<clinit>(<console>)
    at $export(<console>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.spark.repl.SparkIMain$ReadEvalPrint.call(SparkIMain.scala:629)
    at org.apache.spark.repl.SparkIMain$Request$$anonfun$10.apply(SparkIMain.scala:890)
    at scala.tools.nsc.interpreter.Line$$anonfun$1.apply$mcV$sp(Line.scala:43)
    at scala.tools.nsc.io.package$$anon$2.run(package.scala:25)
    at java.lang.Thread.run(Thread.java:744)

根据文档 (https://github.com/amplab/shark/wiki/Shark-User-Guide),这些步骤足以启动并运行 Shark 并使用 Scala 选择数据。或者我错过了什么?是否需要修改某些配置文件才能从 shark-shell 访问 Shark?

最佳答案

您是否更新了 shark-hive 目录配置以正确反射(reflect) hive metastore jdbc 连接信息?

您需要将 hive-default.xml 复制到 hive-site.xml 。然后确保已设置 Metastore 属性。

这里是hive-site.xml中的基本信息

<property>
  <name>javax.jdo.option.ConnectionURL</name>
  <value>jdbc:mysql://myhost/metastore</value>
  <description>the URL of the MySQL database</description>
</property>

<property>
  <name>javax.jdo.option.ConnectionDriverName</name>
  <value>com.mysql.jdbc.Driver</value>
</property>

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

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

您可以在此处获得更多详细信息:configuring hive metastore

关于scala - 从 Scala (shark-shell) 访问 Shark 表 (Hive),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23565853/

相关文章:

java - 使用Scala获取底层的JSON数据

sql - Hive 在简单的选择查询中不返回任何结果

hadoop - 是否可以计算分区的数量?

python - Apache-Spark 如何与类中的方法一起工作

scala - 如何将一组 RelationalGroupedDataset 传递给函数?

scala - 向 Apache Spark 的抽象 Evaluator 类添加参数

scala - 玩 2 Scala : Adding a description attribute to this model

scala - 编译错误 : not found: value nonEmptyText in Play framework while using Scala

join - Hive Sort 合并桶加入

java - Cassandra 和 Spark : can I add an item to a row to create a dataframe from a list of Rows