首页 > 解决方案 > 从 Hive 到 Druid 交互时出错

问题描述

我正在尝试从 Hive 创建一个 Druid 数据源,并且我正在使用表 Hive。

首先,我创建了一个数据库 Hive:database_hive然后,我在这个数据库中创建了一个表。

CREATE TABLE database_hive.hive_table (
    timemachine int,
    userId String,
    lang String,
    location String,
    name String,
    network String,
    posted String,
    sentiment String,
    text String,
);

第二次,我试图hive_table在 Druid 上创建一个新的数据源。

SET hive.druid.broker.address.default = 10.1.123.30:8082; --fake ip for example
SET hive.druid.metadata.username = druid;
SET hive.druid.metadata.password = druidpassword;
SET hive.druid.metadata.db.type = derby;
SET hive.druid.metadata.uri = jdbc:mysql://10.1.123.30:3306/druid?createDatabaseIfNoExist=true;

CREATE TABLE druid_table
STORED BY 'org.apache.hadoop.hive.druid.DruidStorageHandler'
TBLPROPERTIES (
    "druid.segment.granularity" = "MONTH",
    "druid.query.granularity" = "DAY")
    AS
    SELECT
    cast(timemachine as timestamp) as `__time`,   
    cast(userId as string) userId,
    cast(lang as string) lang,
    cast(location as string) location,
    cast(name as string) name,
    cast(network as string) network,
    cast(posted as string) posted,
    cast(sentiment as string) sentiment,
    cast(text as string) text
    FROM hive_table
;

此查询返回一个错误:

Error: Error while processing statement: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. org.skife.jdbi.v2.exceptions.UnableToObtainConnectionException: java.sql.SQLException: Cannot create JDBC driver of class 'org.apache.derby.jdbc.ClientDriver' for connect URL 'jdbc:mysql://10.1.123.30:3306/druid?createDatabaseIfNoExist=true' (state=08S01,code=1)

在我的 Hive 存储库中,mysql-connector-java.jar我不明白问题出在哪里。我尝试了一些关于其他主题的建议,但没有找到解决方案。有人有建议吗?

感谢帮助 !

标签: hadoophivehortonworks-data-platformdruid

解决方案


问题出在您的 Druid 元数据数据库配置中。Hive 需要访问 Druid 用来存储所有元数据的关系数据库。可以derby在 Druid 端设置,但是 Derby 就像 SQLite,所以不能被 Hive 访问。因此,Hive 不允许derby作为hive.druid.metadata.db.type属性的有效参数。唯一允许的是mysqlpostgresql

因此,要解决此问题,您需要:

  • 确保您的 Druid 集群使用 MySQL 或 PSQL 进行元数据存储
  • 设置hive.druid.metadata.db.type为正确的数据库类型
  • 设置hive.druid.metadata.uri为正确的数据库 url

推荐阅读