Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

phoenix java API issues

Solved Go to solution

phoenix java API issues

Master Collaborator

I am trying to run a java code which queries a phoenix view but I am getting errors . The code and error results are shown below.

[root@hadoop1 ~]# more phoenixTest.java
import java.sql.*;
import java.util.*;
import org.apache.phoenix.jdbc.PhoenixDriver;
public class phoenixTest {
    public static void main(String args[]) throws Exception {
        Connection conn;
        Properties prop = new Properties();
        Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");
        conn =  DriverManager.getConnection("jdbc:phoenix:hadoop1:2181:/hbase-unsecure");
        System.out.println("got connection");
        ResultSet rst = conn.createStatement().executeQuery("select ufmid,list1,txntm from ufm");
        while (rst.next()) {
            System.out.println(rst.getString(1) + " " + rst.getString(2));
        }
        conn.commit();
    }
}






18/06/08 14:57:35 INFO zookeeper.ZooKeeper: Client environment:os.arch=amd64
18/06/08 14:57:35 INFO zookeeper.ZooKeeper: Client environment:os.version=2.6.32-642.6.2.el6.x86_64
18/06/08 14:57:35 INFO zookeeper.ZooKeeper: Client environment:user.name=root
18/06/08 14:57:35 INFO zookeeper.ZooKeeper: Client environment:user.home=/root
18/06/08 14:57:35 INFO zookeeper.ZooKeeper: Client environment:user.dir=/root
18/06/08 14:57:35 INFO zookeeper.ZooKeeper: Initiating client connection, connectString=hadoop1:2181 sessionTimeout=90000 watcher=org.apache.hadoop.hbase.zookeeper.PendingWatcher@740773a3
18/06/08 14:57:35 DEBUG zookeeper.ClientCnxn: zookeeper.disableAutoWatchReset is false
18/06/08 14:57:35 INFO zookeeper.ClientCnxn: Opening socket connection to server hadoop1.tolls.dot.state.fl.us/10.100.44.17:2181. Will not attempt to authenticate using SASL (unknown error)
18/06/08 14:57:35 INFO zookeeper.ClientCnxn: Socket connection established, initiating session, client: /10.100.44.17:57104, server: hadoop1.tolls.dot.state.fl.us/10.100.44.17:2181
18/06/08 14:57:35 DEBUG zookeeper.ClientCnxn: Session establishment request sent on hadoop1.tolls.dot.state.fl.us/10.100.44.17:2181
18/06/08 14:57:35 INFO zookeeper.ClientCnxn: Session establishment complete on server hadoop1.tolls.dot.state.fl.us/10.100.44.17:2181, sessionid = 0x163891d95120b6f, negotiated timeout = 60000
18/06/08 14:57:35 DEBUG zookeeper.ZooKeeperWatcher: hconnection-0x2e3774000x0, quorum=hadoop1:2181, baseZNode=/hbase-unsecure Received ZooKeeper Event, type=None, state=SyncConnected, path=null
18/06/08 14:57:35 DEBUG zookeeper.ZooKeeperWatcher: hconnection-0x2e377400-0x163891d95120b6f connected
18/06/08 14:57:35 DEBUG zookeeper.ClientCnxn: Reading reply sessionid:0x163891d95120b6f, packet:: clientPath:null serverPath:null finished:false header:: 1,3  replyHeader:: 1,8595902057,0  request:: '/hbase-unsecure/hbaseid,F  response:: s{4294967631,8590066278,1522792678572,1522935216432,4,0,0,0,67,0,4294967631}
18/06/08 14:57:35 DEBUG zookeeper.ClientCnxn: Reading reply sessionid:0x163891d95120b6f, packet:: clientPath:null serverPath:null finished:false header:: 2,4  replyHeader:: 2,8595902057,0  request:: '/hbase-unsecure/hbaseid,F  response:: #ffffffff000146d61737465723a3136303030ffffff8bffffff92ffffff8f343cffffffb1fffffff75a50425546a2431393337393739322d626566622d343261372d613061352d653161323939323037343330,s{4294967631,8590066278,1522792678572,1522935216432,4,0,0,0,67,0,4294967631}
18/06/08 14:57:36 DEBUG ipc.AbstractRpcClient: Codec=org.apache.hadoop.hbase.codec.KeyValueCodec@28b46423, compressor=null, tcpKeepAlive=true, tcpNoDelay=true, connectTO=10000, readTO=20000, writeTO=60000, minIdleTimeBeforeClose=120000, maxRetries=0, fallbackAllowed=false, bind address=null
18/06/08 14:57:36 WARN util.Tracing: Tracing will outputs will not be written to any metrics sink! No TraceMetricsSink found on the classpath
java.lang.RuntimeException: Could not create  interface org.apache.phoenix.trace.PhoenixSpanReceiver Is the hadoop compatibility jar on the classpath?
        at org.apache.hadoop.hbase.CompatibilityFactory.getInstance(CompatibilityFactory.java:60)
        at org.apache.phoenix.trace.TracingCompat.newTraceMetricSource(TracingCompat.java:40)
        at org.apache.phoenix.trace.util.Tracing.addTraceMetricsSource(Tracing.java:294)
        at org.apache.phoenix.jdbc.PhoenixConnection.<clinit>(PhoenixConnection.java:125)
        at org.apache.phoenix.query.ConnectionQueryServicesImpl$9.call(ConnectionQueryServicesImpl.java:1516)
        at org.apache.phoenix.query.ConnectionQueryServicesImpl$9.call(ConnectionQueryServicesImpl.java:1489)

1 ACCEPTED SOLUTION

Accepted Solutions

Re: phoenix java API issues

Master Collaborator

i fixed this issue by copying htrace-core-2.04.jar file in the $HBASE_HOME/lib folder.

8 REPLIES 8

Re: phoenix java API issues

Master Collaborator

as you see the connection is established it says but I don't see the "got connection" message that's posted in the code .

Highlighted

Re: phoenix java API issues

Have you enabled tracing?

Re: phoenix java API issues

Master Collaborator

how do I enable it ? you suggesting to enable tracing ?

Re: phoenix java API issues

No actually, I'm unable to find TracingCompat.java in our HDP 2.6.0 version, so curious how did you get it. Are you sure your java application is using the right dependency for Phoenix?

Re: phoenix java API issues

Super Guru

Do you have this in your pom?

>>>>>     <dependency>
>>>>>         <groupId>org.apache.phoenix</groupId>
>>>>>         <artifactId>phoenix-core</artifactId>
>>>>>         <version>4.1.0</version>
>>>>>     </dependency>

Re: phoenix java API issues

Master Collaborator

do you mean put this in pom if already not there before compiling ? I don't get error compiling , I am getting run time error.

also where can I find this pom file ?

Re: phoenix java API issues

Super Guru

I recommend you take a look at building a uber jar. This will allow you to solve classpath issues where dependencies are not found.

Re: phoenix java API issues

Master Collaborator

i fixed this issue by copying htrace-core-2.04.jar file in the $HBASE_HOME/lib folder.