Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read a single row #1

Open
monisa opened this issue May 5, 2011 · 2 comments
Open

read a single row #1

monisa opened this issue May 5, 2011 · 2 comments

Comments

@monisa
Copy link

monisa commented May 5, 2011

Hi am new to cassandra 0.7. could u able to clear my doubt???

This is my code for read a single row

public class Read1Column
{
private static StringSerializer stringSerializer = StringSerializer.get();
private static DoubleSerializer doubtSerializer = DoubleSerializer.get();
public static void main(String[] args) throws Exception {

          String keyspaceName = "User";
          String columnFamilyName ="User_Details";
          String serverAddress = "localhost:9160";
          //String username="stu1";
          String Uid="0001";
          // String FirstName="ss";
         // String LastName="kk";
         // String EMail="sksk";
         String password="ssss";      
    // Create a cluster
          Cluster cluster = HFactory.getOrCreateCluster("TestCluster", serverAddress);            
          Keyspace keyspaceOperator = HFactory.createKeyspace(keyspaceName, cluster);


            try{

                Iterator<SuperRow<String, String, String, Double>> rowIter =
                    HFactory.createRangeSuperSlicesQuery(keyspaceOperator,
                            stringSerializer, stringSerializer, stringSerializer,
                            doubtSerializer)
                                        .setColumnFamily(columnFamilyName)
                                        .setKeys(Uid,password)
                                        .setRange(Uid, password, false, 40)
                                        .execute()
                                        .get()
                                        .iterator();

                    while (rowIter.hasNext()) {

                                    SuperRow<String, String, String, Double> row =
                    rowIter.next();

                                    List<HSuperColumn<String, String, Double>> scList =
                    row.getSuperSlice().getSuperColumns();

                                    for (int i=0; i<scList.size(); i++) {
                                             HSuperColumn<String, String, Double> sc =
                    scList.get(i);
                                            // Double val = sc.get(2).getValue(); 
                            // gets the value of column 2 within the supercolumn
                                             System.out.println(sc.get(2).getValue());

                                    }
                    }


            } catch (HectorException e) {
                e.printStackTrace();
            }
          //  client.getConnectionManager().shutdown();
        }

}

its show the error:

log4j:WARN No appenders could be found for logger (me.prettyprint.cassandra.connection.CassandraHostRetryService).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.NullPointerException: Null not allowed, number 1
at me.prettyprint.cassandra.utils.Assert.noneNull(Assert.java:25)
at me.prettyprint.cassandra.model.HSuperColumnImpl.(HSuperColumnImpl.java:58)
at me.prettyprint.cassandra.model.SuperSliceImpl.(SuperSliceImpl.java:35)
at me.prettyprint.cassandra.model.SuperRowImpl.(SuperRowImpl.java:34)
at me.prettyprint.cassandra.model.SuperRowsImpl.(SuperRowsImpl.java:35)
at me.prettyprint.cassandra.model.OrderedSuperRowsImpl.(OrderedSuperRowsImpl.java:28)
at me.prettyprint.cassandra.model.thrift.ThriftRangeSuperSlicesQuery$1.doInKeyspace(ThriftRangeSuperSlicesQuery.java:73)
at me.prettyprint.cassandra.model.thrift.ThriftRangeSuperSlicesQuery$1.doInKeyspace(ThriftRangeSuperSlicesQuery.java:67)
at me.prettyprint.cassandra.model.KeyspaceOperationCallback.doInKeyspaceAndMeasure(KeyspaceOperationCallback.java:20)
at me.prettyprint.cassandra.model.ExecutingKeyspace.doExecute(ExecutingKeyspace.java:65)
at me.prettyprint.cassandra.model.thrift.ThriftRangeSuperSlicesQuery.execute(ThriftRangeSuperSlicesQuery.java:66)
at Read1Column.main(Read1Column.java:40)

@zznate
Copy link
Owner

zznate commented May 5, 2011

Strange - looks like you got a null SC back in the result list. Can you show me output from cassandra-cli of what you expect to be there?

@monisa
Copy link
Author

monisa commented May 6, 2011

If i give the key(Uid) means its display the entire column from the cassandra-cli. This is my expecting output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants