You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by "Cathy Daw (JIRA)" <ji...@apache.org> on 2011/06/02 02:12:47 UTC

[jira] [Created] (CASSANDRA-2734) NPE running res.next() for a select statement

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


*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;
        
        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.println("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)");    
            res.next();
            
            System.out.println("Running INSERT Statement");
            res = stmt.executeQuery("INSERT INTO users (KEY, password) VALUES ('user1', 'ch@nge')");  
            res.next();
            
            System.out.println("Running SELECT Statement");
            res = stmt.executeQuery("SELECT bar FROM users");  
            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

[jira] [Updated] (CASSANDRA-2734) NPE running res.next() for a select statement

Posted by "Cathy Daw (JIRA)" <ji...@apache.org>.
     [ 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.  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}


  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;
        
        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.println("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)");    
            res.next();
            
            System.out.println("Running INSERT Statement");
            res = stmt.executeQuery("INSERT INTO users (KEY, password) VALUES ('user1', 'ch@nge')");  
            res.next();
            
            System.out.println("Running SELECT Statement");
            res = stmt.executeQuery("SELECT bar FROM users");  
            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.  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}

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

[jira] [Commented] (CASSANDRA-2734) NPE running res.next() for a select statement

Posted by "Aaron Morton (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CASSANDRA-2734?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13043270#comment-13043270 ] 

Aaron Morton commented on CASSANDRA-2734:
-----------------------------------------

I think there is a reasonable case for handling it better, it just may be out of scope for the current CQL dev cycle. 

Imagine long running code, a schema change, and a situation where the code does not have to be restarted to start executing queries using the new or modified CF's. Or imagine creating a Query Tool for cassandra like other DB's have, where DDL and DML statement are run. 

Jonathan, in the future could we include the schema id in the query response and in the response when the client reads the schema (currently describe_keyspaces). Then we could invalidate the client side meta data.  
   
I'll take another look at the column count example. 



> 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
>            Assignee: Aaron Morton
>            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

[jira] [Updated] (CASSANDRA-2734) CQL protocol does not include schema information

Posted by "Jonathan Ellis (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CASSANDRA-2734?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jonathan Ellis updated CASSANDRA-2734:
--------------------------------------

    Summary: CQL protocol does not include schema information  (was: JDBC driver assumes schema is constant for the duration of the connection)

> CQL protocol does not include schema information
> ------------------------------------------------
>
>                 Key: CASSANDRA-2734
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-2734
>             Project: Cassandra
>          Issue Type: Sub-task
>          Components: API
>    Affects Versions: 0.8.0
>            Reporter: Cathy Daw
>            Assignee: Jonathan Ellis
>            Priority: Minor
>              Labels: cql
>             Fix For: 1.0
>
>         Attachments: 0001-include-schema-with-resultset.patch, 0002-ant-gen-thrift-java.txt, 0003-thrift-gen.txt
>
>
> *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

        

[jira] [Updated] (CASSANDRA-2734) JDBC driver assumes schema is constant for the duration of the connection

Posted by "Jonathan Ellis (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CASSANDRA-2734?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jonathan Ellis updated CASSANDRA-2734:
--------------------------------------

    Attachment: 0001-include-schema-with-resultset.patch

new version of 01 "minifies" type classnames for the standard o.a.c.db.marshal types

> JDBC driver assumes schema is constant for the duration of the connection
> -------------------------------------------------------------------------
>
>                 Key: CASSANDRA-2734
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-2734
>             Project: Cassandra
>          Issue Type: Sub-task
>          Components: API
>    Affects Versions: 0.8.0
>            Reporter: Cathy Daw
>            Assignee: Jonathan Ellis
>            Priority: Minor
>              Labels: cql
>             Fix For: 1.0
>
>         Attachments: 0001-include-schema-with-resultset.patch, 0002-ant-gen-thrift-java.txt, 0003-thrift-gen.txt
>
>
> *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

        

[jira] [Commented] (CASSANDRA-2734) NPE running res.next() for a select statement

Posted by "Cathy Daw (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CASSANDRA-2734?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13043244#comment-13043244 ] 

Cathy Daw commented on CASSANDRA-2734:
--------------------------------------

BTW ... I am not sure if this is not implemented or a bug, but the following will return 0 but I expected 2.

