1 问题产生背景
更换hive客户端还使用原先的关系型数据库(我用的是mysql)的metastore。
2 报错信息
Error: Error while compiling statement: FAILED: SemanticException Unable to fetch table emp.
Exception thrown when executing query :
SELECT DISTINCT 'org.apache.hadoop.hive.metastore.model.MTable' AS
`NUCLEUS_TYPE`,`A0`.`CREATE_TIME`,`A0`.`LAST_ACCESS_TIME`,`A0`.`OWNER`,`A0`.`RETENTION`,
`A0`.`IS_REWRITE_ENABLED`,`A0`.`TBL_NAME`,`A0`.`TBL_TYPE`,`A0`.`TBL_ID`
FROM `TBLS` `A0` LEFT OUTER JOIN `DBS` `B0` ON `A0`.`DB_ID` = `B0`.`DB_ID`
WHERE `A0`.`TBL_NAME` = ? AND `B0`.`NAME` = ? (state=42000,code=40000)
3 分析问题
网上能查到类似的问题很少,只好自己想办法了。
乍一看报错信息中最后是一个关系型数据库的查询语句,就把它复制出来到mysql的元数据库下执行,问号?改成具体的表名和字段名(到元数据库的TBLS
表和DBS
查看),比如我的:
SELECT
DISTINCT 'org.apache.hadoop.hive.metastore.model.MTable'
AS `NUCLEUS_TYPE`,
`A0`.`CREATE_TIME`,
`A0`.`LAST_ACCESS_TIME`,
`A0`.`OWNER`,
`A0`.`RETENTION`,
`A0`.`IS_REWRITE_ENABLED`,
`A0`.`TBL_NAME`,
`A0`.`TBL_TYPE`,
`A0`.`TBL_ID`
FROM `TBLS` `A0`
LEFT OUTER JOIN `DBS` `B0` ON `A0`.`DB_ID` = `B0`.`DB_ID`
WHERE `A0`.`TBL_NAME` = 'student' AND `B0`.`NAME` = 'default'
执行有报错:
org.jkiss.dbeaver.model.sql.DBSQLException: SQL 错误 [1054] [42S22]: Unknown column 'A0.IS_REWRITE_ENABLED' in 'field list'
at org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCStatementImpl.executeStatement(JDBCStatementImpl.java:133)
at org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob.executeStatement(SQLQueryJob.java:509)
at org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob.lambda$0(SQLQueryJob.java:440)
at org.jkiss.dbeaver.model.exec.DBExecUtils.tryExecuteRecover(DBExecUtils.java:168)
at org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob.executeSingleQuery(SQLQueryJob.java:427)
at org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob.extractData(SQLQueryJob.java:812)
at org.jkiss.dbeaver.ui.editors.sql.SQLEditor$QueryResultsContainer.readData(SQLEditor.java:3226)
at org.jkiss.dbeaver.ui.controls.resultset.ResultSetJobDataRead.lambda$0(ResultSetJobDataRead.java:118)
at org.jkiss.dbeaver.model.exec.DBExecUtils.tryExecuteRecover(DBExecUtils.java:168)
at org.jkiss.dbeaver.ui.controls.resultset.ResultSetJobDataRead.run(ResultSetJobDataRead.java:116)
at org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer$ResultSetDataPumpJob.run(ResultSetViewer.java:4516)
at org.jkiss.dbeaver.model.runtime.AbstractJob.run(AbstractJob.java:105)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: java.sql.SQLSyntaxErrorException: Unknown column 'A0.IS_REWRITE_ENABLED' in 'field list'
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.StatementImpl.executeInternal(StatementImpl.java:764)
at com.mysql.cj.jdbc.StatementImpl.execute(StatementImpl.java:648)
at org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCStatementImpl.execute(JDBCStatementImpl.java:327)
at org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCStatementImpl.executeStatement(JDBCStatementImpl.java:130)
... 12 more
报错信息大概意思是说这个表TBLS
的IS_REWRITE_ENABLED
列不存在,把这个字段注释掉就能正常运行了。但是这个问题没法解决呀,因为hive元数据库里的表都是hive自动生成的,最好别改。
4 解决问题
既然更换hive客户端那就重新建一个元数据库吧,名字可以自己起,那就叫metastore2
吧,在hive解压后的conf文件夹下的hive-site.xml中修改javax.jdo.option.ConnectionURL
、hive.metastore.warehouse.dir
即可。下面是我的配置信息仅供参考:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://cts111:3306/metastore2?createDatabaseIfNotExist=true&useSSL=false</value>
<description>JDBC connect string for a JDBC metastore</description>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
<description>Driver class name for a JDBC metastore</description>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
<description>username to use against metastore database</description>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>mysql123</value>
<description>password to use against metastore database</description>
</property>
<!-- hue配置 -->
<property>
<name>hive.server2.thrift.port</name>
<value>10000</value>
<description>TCP 的监听端口</description>
</property>
<property>
<name>hive.server2.thrift.bind.host</name>
<value>192.168.1.111</value>
<description>TCP绑定的主机</description>
</property>
<property>
<name>hive.server2.long.polling.timeout</name>
<value>5000</value>
<description>HiveServer2在响应使用长轮询的异步调用之前等待的时间(毫秒)</description>
</property>
<!-- 如果使用了下面这个配置得先启动metastore,否则hiveserver2会报错跑不起来 -->
<property>
<name>hive.metastore.uris</name>
<value>thrift://192.168.1.111:9083</value>
<description>指向的是运行metastore服务的主机</description>
</property>
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse2</value>
</property>
<property>
<name>hive.cli.print.current.db</name>
<value>true</value>
<description>
Whether to include the current database in the Hive prompt.
</description>
</property>
<property>
<name>hive.cli.print.header</name>
<value>true</value>
<description>
Whether to print the names of the columns in query output.
</description>
</property>
<!-- 关闭元数据检查 -->
<property>
<name>hive.metastore.schema.verification</name>
<value>false</value>
</property>
<!-- tez -->
<property>
<name>hive.execution.engine</name>
<value>tez</value>
</property>
<!-- 解决hive配置tez后查询一直pending的问题 默认是-1 -->
<property>
<name>hive.tez.cpu.vcores</name>
<value>1</value>
<description>
https://cwiki.apache.org/confluence/display/Hive/Configuration+Properties
</description>
</property>
<!-- 为了tez稳定运行的可选设置 -->
<property>
<name>hive.tez.container.size</name>
<value>1024</value>
</property>
<property>
<name>hive.prewarm.enabled</name>
<value>true</value>
</property>
<!--配置hive默认的提交队列,在capacity-scheduler.xml中设置了-->
<property>
<name>mapreduce.job.queuename</name>
<value>hive</value>
</property>
<!--配置tez默认的提交队列,在capacity-scheduler.xml中设置了-->
<property>
<name>tez.queue.name</name>
<value>hive</value>
</property>
</configuration>
hive-site.xml
的配置文件一定要根据自己的实际情况做剪裁,自己的环境跟别人的可能不一样,如果是刚安装hive测试运行只要配置前四个基本的四大件就好。