Support Questions

Find answers, ask questions, and share your expertise

select count(*) command failing in Phoenix

avatar
Super Collaborator

the 'select * from emp' command works but if i execute the command 'select count(*) from emp' from a java api it fails. i am giving the code and the error below .

code

# cat  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 count(*) from emp");
        while (rst.next()) {
            System.out.println(rst.getString(1) + " " + rst.getString(2));
        }
        conn.commit();
    }
}

error

got connection
18/06/11 11:30:23 DEBUG jdbc.PhoenixStatement: Execute query: select count(*) from emp
18/06/11 11:30:23 DEBUG compile.FromCompiler: Re-resolved stale table EMP with seqNum 2 at timestamp 1522943831949 with 3 columns: [ID, 0 .FNAME, 0.LNAME]
18/06/11 11:30:23 DEBUG compile.FromCompiler: Re-resolved stale table LNAMEIDX with seqNum 0 at timestamp 1522943474697 with 2 columns: [ 0:LNAME, :ID]
18/06/11 11:30:23 DEBUG compile.FromCompiler: Re-resolved stale table EMP with seqNum 2 at timestamp 1522943831949 with 3 columns: [ID, 0 .FNAME, 0.LNAME]
18/06/11 11:30:23 DEBUG compile.FromCompiler: Re-resolved stale table LNAMEIDXCOVER with seqNum 0 at timestamp 1522943831949 with 3 colum ns: [0:LNAME, :ID, 0.0:FNAME]
18/06/11 11:30:23 DEBUG compile.FromCompiler: Re-resolved stale table EMP with seqNum 2 at timestamp 1522943831949 with 3 columns: [ID, 0 .FNAME, 0.LNAME]
18/06/11 11:30:23 DEBUG execute.BaseQueryPlan: Scan ready for iteration: {"loadColumnFamiliesOnDemand":null,"startRow":"","stopRow":"","b atch":-1,"cacheBlocks":true,"totalColumns":0,"maxResultSize":-1,"families":{},"caching":100,"maxVersions":1,"timeRange":[0,1528731024323] }
18/06/11 11:30:23 DEBUG ipc.AbstractRpcClient: Use SIMPLE authentication for service ClientService, sasl=false
18/06/11 11:30:23 DEBUG ipc.AbstractRpcClient: Connecting to hadoop4.tolls.dot.state.fl.us/10.100.44.18:16020
18/06/11 11:30:23 DEBUG execute.BaseQueryPlan: Iterator ready: UngroupedAggregatingResultIterator [hasRows=false, aggregators=org.apache. phoenix.expression.aggregator.ClientAggregators [1]:    0) COUNT(1)]
18/06/11 11:30:23 DEBUG jdbc.PhoenixStatement: Explain plan: CLIENT 1-CHUNK 0 ROWS 0 BYTES PARALLEL 1-WAY FULL SCAN OVER LNAMEIDX
    SERVER FILTER BY FIRST KEY ONLY
    SERVER AGGREGATE INTO SINGLE ROW
18/06/11 11:30:23 DEBUG iterate.BaseResultIterators: Getting iterators for ResultIterators [name=PARALLEL,id=57d408d6-987a-412f-8ace-2293 2851ed10,scans=[[{"loadColumnFamiliesOnDemand":null,"filter":"FirstKeyOnlyFilter","startRow":"","stopRow":"","batch":-1,"cacheBlocks":tru e,"totalColumns":1,"maxResultSize":-1,"families":{"0":["_0"]},"caching":100,"maxVersions":1,"timeRange":[0,1528731024323]}]]]
18/06/11 11:30:23 DEBUG iterate.ParallelIterators: Id: 57d408d6-987a-412f-8ace-22932851ed10, Time: 10ms, Scan: {"loadColumnFamiliesOnDema nd":null,"filter":"FirstKeyOnlyFilter","startRow":"","stopRow":"","batch":-1,"cacheBlocks":true,"totalColumns":1,"maxResultSize":2097152, "families":{"0":["_0"]},"caching":100,"maxVersions":1,"timeRange":[0,1528731024323]}
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
        at java.util.ArrayList.rangeCheck(ArrayList.java:653)
        at java.util.ArrayList.get(ArrayList.java:429)
        at java.util.Collections$UnmodifiableList.get(Collections.java:1309)
        at org.apache.phoenix.compile.RowProjector.getColumnProjector(RowProjector.java:167)
        at org.apache.phoenix.jdbc.PhoenixResultSet.getString(PhoenixResultSet.java:606)
        at phoenixTest.main(phoenixTest.java:14)
18/06/11 11:30:23 DEBUG util.ShutdownHookManager: ShutdownHookManger complete shutdown.
1 ACCEPTED SOLUTION

avatar
Super Guru

@Sami Ahmad,

When you run "select count(*) from emp" , the size of rst (ResultSet) will be only 1. So rst.getString(2) will give IndexOutOfBoundsException.

Remove rst.getString(2) when you run select count(*) from emp and it will work properly.

.

Please "Accept" the answer if this works for you.

.

-Aditya

View solution in original post

2 REPLIES 2

avatar
Super Guru

@Sami Ahmad,

When you run "select count(*) from emp" , the size of rst (ResultSet) will be only 1. So rst.getString(2) will give IndexOutOfBoundsException.

Remove rst.getString(2) when you run select count(*) from emp and it will work properly.

.

Please "Accept" the answer if this works for you.

.

-Aditya

avatar
Super Collaborator

yes that fixed the issue ..thanks a lot