Return-Path: X-Original-To: apmail-cassandra-commits-archive@www.apache.org Delivered-To: apmail-cassandra-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 68BDF44E4 for ; Mon, 6 Jun 2011 03:42:12 +0000 (UTC) Received: (qmail 40249 invoked by uid 500); 6 Jun 2011 03:42:12 -0000 Delivered-To: apmail-cassandra-commits-archive@cassandra.apache.org Received: (qmail 40220 invoked by uid 500); 6 Jun 2011 03:42:12 -0000 Mailing-List: contact commits-help@cassandra.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cassandra.apache.org Delivered-To: mailing list commits@cassandra.apache.org Received: (qmail 39983 invoked by uid 99); 6 Jun 2011 03:42:11 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Jun 2011 03:42:11 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Jun 2011 03:42:08 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id A1A27102FB3 for ; Mon, 6 Jun 2011 03:41:47 +0000 (UTC) Date: Mon, 6 Jun 2011 03:41:47 +0000 (UTC) From: "Aaron Morton (JIRA)" To: commits@cassandra.apache.org Message-ID: <1028623671.70577.1307331707658.JavaMail.tomcat@hel.zones.apache.org> In-Reply-To: <996877646.61422.1306973567550.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Commented] (CASSANDRA-2734) NPE running res.next() for a select statement MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on 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