Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added support for retrieving long types in a get operation.

  • Loading branch information...
commit 9641b3bea49055ac63fc81e6d72b65534e1e755a 1 parent cbc0e61
@posulliv authored
View
9 libcassandra/cassandra.cc
@@ -282,6 +282,15 @@ string Cassandra::getColumnValue(const string& key,
}
+int64_t Cassandra::getIntegerColumnValue(const string& key,
+ const string& column_family,
+ const string& column_name)
+{
+ string ret= getColumn(key, column_family, column_name).value;
+ return deserializeLong(ret);
+}
+
+
SuperColumn Cassandra::getSuperColumn(const string& key,
const string& column_family,
const string& super_column_name,
View
13 libcassandra/cassandra.h
@@ -274,6 +274,19 @@ class Cassandra
const std::string& column_family,
const std::string& column_name);
+ /**
+ * Retrieve a column value
+ *
+ * @param[in] key the column key
+ * @param[in] column_family the column family
+ * @param[in] column_name the column name (optional)
+ * @return the value for the column that corresponds to the given parameters
+ * but as an integer
+ */
+ int64_t getIntegerColumnValue(const std::string& key,
+ const std::string& column_family,
+ const std::string& column_name);
+
org::apache::cassandra::SuperColumn getSuperColumn(const std::string& key,
const std::string& column_family,
const std::string& super_column_name,
View
27 libcassandra/util_functions.cc
@@ -232,8 +232,7 @@ vector<SuperColumn> getSuperColumnList(vector<ColumnOrSuperColumn>& cols)
++it)
{
ret.push_back((*it).super_column);
- }
- return ret;
+ } return ret;
}
@@ -259,4 +258,28 @@ string serializeLong(int64_t t)
return string(reinterpret_cast<const char *>(raw_array), 8);
}
+
+int64_t deserializeLong(string& t)
+{
+ int64_t ret= 0;
+ int64_t tmp= 0;
+ unsigned char *raw_array= reinterpret_cast<unsigned char *>(const_cast<char *>(t.c_str()));
+ ret|= raw_array[7];
+ tmp= raw_array[6];
+ ret|= (tmp << 8);
+ tmp= raw_array[5];
+ ret|= (tmp << 16);
+ tmp= raw_array[4];
+ ret|= (tmp << 24);
+ tmp= raw_array[3];
+ ret|= (tmp << 32);
+ tmp= raw_array[2];
+ ret|= (tmp << 40);
+ tmp= raw_array[1];
+ ret|= (tmp << 48);
+ tmp= raw_array[0];
+ ret|= (tmp << 56);
+ return ret;
+}
+
} /* end namespace libcassandra */
View
8 libcassandra/util_functions.h
@@ -98,6 +98,14 @@ int64_t createTimestamp();
*/
std::string serializeLong(int64_t t);
+/**
+ * Convert given string in big-endian format
+ * to a 64 bit integer
+ * @param[in] t string to work with
+ * @return a int64_t
+ */
+int64_t deserializeLong(std::string& t);
+
} /* end namespace libcassandra */
#endif /* __LIBCASSANDRA_UTIL_FUNCTIONS_H */
View
19 tests/cassandra_client_test.cc
@@ -143,6 +143,25 @@ TEST_F(ClientTest, InsertColumn)
}
+TEST_F(ClientTest, InsertLongColumn)
+{
+ int64_t mock_data= 56;
+ KeyspaceDefinition ks_def;
+ ks_def.setName("unittest");
+ c->createKeyspace(ks_def);
+ ColumnFamilyDefinition cf_def;
+ cf_def.setName("padraig");
+ cf_def.setKeyspaceName(ks_def.getName());
+ c->setKeyspace(ks_def.getName());
+ c->createColumnFamily(cf_def);
+ c->insertColumn("sarah", "padraig", "third", mock_data);
+ int64_t res= c->getIntegerColumnValue("sarah", "padraig", "third");
+ EXPECT_EQ(mock_data, res);
+ c->dropColumnFamily("padraig");
+ c->dropKeyspace("unittest");
+}
+
+
TEST_F(ClientTest, DeleteColumn)
{
KeyspaceDefinition ks_def;
Please sign in to comment.
Something went wrong with that request. Please try again.