{code}
res = stmt.executeQuery("SELECT KEY, password FROM users");  
colCount = res.getMetaData().getColumnCount();
System.out.println(" -- Column Count: " + colCount);
{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
>            Assignee: Aaron Morton
>            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

[jira] [Updated] (CASSANDRA-2734) JDBC driver assumes schema is constant for the duration of the connection

Posted by "Jonathan Ellis (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CASSANDRA-2734?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jonathan Ellis updated CASSANDRA-2734:
--------------------------------------

    Attachment:     (was: 0001-include-schema-with-resultset.txt)

> JDBC driver assumes schema is constant for the duration of the connection
> -------------------------------------------------------------------------
>
>                 Key: CASSANDRA-2734
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-2734
>             Project: Cassandra
>          Issue Type: Sub-task
>          Components: API
>    Affects Versions: 0.8.0
>            Reporter: Cathy Daw
>            Assignee: Jonathan Ellis
>            Priority: Minor
>              Labels: cql
>             Fix For: 1.0
>
>         Attachments: 0001-include-schema-with-resultset.patch, 0002-ant-gen-thrift-java.txt, 0003-thrift-gen.txt
>
>
> *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

        

[jira] [Commented] (CASSANDRA-2734) NPE running res.next() for a select statement

Posted by "Cathy Daw (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CASSANDRA-2734?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13043980#comment-13043980 ] 

Cathy Daw commented on CASSANDRA-2734:
--------------------------------------

Another good reason to run this is that if we ever start working with analytics tools via jdbc, those tools create and drop lot of temp tables to massage data in.

> 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
>            Assignee: Aaron Morton
>            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

[jira] [Commented] (CASSANDRA-2734) NPE running res.next() for a select statement

Posted by "Aaron Morton (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CASSANDRA-2734?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13044692#comment-13044692 ] 

Aaron Morton commented on CASSANDRA-2734:
-----------------------------------------

Jonathan, 
This is from the Postgres Protocol docs http://www.postgresql.org/docs/9.0/static/protocol-flow.html#AEN84318

bq. The response to a SELECT query (or other queries that return row sets, such as EXPLAIN or SHOW) normally consists of RowDescription, zero or more DataRow messages, and then CommandComplete. COPY to or from the frontend invokes special protocol as described in Section 46.2.5. All other query types normally produce only a CommandComplete message.

Obviously the ability for of a SQL SELECT to cast and create any data it wants makes their life a bit harder.

Longer term we could allow the client to include it's schema ID in the request (like the compression param) and then return the schema for the CF involved in the select if it does not match. Could get a bit messy with the client holding CF definitions from different schema versions. Returning the full KS def may be a bit heavy weight.   

Short term and until CASSANDRA-2477 is in place, a possible solution is:

Add an optional string to the CqlResult thrift type that is set to DatabaseDescriptor.getDefsVersion() for ROWS result types. 

Have the JDBC client could also call describe_schema_versions() and get the schema ID for the node it's connected to when it is building the meta data. describe_schema_versions() goes to all live nodes.
  

> 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
>            Assignee: Aaron Morton
>            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

[jira] [Commented] (CASSANDRA-2734) NPE running res.next() for a select statement

Posted by "Aaron Morton (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CASSANDRA-2734?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13044683#comment-13044683 ] 

Aaron Morton commented on CASSANDRA-2734:
-----------------------------------------

Cathy, 
I've taken a look at the code and cannot reproduce the bug. I think the problem is you are checking the column count before advancing to the first record, call next() first. There should only be a column count for the SELECT statement and it potentially will be different for each row. 

> 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
>            Assignee: Aaron Morton
>            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

[jira] [Commented] (CASSANDRA-2734) NPE running res.next() for a select statement

Posted by "Cathy Daw (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CASSANDRA-2734?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13043243#comment-13043243 ] 

Cathy Daw commented on CASSANDRA-2734:
--------------------------------------

Hi Aaron,

Creating the new connection after CREATE COLUMNFAMILY worked.  But you just killed my test harness!  Plan is to run CQL's thru cqlsh, jdbc and the python drivers, so I am gonna have to break and reconnect when I see a CREATE statement :-)

Thanks,
Cathy


> 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
>            Assignee: Aaron Morton
>            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

[jira] [Updated] (CASSANDRA-2734) JDBC driver assumes schema is constant for the duration of the connection

Posted by "Jonathan Ellis (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CASSANDRA-2734?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jonathan Ellis updated CASSANDRA-2734:
--------------------------------------

    Attachment: 0003-thrift-gen.txt
                0002-ant-gen-thrift-java.txt
                0001-include-schema-with-resultset.txt

> JDBC driver assumes schema is constant for the duration of the connection
> -------------------------------------------------------------------------
>
>                 Key: CASSANDRA-2734
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-2734
>             Project: Cassandra
>          Issue Type: Sub-task
>          Components: API
>    Affects Versions: 0.8.0
>            Reporter: Cathy Daw
>            Assignee: Jonathan Ellis
>            Priority: Minor
>              Labels: cql
>             Fix For: 1.0
>
>         Attachments: 0001-include-schema-with-resultset.txt, 0002-ant-gen-thrift-java.txt, 0003-thrift-gen.txt
>
>
> *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

        

[jira] [Commented] (CASSANDRA-2734) JDBC driver assumes schema is constant for the duration of the connection

Posted by "Jonathan Ellis (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CASSANDRA-2734?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13094086#comment-13094086 ] 

Jonathan Ellis commented on CASSANDRA-2734:
-------------------------------------------

Thinking it through, I think we do need to provide a "full" resultset schema with each query, or we fail in our goal of pushing this logic to the server.  We already have a taste of this in that clients have to parse queries to guess what keyspace and CF is being referenced by a SELECT; that's going to get worse as we start to add things like transposition/composite column syntax (CASSANDRA-2474).

> JDBC driver assumes schema is constant for the duration of the connection
> -------------------------------------------------------------------------
>
>                 Key: CASSANDRA-2734
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-2734
>             Project: Cassandra
>          Issue Type: Sub-task
>          Components: API
>    Affects Versions: 0.8.0
>            Reporter: Cathy Daw
>            Assignee: Aaron Morton
>            Priority: Minor
>              Labels: cql
>             Fix For: 1.0
>
>
> *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

        

[jira] [Commented] (CASSANDRA-2734) JDBC driver assumes schema is constant for the duration of the connection

Posted by "Tyler Hobbs (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CASSANDRA-2734?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13096448#comment-13096448 ] 

Tyler Hobbs commented on CASSANDRA-2734:
----------------------------------------

struct CqlMetadata uses 1 for the field number twice in cassandra.thrift.


In {{decoders.py}} in {{decode_description}}:

{noformat}
name = column.name
comparator = schema.name_types[name] \
             if name in schema.name_types \
             else schema.default_name_type
{noformat}

can just be:

{noformat}
comparator = schema.name_types.get(column.name, schema.default_name_type)
{noformat}

and similarly in {{decode_row()}}.

Other than that, it looks good to me.

> JDBC driver assumes schema is constant for the duration of the connection
> -------------------------------------------------------------------------
>
>                 Key: CASSANDRA-2734
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-2734
>             Project: Cassandra
>          Issue Type: Sub-task
>          Components: API
>    Affects Versions: 0.8.0
>            Reporter: Cathy Daw
>            Assignee: Jonathan Ellis
>            Priority: Minor
>              Labels: cql
>             Fix For: 1.0
>
>         Attachments: 0001-include-schema-with-resultset.patch, 0002-ant-gen-thrift-java.txt, 0003-thrift-gen.txt
>
>
> *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

        

[jira] [Updated] (CASSANDRA-2734) JDBC driver assumes schema is constant for the duration of the connection

Posted by "Jonathan Ellis (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CASSANDRA-2734?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jonathan Ellis updated CASSANDRA-2734:
--------------------------------------

    Issue Type: Sub-task  (was: Bug)
        Parent: CASSANDRA-2472

> JDBC driver assumes schema is constant for the duration of the connection
> -------------------------------------------------------------------------
>
>                 Key: CASSANDRA-2734
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-2734
>             Project: Cassandra
>          Issue Type: Sub-task
>          Components: API
>    Affects Versions: 0.8.0
>            Reporter: Cathy Daw
>            Assignee: Aaron Morton
>            Priority: Minor
>              Labels: cql
>             Fix For: 0.8.5
>
>
> *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

        

[jira] [Updated] (CASSANDRA-2734) JDBC driver assumes schema is constant for the duration of the connection

Posted by "Tyler Hobbs (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CASSANDRA-2734?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Tyler Hobbs updated CASSANDRA-2734:
-----------------------------------

    Reviewer: thobbs

> JDBC driver assumes schema is constant for the duration of the connection
> -------------------------------------------------------------------------
>
>                 Key: CASSANDRA-2734
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-2734
>             Project: Cassandra
>          Issue Type: Sub-task
>          Components: API
>    Affects Versions: 0.8.0
>            Reporter: Cathy Daw
>            Assignee: Jonathan Ellis
>            Priority: Minor
>              Labels: cql
>             Fix For: 1.0
>
>         Attachments: 0001-include-schema-with-resultset.patch, 0002-ant-gen-thrift-java.txt, 0003-thrift-gen.txt
>
>
> *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

        

[jira] [Commented] (CASSANDRA-2734) NPE running res.next() for a select statement

Posted by "Jonathan Ellis (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CASSANDRA-2734?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13060065#comment-13060065 ] 

Jonathan Ellis commented on CASSANDRA-2734:
-------------------------------------------

bq. Add an optional string to the CqlResult thrift type that is set to DatabaseDescriptor.getDefsVersion() for ROWS result types.  Have the JDBC client could also call describe_schema_versions() and get the schema ID for the node it's connected to when it is building the meta data. 

I like this idea.

> 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
>            Assignee: Aaron Morton
>            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

        

[jira] [Commented] (CASSANDRA-2734) NPE running res.next() for a select statement

Posted by "Jonathan Ellis (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CASSANDRA-2734?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13043984#comment-13043984 ] 

Jonathan Ellis commented on CASSANDRA-2734:
-------------------------------------------

bq. I am not sure if this is not implemented or a bug, but the following will return 0 but I expected 2

that's a bug

bq. Jonathan, in the future could we include the schema id in the query response 

Not sure how we'd do that w/o breaking compatibility. :(

What do drivers like libpq do here? Do they send the schema w/ each query result?

> 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
>            Assignee: Aaron Morton
>            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

[jira] [Commented] (CASSANDRA-2734) JDBC driver assumes schema is constant for the duration of the connection

Posted by "Rick Shaw (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CASSANDRA-2734?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13094103#comment-13094103 ] 

Rick Shaw commented on CASSANDRA-2734:
--------------------------------------

Are you saying you would return a JDBC {{ResultSet}} interface from a CQL call, or enough schema information to let {{Statement}} and {{ResultSet}} do a more complete job on the client side? 

> JDBC driver assumes schema is constant for the duration of the connection
> -------------------------------------------------------------------------
>
>                 Key: CASSANDRA-2734
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-2734
>             Project: Cassandra
>          Issue Type: Sub-task
>          Components: API
>    Affects Versions: 0.8.0
>            Reporter: Cathy Daw
>            Assignee: Jonathan Ellis
>            Priority: Minor
>              Labels: cql
>             Fix For: 1.0
>
>
> *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

        

[jira] [Commented] (CASSANDRA-2734) JDBC driver assumes schema is constant for the duration of the connection

Posted by "Eric Evans (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CASSANDRA-2734?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13094929#comment-13094929 ] 

Eric Evans commented on CASSANDRA-2734:
---------------------------------------

Thinking out loud... I wish we at least *knew* the performance impact of changes like this.  It might be negligible, it might be totally worth it, but I would feel better just knowing.

> JDBC driver assumes schema is constant for the duration of the connection
> -------------------------------------------------------------------------
>
>                 Key: CASSANDRA-2734
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-2734
>             Project: Cassandra
>          Issue Type: Sub-task
>          Components: API
>    Affects Versions: 0.8.0
>            Reporter: Cathy Daw
>            Assignee: Jonathan Ellis
>            Priority: Minor
>              Labels: cql
>             Fix For: 1.0
>
>         Attachments: 0001-include-schema-with-resultset.patch, 0002-ant-gen-thrift-java.txt, 0003-thrift-gen.txt
>
>
> *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

        

[jira] [Commented] (CASSANDRA-2734) JDBC driver assumes schema is constant for the duration of the connection

Posted by "Jonathan Ellis (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CASSANDRA-2734?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13094109#comment-13094109 ] 

Jonathan Ellis commented on CASSANDRA-2734:
-------------------------------------------

Here's my first stab at it:

{code}
+struct CqlColumnDef {
+    1: required binary column_name,
+    2: required string validation_class
+}
+
+struct CqlSchema {
+    1: required list<CqlColumnDef> column_metadata,
+    2: required string comparator_type,
+    3: required string default_validation_class,
+    4: optional binary key_alias,
+    5: optional string key_validation_class,
+}
+
 struct CqlResult {
     1: required CqlResultType type,
     2: optional list<CqlRow> rows,
-    3: optional i32 num
+    3: optional i32 num,
+    4: optional CqlSchema schema
 }
{code}

> JDBC driver assumes schema is constant for the duration of the connection
> -------------------------------------------------------------------------
>
>                 Key: CASSANDRA-2734
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-2734
>             Project: Cassandra
>          Issue Type: Sub-task
>          Components: API
>    Affects Versions: 0.8.0
>            Reporter: Cathy Daw
>            Assignee: Jonathan Ellis
>            Priority: Minor
>              Labels: cql
>             Fix For: 1.0
>
>
> *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

        

[jira] [Updated] (CASSANDRA-2734) SELECT after DDL can result in NPE

Posted by "Jonathan Ellis (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CASSANDRA-2734?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jonathan Ellis updated CASSANDRA-2734:
--------------------------------------

      Component/s: API
    Fix Version/s: 0.8.2
          Summary: SELECT after DDL can result in NPE  (was: NPE running res.next() for a select statement)

> SELECT after DDL can result in NPE
> ----------------------------------
>
>                 Key: CASSANDRA-2734
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-2734
>             Project: Cassandra
>          Issue Type: Bug
>          Components: API
>    Affects Versions: 0.8.0 beta 2
>            Reporter: Cathy Daw
>            Assignee: Aaron Morton
>            Priority: Minor
>              Labels: cql
>             Fix For: 0.8.2
>
>
> *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

        

[jira] [Updated] (CASSANDRA-2734) JDBC driver assumes schema is constant for the duration of the connection

Posted by "Jonathan Ellis (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CASSANDRA-2734?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jonathan Ellis updated CASSANDRA-2734:
--------------------------------------

    Affects Version/s:     (was: 0.8.0 beta 2)
                       0.8.0
              Summary: JDBC driver assumes schema is constant for the duration of the connection  (was: SELECT after DDL can result in NPE)

> JDBC driver assumes schema is constant for the duration of the connection
> -------------------------------------------------------------------------
>
>                 Key: CASSANDRA-2734
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-2734
>             Project: Cassandra
>          Issue Type: Bug
>          Components: API
>    Affects Versions: 0.8.0
>            Reporter: Cathy Daw
>            Assignee: Aaron Morton
>            Priority: Minor
>              Labels: cql
>             Fix For: 0.8.5
>
>
> *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

        

[jira] [Commented] (CASSANDRA-2734) NPE running res.next() for a select statement

Posted by "Aaron Morton (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CASSANDRA-2734?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13043212#comment-13043212 ] 

Aaron Morton commented on CASSANDRA-2734:
-----------------------------------------

All the keyspace meta data is read from the server and cached in the ColumnDecoder the first time o.a.c.cql.jdbc.Connection.execute() is run and cached for future calls. In the test this happens when the "CREATE COLUMNFAMILY" statement is run and so there are no CF's defined for the ks1.


The code for makeKeyColumn() expects that all the meta data is present, like the other functions on ColumnDecoder. And the NPE is because the CF does not exist in the ks metadata held by the Connection. 

The test passes if a new connection is created after CREATE COLUMNFAMILY. 

We could either:

1. Raise a StaleClientSchemaException or some such from ColumnDecoder if it does not have the meta data for a CF. Clients responsibility would be to create a new connection.  
2. Re-get the meta data if an unknown CF is returned. Unsure about the implications, if any, of lots of connections discovering they have bad meta data all at once. 


INSERT and CREATE COLUMNFAMILY return void resultsets, the 0 column count is to be expected. 

btw, thanks for the nice bug report :)
 

