spring phoenix结合操作hbase

参考网址:https://www.cnblogs.com/MOBIN/p/5234816.html
发生错误的原因:主要是url写错,按照推荐的url地址为jdbc:phoenix:zookeeper安装地址:2181,后面应该加上具体的hbase安装路径,如/hbase-unsecure
1,报错如下:
org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (ERROR 103 (08004): Unable to establish connection.)
 at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
 at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:394)
 at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:445)
 at zmap.dao.phoenix.impl.PhoenixBaseDaoImpl.createHbaseView(PhoenixBaseDaoImpl.java:72)
 at zmap.dao.phoenix.impl.PhoenixBaseDaoImpl.main(PhoenixBaseDaoImpl.java:83)
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (ERROR 103 (08004): Unable to establish connection.)
 at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
 at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
 at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
 at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
 at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
 ... 4 more
Caused by: java.sql.SQLException: ERROR 103 (08004): Unable to establish connection.
 at org.apache.phoenix.exception.SQLExceptionCode$Factory$1.newException(SQLExceptionCode.java:441)
 at org.apache.phoenix.exception.SQLExceptionInfo.buildException(SQLExceptionInfo.java:145)
 at org.apache.phoenix.query.ConnectionQueryServicesImpl.openConnection(ConnectionQueryServicesImpl.java:391)
 at org.apache.phoenix.query.ConnectionQueryServicesImpl.access$300(ConnectionQueryServicesImpl.java:217)
 at org.apache.phoenix.query.ConnectionQueryServicesImpl$13.call(ConnectionQueryServicesImpl.java:2348)
 at org.apache.phoenix.query.ConnectionQueryServicesImpl$13.call(ConnectionQueryServicesImpl.java:2327)
 at org.apache.phoenix.util.PhoenixContextExecutor.call(PhoenixContextExecutor.java:78)
 at org.apache.phoenix.query.ConnectionQueryServicesImpl.init(ConnectionQueryServicesImpl.java:2327)
 at org.apache.phoenix.jdbc.PhoenixDriver.getConnectionQueryServices(PhoenixDriver.java:233)
 at org.apache.phoenix.jdbc.PhoenixEmbeddedDriver.createConnection(PhoenixEmbeddedDriver.java:142)
 at org.apache.phoenix.jdbc.PhoenixDriver.connect(PhoenixDriver.java:202)
 at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
 at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
 at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556)
 at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545)
 ... 8 more
Caused by: java.io.IOException: java.lang.reflect.InvocationTargetException
 at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java:240)
 at org.apache.hadoop.hbase.client.ConnectionManager.createConnection(ConnectionManager.java:427)
 at org.apache.hadoop.hbase.client.ConnectionManager.createConnectionInternal(ConnectionManager.java:336)
 at org.apache.hadoop.hbase.client.HConnectionManager.createConnection(HConnectionManager.java:144)
 at org.apache.phoenix.query.HConnectionFactory$HConnectionFactoryImpl.createConnection(HConnectionFactory.java:47)
 at org.apache.phoenix.query.ConnectionQueryServicesImpl.openConnection(ConnectionQueryServicesImpl.java:389)
 ... 20 more
Caused by: java.lang.reflect.InvocationTargetException
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
 at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
 at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java:238)
 ... 25 more
Caused by: java.lang.IllegalArgumentException: A HostProvider may not be empty!
 at org.apache.zookeeper.client.StaticHostProvider.(StaticHostProvider.java:63)
 at org.apache.zookeeper.ZooKeeper.(ZooKeeper.java:445)
 at org.apache.zookeeper.ZooKeeper.(ZooKeeper.java:380)
 at org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper.checkZk(RecoverableZooKeeper.java:141)
 at org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper.exists(RecoverableZooKeeper.java:221)
 at org.apache.hadoop.hbase.zookeeper.ZKUtil.checkExists(ZKUtil.java:418)
 at org.apache.hadoop.hbase.zookeeper.ZKClusterId.readClusterIdZNode(ZKClusterId.java:65)
 at org.apache.hadoop.hbase.client.ZooKeeperRegistry.getClusterId(ZooKeeperRegistry.java:105)
 at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.retrieveClusterId(ConnectionManager.java:886)
 at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.(ConnectionManager.java:642)
 ... 30 more

2,错误如下

 
  
Caused by: java.sql.SQLException: ERROR 726 (43M10):  Inconsistent namespace mapping properites.. Cannot initiate connection as SYSTEM:CATALOG is found but client does not have phoenix.schema.isNamespaceMappingEnabled enabled
 at org.apache.phoenix.exception.SQLExceptionCode$Factory$1.newException(SQLExceptionCode.java:441)
 at org.apache.phoenix.exception.SQLExceptionInfo.buildException(SQLExceptionInfo.java:145)
 at org.apache.phoenix.query.ConnectionQueryServicesImpl$13.call(ConnectionQueryServicesImpl.java:2367)
 at org.apache.phoenix.query.ConnectionQueryServicesImpl$13.call(ConnectionQueryServicesImpl.java:2327)
 at org.apache.phoenix.util.PhoenixContextExecutor.call(PhoenixContextExecutor.java:78)
 at org.apache.phoenix.query.ConnectionQueryServicesImpl.init(ConnectionQueryServicesImpl.java:2327)
 at org.apache.phoenix.jdbc.PhoenixDriver.getConnectionQueryServices(PhoenixDriver.java:233)
 at org.apache.phoenix.jdbc.PhoenixEmbeddedDriver.createConnection(PhoenixEmbeddedDriver.java:142)
 at org.apache.phoenix.jdbc.PhoenixDriver.connect(PhoenixDriver.java:202)
 at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
 at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
 at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556)
 at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545)
 ... 39 more
设置如下:
hbConfig.set("phoenix.schema.isNamespaceMappingEnabled","true");
hbConfig.set("phoenix.schema.mapSystemTablesToNamespace ","true");
即可

3,错误如下

java.lang.ClassCastException: java.util.ArrayList cannot be cast to org.apache.phoenix.schema.types.PhoenixArray
 at org.apache.phoenix.schema.types.PDataType.fromLiteral(PDataType.java:1143)
 at org.apache.phoenix.expression.LiteralExpression.newConstant(LiteralExpression.java:133)
 at org.apache.phoenix.compile.ExpressionCompiler.visit(ExpressionCompiler.java:428)
 at org.apache.phoenix.compile.ExpressionCompiler.visit(ExpressionCompiler.java:141)
 at org.apache.phoenix.parse.BindParseNode.accept(BindParseNode.java:47)
 at org.apache.phoenix.parse.CompoundParseNode.acceptChildren(CompoundParseNode.java:64)
 at org.apache.phoenix.parse.ComparisonParseNode.accept(ComparisonParseNode.java:45)
 at org.apache.phoenix.compile.WhereCompiler.compile(WhereCompiler.java:130)
 at org.apache.phoenix.compile.WhereCompiler.compile(WhereCompiler.java:100)
 at org.apache.phoenix.compile.QueryCompiler.compileSingleFlatQuery(QueryCompiler.java:558)
 at org.apache.phoenix.compile.QueryCompiler.compileSingleQuery(QueryCompiler.java:510)
 at org.apache.phoenix.compile.QueryCompiler.compileSelect(QueryCompiler.java:205)
 at org.apache.phoenix.compile.QueryCompiler.compile(QueryCompiler.java:160)
 at org.apache.phoenix.compile.DeleteCompiler.compile(DeleteCompiler.java:368)
 at org.apache.phoenix.jdbc.PhoenixStatement$ExecutableDeleteStatement.compilePlan(PhoenixStatement.java:611)
 at org.apache.phoenix.jdbc.PhoenixStatement$ExecutableDeleteStatement.compilePlan(PhoenixStatement.java:599)
 at org.apache.phoenix.jdbc.PhoenixStatement$2.call(PhoenixStatement.java:336)
 at org.apache.phoenix.jdbc.PhoenixStatement$2.call(PhoenixStatement.java:331)
 at org.apache.phoenix.call.CallRunner.run(CallRunner.java:53)
 at org.apache.phoenix.jdbc.PhoenixStatement.executeMutation(PhoenixStatement.java:329)
 at org.apache.phoenix.jdbc.PhoenixPreparedStatement.executeUpdate(PhoenixPreparedStatement.java:199)
 at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
 at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
 at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:883)
 at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:876)
 at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:639)
 at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:876)
 at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:937)
 at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:947)
 at zmap.dao.phoenix.impl.PhoenixBaseDaoImpl.deleteHbaseDataByPhoenix(PhoenixBaseDaoImpl.java:234)
 at zmap.service.impl.ZmapServiceImpl.deleteHbaseDataByPhoenix(ZmapServiceImpl.java:116)
 at test.zmap.service.impl.ZmapServiceImplTest.testDeleteHbaseDataByPhoenix(ZmapServiceImplTest.java:136)
 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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
 at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
 at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
 at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
 at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
 at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
 at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
 at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
 at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
 at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
 at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
 at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
 at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
 at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
 at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
 at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
 at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
 at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
 at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
 at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
 at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
 at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
 at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
 at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
 at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
 at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

Process finished with exit code -1
将ArrayList转换成object数组即可,采用toArray()方法


 


你可能感兴趣的:(Hadoop开发)