2014-12-11 10 views
9

से बिगइंटर गुण प्राप्त करें मैं कैसंड्रा कॉलम परिवार में महत्वपूर्ण मूल्य जोड़े की संख्या प्राप्त करने का प्रयास कर रहा हूं। मेरे द्वारा उपयोग किया जाने वाला कोड निम्नलिखित है।कैसंड्रा परिणामसेट

PreparedStatement statement = client.session 
      .prepare("select count(*) from corpus.word_usage"); 
ResultSet results = client.session.execute(statement.bind()); 
Row row = results.one(); 
System.out.println(row.getVarint(0)); 

लेकिन जब मैं इस कोड को चलाता हूं, तो मुझे निम्नलिखित अपवाद मिल रहा है।

Exception in thread "main" com.datastax.driver.core.exceptions.InvalidTypeException: Column count is of type bigint 
    at com.datastax.driver.core.ColumnDefinitions.checkType(ColumnDefinitions.java:291) 
    at com.datastax.driver.core.ArrayBackedRow.getVarint(ArrayBackedRow.java:185) 
    at SimpleClient.main(SimpleClient.java:57) 

datastax प्रलेखन के अनुसार (http://www.datastax.com/drivers/java/2.0/com/datastax/driver/core/Row.html) getVarint एक BigInteger लौटना चाहिए। तो मुझे यहां अपवाद क्यों मिल रहा है? मैं क्या गलत कर रहा हूँ?

उत्तर

8

निर्दिष्ट here के रूप में, आप इसके बजाय लंबे समय तक मूल्य प्राप्त कर सकते हैं।

मैं इसे परीक्षण नहीं कर सकता है, लेकिन आप की कोशिश कर सकते इस:

PreparedStatement statement = client.session.prepare("select count(*) from corpus.word_usage"); 
ResultSet results = client.session.execute(statement.bind()); 
Row row = results.one(); 
long expected = row.getLong("count"); 
+0

हाँ यह मेरे लिए भी काम करता है, धन्यवाद। –

0

निम्नलिखित काम किया। मुझे यकीन नहीं है कि यह क्यों काम कर रहा है।

row.getLong(0) 
+0

यह काम करता है क्योंकि एकीकृत फ़ंक्शन गिनती (*) वास्तव में एक पूर्णांक (जो जावा मामले में एक लंबा है) नहीं एक varint रिटर्न (जो जावा में बिगइंटर होगा)। एक तालिका में आप 2^63 पंक्तियों से अधिक नहीं हो सकते हैं, लेकिन यह पर्याप्त होना चाहिए। – sme