> 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
>            Assignee: Aaron Morton
>            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

[jira] [Commented] (CASSANDRA-2734) JDBC driver assumes schema is constant for the duration of the connection

Posted by "Rick Shaw (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CASSANDRA-2734?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13094112#comment-13094112 ] 

Rick Shaw commented on CASSANDRA-2734:
--------------------------------------

Cool!

> JDBC driver assumes schema is constant for the duration of the connection
> -------------------------------------------------------------------------
>
>                 Key: CASSANDRA-2734
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-2734
>             Project: Cassandra
>          Issue Type: Sub-task
>          Components: API
>    Affects Versions: 0.8.0
>            Reporter: Cathy Daw
>            Assignee: Jonathan Ellis
>            Priority: Minor
>              Labels: cql
>             Fix For: 1.0
>
>
> *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

        

[jira] [Commented] (CASSANDRA-2734) JDBC driver assumes schema is constant for the duration of the connection

Posted by "Hudson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CASSANDRA-2734?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13098180#comment-13098180 ] 

Hudson commented on CASSANDRA-2734:
-----------------------------------

Integrated in Cassandra #1079 (See [https://builds.apache.org/job/Cassandra/1079/])
    include schema with CQL resultset
patch by jbellis; reviewed by thobbs for CASSANDRA-2734

