cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Cathy Daw (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (CASSANDRA-2734) NPE running res.next() for a select statement
Date Thu, 02 Jun 2011 00:30:47 GMT

     [ https://issues.apache.org/jira/browse/CASSANDRA-2734?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Cathy Daw updated CASSANDRA-2734:
---------------------------------

    Description: 
*The following statement fails when used with a Statement or PreparedStatement*
{code}
res = stmt.executeQuery("SELECT bar FROM users");  
res.next();
{code}

*Error Message*
{code}
    [junit] Testcase: simpleSelect(com.datastax.cql.reproBugTest):	Caused an ERROR
    [junit] null
    [junit] java.lang.NullPointerException
    [junit] 	at org.apache.cassandra.cql.jdbc.ColumnDecoder.makeKeyColumn(ColumnDecoder.java:136)
    [junit] 	at org.apache.cassandra.cql.jdbc.CResultSet.next(CResultSet.java:388)
    [junit] 	at com.datastax.cql.reproBugTest.simpleSelect(reproBugTest.java:57)
    [junit] 
    [junit] 
    [junit] Test com.datastax.cql.reproBugTest FAILED
{code}


*Here is a quick repro.  Showing that res.next() works with other statements but not select.*
_Also notice that ResultSet.getMetaData().getColumnCount() always returns zero._  
_I noticed in the existing driver tests similar test cases, so not sure the issue._

*Steps to run script*
* you will need to drop this in your test directory
* change the package declaration
* ant test -Dtest.name=reproBugTest

{code}
package com.datastax.cql;

import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.junit.Test;

public class reproBugTest {
    
    @Test
    public void simpleSelect() throws Exception {   
        Connection connection = null;
        ResultSet res;
        Statement stmt;
        int colCount = 0;
        
        try {
            Class.forName("org.apache.cassandra.cql.jdbc.CassandraDriver");
            
            // Check create keyspace
            connection = DriverManager.getConnection("jdbc:cassandra:root/root@127.0.0.1:9160/default");
    
            stmt = connection.createStatement();

            try {
              System.out.println("Running DROP KS Statement");  
              res = stmt.executeQuery("DROP KEYSPACE ks1");  
              res.next();
              
              System.out.println("Running CREATE KS Statement");
              res = stmt.executeQuery("CREATE KEYSPACE ks1 with strategy_class =  'org.apache.cassandra.locator.SimpleStrategy'
and strategy_options:replication_factor=1");  
              res.next();

            } catch (SQLException e) {
                if (e.getMessage().startsWith("Keyspace does not exist")) 
                {
                    res = stmt.executeQuery("CREATE KEYSPACE ks1 with strategy_class =  'org.apache.cassandra.locator.SimpleStrategy'
and strategy_options:replication_factor=1");  
                } 
            }   
            connection.close();    
            
            // Run Test
            connection = DriverManager.getConnection("jdbc:cassandra:root/root@127.0.0.1:9160/ks1");
    
            stmt = connection.createStatement();

            System.out.print("Running CREATE CF Statement");
            res = stmt.executeQuery("CREATE COLUMNFAMILY users (KEY varchar PRIMARY KEY, password
varchar, gender varchar, session_token varchar, state varchar, birth_year bigint)");    
            colCount = res.getMetaData().getColumnCount();
            System.out.println(" -- Column Count: " + colCount); 
            res.next();
            
            System.out.print("Running INSERT Statement");
            res = stmt.executeQuery("INSERT INTO users (KEY, password) VALUES ('user1', 'ch@nge')");
 
            colCount = res.getMetaData().getColumnCount();
            System.out.println(" -- Column Count: " + colCount); 
            res.next();
            
            System.out.print("Running SELECT Statement");
            res = stmt.executeQuery("SELECT bar FROM users");  
            colCount = res.getMetaData().getColumnCount();
            System.out.println(" -- Column Count: " + colCount); 
            res.getRow();
            res.next();
                
            connection.close();               

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
       
}
{code}


  was:
*The following statement fails when used with a Statement or PreparedStatement*
{code}
res = stmt.executeQuery("SELECT bar FROM users");  
res.next();
{code}

*Error Message*
{code}
    [junit] Testcase: simpleSelect(com.datastax.cql.reproBugTest):	Caused an ERROR
    [junit] null
    [junit] java.lang.NullPointerException
    [junit] 	at org.apache.cassandra.cql.jdbc.ColumnDecoder.makeKeyColumn(ColumnDecoder.java:136)
    [junit] 	at org.apache.cassandra.cql.jdbc.CResultSet.next(CResultSet.java:388)
    [junit] 	at com.datastax.cql.reproBugTest.simpleSelect(reproBugTest.java:57)
    [junit] 
    [junit] 
    [junit] Test com.datastax.cql.reproBugTest FAILED
{code}


*Here is a quick repro.  Showing that res.next() works with other statements but not select.
 I noticed in the existing driver tests similar test cases, so not sure the issue.*
* you will need to drop this in your test directory
* change the package declaration
* ant test -Dtest.name=reproBugTest

{code}
package com.datastax.cql;

import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.junit.Test;

public class reproBugTest {
    
    @Test
    public void simpleSelect() throws Exception {   
        Connection connection = null;
        ResultSet res;
        Statement stmt;
        int colCount = 0;
        
        try {
            Class.forName("org.apache.cassandra.cql.jdbc.CassandraDriver");
            
            // Check create keyspace
            connection = DriverManager.getConnection("jdbc:cassandra:root/root@127.0.0.1:9160/default");
    
            stmt = connection.createStatement();

            try {
              System.out.println("Running DROP KS Statement");  
              res = stmt.executeQuery("DROP KEYSPACE ks1");  
              res.next();
              
              System.out.println("Running CREATE KS Statement");
              res = stmt.executeQuery("CREATE KEYSPACE ks1 with strategy_class =  'org.apache.cassandra.locator.SimpleStrategy'
and strategy_options:replication_factor=1");  
              res.next();

            } catch (SQLException e) {
                if (e.getMessage().startsWith("Keyspace does not exist")) 
                {
                    res = stmt.executeQuery("CREATE KEYSPACE ks1 with strategy_class =  'org.apache.cassandra.locator.SimpleStrategy'
and strategy_options:replication_factor=1");  
                } 
            }   
            connection.close();    
            
            // Run Test
            connection = DriverManager.getConnection("jdbc:cassandra:root/root@127.0.0.1:9160/ks1");
    
            stmt = connection.createStatement();

            System.out.print("Running CREATE CF Statement");
            res = stmt.executeQuery("CREATE COLUMNFAMILY users (KEY varchar PRIMARY KEY, password
varchar, gender varchar, session_token varchar, state varchar, birth_year bigint)");    
            colCount = res.getMetaData().getColumnCount();
            System.out.println(" -- Column Count: " + colCount); 
            res.next();
            
            System.out.print("Running INSERT Statement");
            res = stmt.executeQuery("INSERT INTO users (KEY, password) VALUES ('user1', 'ch@nge')");
 
            colCount = res.getMetaData().getColumnCount();
            System.out.println(" -- Column Count: " + colCount); 
            res.next();
            
            System.out.print("Running SELECT Statement");
            res = stmt.executeQuery("SELECT bar FROM users");  
            colCount = res.getMetaData().getColumnCount();
            System.out.println(" -- Column Count: " + colCount); 
            res.getRow();
            res.next();
                
            connection.close();               

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
       
}
{code}



> NPE running res.next() for a select statement
> ---------------------------------------------
>
>                 Key: CASSANDRA-2734
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-2734
>             Project: Cassandra
>          Issue Type: Bug
>    Affects Versions: 0.8.0 beta 2
>            Reporter: Cathy Daw
>            Priority: Minor
>              Labels: cql
>
> *The following statement fails when used with a Statement or PreparedStatement*
> {code}
> res = stmt.executeQuery("SELECT bar FROM users");  
> res.next();
> {code}
> *Error Message*
> {code}
>     [junit] Testcase: simpleSelect(com.datastax.cql.reproBugTest):	Caused an ERROR
>     [junit] null
>     [junit] java.lang.NullPointerException
>     [junit] 	at org.apache.cassandra.cql.jdbc.ColumnDecoder.makeKeyColumn(ColumnDecoder.java:136)
>     [junit] 	at org.apache.cassandra.cql.jdbc.CResultSet.next(CResultSet.java:388)
>     [junit] 	at com.datastax.cql.reproBugTest.simpleSelect(reproBugTest.java:57)
>     [junit] 
>     [junit] 
>     [junit] Test com.datastax.cql.reproBugTest FAILED
> {code}
> *Here is a quick repro.  Showing that res.next() works with other statements but not
select.*
> _Also notice that ResultSet.getMetaData().getColumnCount() always returns zero._  
> _I noticed in the existing driver tests similar test cases, so not sure the issue._
> *Steps to run script*
> * you will need to drop this in your test directory
> * change the package declaration
> * ant test -Dtest.name=reproBugTest
> {code}
> package com.datastax.cql;
> import java.sql.DriverManager;
> import java.sql.Connection;
> import java.sql.ResultSet;
> import java.sql.SQLException;
> import java.sql.Statement;
> import org.junit.Test;
> public class reproBugTest {
>     
>     @Test
>     public void simpleSelect() throws Exception {   
>         Connection connection = null;
>         ResultSet res;
>         Statement stmt;
>         int colCount = 0;
>         
>         try {
>             Class.forName("org.apache.cassandra.cql.jdbc.CassandraDriver");
>             
>             // Check create keyspace
>             connection = DriverManager.getConnection("jdbc:cassandra:root/root@127.0.0.1:9160/default");
    
>             stmt = connection.createStatement();
>             try {
>               System.out.println("Running DROP KS Statement");  
>               res = stmt.executeQuery("DROP KEYSPACE ks1");  
>               res.next();
>               
>               System.out.println("Running CREATE KS Statement");
>               res = stmt.executeQuery("CREATE KEYSPACE ks1 with strategy_class =  'org.apache.cassandra.locator.SimpleStrategy'
and strategy_options:replication_factor=1");  
>               res.next();
>             } catch (SQLException e) {
>                 if (e.getMessage().startsWith("Keyspace does not exist")) 
>                 {
>                     res = stmt.executeQuery("CREATE KEYSPACE ks1 with strategy_class
=  'org.apache.cassandra.locator.SimpleStrategy' and strategy_options:replication_factor=1");
 
>                 } 
>             }   
>             connection.close();    
>             
>             // Run Test
>             connection = DriverManager.getConnection("jdbc:cassandra:root/root@127.0.0.1:9160/ks1");
    
>             stmt = connection.createStatement();
>             System.out.print("Running CREATE CF Statement");
>             res = stmt.executeQuery("CREATE COLUMNFAMILY users (KEY varchar PRIMARY KEY,
password varchar, gender varchar, session_token varchar, state varchar, birth_year bigint)");
   
>             colCount = res.getMetaData().getColumnCount();
>             System.out.println(" -- Column Count: " + colCount); 
>             res.next();
>             
>             System.out.print("Running INSERT Statement");
>             res = stmt.executeQuery("INSERT INTO users (KEY, password) VALUES ('user1',
'ch@nge')");  
>             colCount = res.getMetaData().getColumnCount();
>             System.out.println(" -- Column Count: " + colCount); 
>             res.next();
>             
>             System.out.print("Running SELECT Statement");
>             res = stmt.executeQuery("SELECT bar FROM users");  
>             colCount = res.getMetaData().getColumnCount();
>             System.out.println(" -- Column Count: " + colCount); 
>             res.getRow();
>             res.next();
>                 
>             connection.close();               
>         } catch (SQLException e) {
>             e.printStackTrace();
>         }
>     }
>        
> }
> {code}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message