Astyanax を使用して、CQL3 クエリを使用して Cassandra にクエリを実行していますが、正常に動作しています。
クエリ (SELECT ...) のみを作成したいのですが、たとえば次のコードを使用しています。
AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder()
.forCluster("anyCluster") // Not using clusters
.forKeyspace("default") // Name of my keyspace
.withAstyanaxConfiguration(new AstyanaxConfigurationImpl()
.setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
.setCqlVersion("3.0.0")
.setTargetCassandraVersion("1.2")
)
.withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool")
.setPort(9160)
.setMaxConnsPerHost(1)
.setSeeds("localhost:9160")
)
.withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
.buildKeyspace(ThriftFamilyFactory.getInstance());
context.start();
Keyspace keyspace = context.getClient();
// Defining any columnfamily
ColumnFamily<String, String> cf =
new ColumnFamily<String, String>(
".", // It works without passing here the name.
StringSerializer.get(), // Key Serializer
StringSerializer.get());
前のコードは接続の一部であり、クエリを実行してデータを取得したいのですが、クエリで期待しているデータ型がわからないため、取得に使用する方法がわかりません以下に示すように、値はgetBooleanValue
、、、などを使用する必要があるかどうかわかりません。getStringValue
getIntegerValue
try {
OperationResult<CqlResult<String, String>> result
= keyspace.prepareQuery(emp2).withCql("Select * from table_test;").execute();
for (Row<String, String> row : result.getResult().getRows()) {
ColumnList<String> cols = row.getColumns();
System.out.println(cols.getColumnNames());
for(String col : cols.getColumnNames()){
try{
boolean value = cols.getBooleanValue(col, null);
System.out.println(value);
}catch(Exception e){
System.out.println(col + " isn't boolean");
}
try{
Date value = cols.getDateValue(col, null);
System.out.println(value);
}catch(Exception e){
System.out.println(col + " isn't Date");
}
try{
Integer value = cols.getIntegerValue(col, null);
System.out.println(value);
}catch(Exception e){
System.out.println(col + " isn't Integer");
}
try{
Double value = cols.getDoubleValue(col, null);
System.out.println(value);
}catch(Exception e){
System.out.println(col + " isn't Double");
}
try{
String value = cols.getStringValue(col, null);
System.out.println(value);
}catch(Exception e){
System.out.println(col + " isn't string");
}
}
}
} catch (ConnectionException e) {
e.printStackTrace();
}
それで、これを知る方法はありますか?この API を使用することも、別の API を使用することもできます。
ありがとうございました。