jbellis : http://svn.apache.org/viewcvs.cgi/?root=Apache-SVN&view=rev&rev=1165750
Files : 
* /cassandra/trunk/drivers/java/src/org/apache/cassandra/cql/jdbc/CResultSet.java
* /cassandra/trunk/drivers/java/src/org/apache/cassandra/cql/jdbc/CassandraResultSet.java
* /cassandra/trunk/drivers/java/src/org/apache/cassandra/cql/jdbc/CassandraStatement.java
* /cassandra/trunk/drivers/java/src/org/apache/cassandra/cql/jdbc/ColumnDecoder.java
* /cassandra/trunk/drivers/java/test/org/apache/cassandra/cql/EmbeddedServiceBase.java
* /cassandra/trunk/drivers/java/test/org/apache/cassandra/cql/JdbcDriverTest.java
* /cassandra/trunk/drivers/py/cql/cassandra/Cassandra.py
* /cassandra/trunk/drivers/py/cql/cassandra/constants.py
* /cassandra/trunk/drivers/py/cql/cassandra/ttypes.py
* /cassandra/trunk/drivers/py/cql/cursor.py
* /cassandra/trunk/drivers/py/cql/decoders.py
* /cassandra/trunk/drivers/py/cql/marshal.py
* /cassandra/trunk/interface/cassandra.thrift
* /cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/Cassandra.java
* /cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/Constants.java
* /cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/CqlMetadata.java
* /cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/CqlResult.java
* /cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java
* /cassandra/trunk/src/java/org/apache/cassandra/config/Schema.java
* /cassandra/trunk/src/java/org/apache/cassandra/cql/QueryProcessor.java
* /cassandra/trunk/src/java/org/apache/cassandra/cql/jdbc/TypesMap.java
* /cassandra/trunk/src/java/org/apache/cassandra/db/marshal/AbstractType.java
* /cassandra/trunk/src/java/org/apache/cassandra/db/marshal/TypeParser.java


> JDBC driver assumes schema is constant for the duration of the connection
> -------------------------------------------------------------------------
>
>                 Key: CASSANDRA-2734
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-2734
>             Project: Cassandra
>          Issue Type: Sub-task
>          Components: API
>    Affects Versions: 0.8.0
>            Reporter: Cathy Daw
>            Assignee: Jonathan Ellis
>            Priority: Minor
>              Labels: cql
>             Fix For: 1.0
>
>         Attachments: 0001-include-schema-with-resultset.patch, 0002-ant-gen-thrift-java.txt, 0003-thrift-gen.txt
>
>
> *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

        

[jira] [Assigned] (CASSANDRA-2734) NPE running res.next() for a select statement

Posted by "Jonathan Ellis (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CASSANDRA-2734?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jonathan Ellis reassigned CASSANDRA-2734:
-----------------------------------------

    Assignee: Aaron Morton

Aaron, might this be a regression from CASSANDRA-2311? I see makeKeyColumn at the top of the ST.

> 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
>            Assignee: Aaron Morton
>            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

[jira] [Commented] (CASSANDRA-2734) JDBC driver assumes schema is constant for the duration of the connection

Posted by "Jonathan Ellis (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CASSANDRA-2734?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13094268#comment-13094268 ] 

Jonathan Ellis commented on CASSANDRA-2734:
-------------------------------------------

Ended up with a slight modification to the above to avoid having to special case key_alias so much.

Python driver cleaned up nicely; Java cleaned up partway but PreparedStatement is still a nightmare.  Not planning to deal with that until CASSANDRA-2475.

> JDBC driver assumes schema is constant for the duration of the connection
> -------------------------------------------------------------------------
>
>                 Key: CASSANDRA-2734
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-2734
>             Project: Cassandra
>          Issue Type: Sub-task
>          Components: API
>    Affects Versions: 0.8.0
>            Reporter: Cathy Daw
>            Assignee: Jonathan Ellis
>            Priority: Minor
>              Labels: cql
>             Fix For: 1.0
>
>         Attachments: 0001-include-schema-with-resultset.txt, 0002-ant-gen-thrift-java.txt, 0003-thrift-gen.txt
>
>
> *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

        

[jira] [Assigned] (CASSANDRA-2734) JDBC driver assumes schema is constant for the duration of the connection

Posted by "Jonathan Ellis (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CASSANDRA-2734?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jonathan Ellis reassigned CASSANDRA-2734:
-----------------------------------------

    Assignee: Jonathan Ellis  (was: Aaron Morton)

> JDBC driver assumes schema is constant for the duration of the connection
> -------------------------------------------------------------------------
>
>                 Key: CASSANDRA-2734
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-2734
>             Project: Cassandra
>          Issue Type: Sub-task
>          Components: API
>    Affects Versions: 0.8.0
>            Reporter: Cathy Daw
>            Assignee: Jonathan Ellis
>            Priority: Minor
>              Labels: cql
>             Fix For: 1.0
>
>
> *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

        

[jira] [Updated] (CASSANDRA-2734) NPE running res.next() for a select statement

Posted by "Cathy Daw (JIRA)" <ji...@apache.org>.
     [ 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

[jira] [Issue Comment Edited] (CASSANDRA-2734) JDBC driver assumes schema is constant for the duration of the connection

Posted by "Jonathan Ellis (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CASSANDRA-2734?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13098130#comment-13098130 ] 

Jonathan Ellis edited comment on CASSANDRA-2734 at 9/6/11 4:17 PM:
-------------------------------------------------------------------

rebased and committed with above fixes (and bumping Thrift api minor version)

      was (Author: jbellis):
    rebased and committed
  
> JDBC driver assumes schema is constant for the duration of the connection
> -------------------------------------------------------------------------
>
>                 Key: CASSANDRA-2734
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-2734
>             Project: Cassandra
>          Issue Type: Sub-task
>          Components: API
>    Affects Versions: 0.8.0
>            Reporter: Cathy Daw
>            Assignee: Jonathan Ellis
>            Priority: Minor
>              Labels: cql
>             Fix For: 1.0
>
>         Attachments: 0001-include-schema-with-resultset.patch, 0002-ant-gen-thrift-java.txt, 0003-thrift-gen.txt
>
>
> *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

        

[jira] [Commented] (CASSANDRA-2734) NPE running res.next() for a select statement

Posted by "Jonathan Ellis (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CASSANDRA-2734?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13043983#comment-13043983 ] 

Jonathan Ellis commented on CASSANDRA-2734:
-------------------------------------------

bq. if we ever start working with analytics tools via jdbc

we won't, not over CQL.

analytics will always be hadoop/hive oriented, CQL will be for realtime queries (no joins).

> 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
>            Assignee: Aaron Morton
>            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

[jira] [Commented] (CASSANDRA-2734) NPE running res.next() for a select statement

Posted by "Aaron Morton (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CASSANDRA-2734?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13043200#comment-13043200 ] 

Aaron Morton commented on CASSANDRA-2734:
-----------------------------------------

on it now

> 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
>            Assignee: Aaron Morton
>            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