本文整理汇总了Java中org.apache.cassandra.thrift.CqlResult类的典型用法代码示例。如果您正苦于以下问题:Java CqlResult类的具体用法?Java CqlResult怎么用?Java CqlResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CqlResult类属于org.apache.cassandra.thrift包,在下文中一共展示了CqlResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processPrepared
import org.apache.cassandra.thrift.CqlResult; //导入依赖的package包/类
public static CqlResult processPrepared(CQLStatement statement, ThriftClientState clientState, List<ByteBuffer> variables)
throws RequestValidationException, RequestExecutionException
{
// Check to see if there are any bound variables to verify
if (!(variables.isEmpty() && (statement.boundTerms == 0)))
{
if (variables.size() != statement.boundTerms)
throw new InvalidRequestException(String.format("there were %d markers(?) in CQL but %d bound variables",
statement.boundTerms,
variables.size()));
// at this point there is a match in count between markers and variables that is non-zero
if (logger.isTraceEnabled())
for (int i = 0; i < variables.size(); i++)
logger.trace("[{}] '{}'", i+1, variables.get(i));
}
return processStatement(statement, new ExecutionContext(clientState, null, variables));
}
示例2: simpleNativeHandler
import org.apache.cassandra.thrift.CqlResult; //导入依赖的package包/类
@Override
public Function<CqlResult, Integer> simpleNativeHandler()
{
return new Function<CqlResult, Integer>()
{
@Override
public Integer apply(CqlResult result)
{
switch (result.getType())
{
case ROWS:
return result.getRows().size();
default:
return 1;
}
}
};
}
示例3: processPrepared
import org.apache.cassandra.thrift.CqlResult; //导入依赖的package包/类
public static CqlResult processPrepared(CQLStatement statement, ThriftClientState clientState, List<ByteBuffer> variables)
throws RequestValidationException, RequestExecutionException
{
// Check to see if there are any bound variables to verify
if (!(variables.isEmpty() && (statement.boundTerms == 0)))
{
if (variables.size() != statement.boundTerms)
throw new InvalidRequestException(String.format("there were %d markers(?) in CQL but %d bound variables",
statement.boundTerms,
variables.size()));
// at this point there is a match in count between markers and variables that is non-zero
if (logger.isTraceEnabled())
for (int i = 0; i < variables.size(); i++)
logger.trace("[{}] '{}'", i+1, variables.get(i));
}
return processStatement(statement, clientState, variables);
}
示例4: executeCql
import org.apache.cassandra.thrift.CqlResult; //导入依赖的package包/类
protected List<CqlResult> executeCql(final String statements) throws MojoExecutionException
{
final List<CqlResult> results = new ArrayList<CqlResult>();
if (StringUtils.isBlank(statements))
{
getLog().warn("No CQL provided. Nothing to do.");
} else
{
try
{
CqlExecOperation operation = new CqlExecOperation(statements);
Utils.executeThrift(operation);
results.addAll(operation.results);
} catch (ThriftApiExecutionException taee)
{
throw new MojoExecutionException(taee.getMessage(), taee);
}
}
return results;
}
示例5: executeStatement
import org.apache.cassandra.thrift.CqlResult; //导入依赖的package包/类
private CqlResult executeStatement(Client client, String statement) throws ThriftApiExecutionException
{
ByteBuffer buf = ByteBufferUtil.bytes(statement);
try
{
if (cqlVersion.charAt(0) >= '3')
{
return client.execute_cql3_query(buf, Compression.NONE, ConsistencyLevel.ONE);
} else
{
return client.execute_cql_query(buf, Compression.NONE);
}
} catch (Exception e)
{
getLog().debug(statement);
throw new ThriftApiExecutionException(e);
}
}
示例6: printResults
import org.apache.cassandra.thrift.CqlResult; //导入依赖的package包/类
private void printResults(List<CqlResult> results)
{
// TODO fix ghetto formatting
getLog().info("-----------------------------------------------");
for (CqlResult result : results)
{
switch (result.type) {
case VOID:
// Void method so nothing to log
break;
case INT:
getLog().info("Number result: " + result.getNum());
break;
case ROWS:
printRows(result);
break;
}
}
}
示例7: getByCql
import org.apache.cassandra.thrift.CqlResult; //导入依赖的package包/类
/**
* getByCql
*
* @throws Exception
*/
@Test
public void getByCql() throws Exception {
String KEYSPACE = "mock";
client.set_keyspace(KEYSPACE);
//
String CQL = "select * from student where KEY='Jack'";
// query, compression
CqlResult result = client.execute_cql_query(
ByteBufferHelper.toByteBuffer(CQL), Compression.NONE);
System.out.println(result);
for (CqlRow cqlRow : result.getRows()) {
for (Column column : cqlRow.getColumns()) {
System.out.println(ByteHelper.toString(cqlRow.getKey()) + ", "
+ ByteHelper.toString(column.getName()) + ": "
+ ByteHelper.toString(column.getValue()) + ", "
+ column.getTimestamp());
// Jack, KEY: Jack, -1
// Jack, art: 87, 1380933848350
// Jack, grad: 5, 1380932164492000
// Jack, math: 97, 1380933848305
}
}
}
示例8: simpleNativeHandler
import org.apache.cassandra.thrift.CqlResult; //导入依赖的package包/类
@Override
public Function<CqlResult, ByteBuffer[][]> simpleNativeHandler()
{
return new Function<CqlResult, ByteBuffer[][]>()
{
@Override
public ByteBuffer[][] apply(CqlResult result)
{
ByteBuffer[][] r = new ByteBuffer[result.getRows().size()][];
for (int i = 0 ; i < r.length ; i++)
{
CqlRow row = result.getRows().get(i);
r[i] = new ByteBuffer[row.getColumns().size()];
for (int j = 0 ; j < r[i].length ; j++)
r[i][j] = ByteBuffer.wrap(row.getColumns().get(j).getValue());
}
return r;
}
};
}
示例9: toThriftResult
import org.apache.cassandra.thrift.CqlResult; //导入依赖的package包/类
public CqlResult toThriftResult()
{
assert metadata.names != null;
String UTF8 = "UTF8Type";
CqlMetadata schema = new CqlMetadata(new HashMap<ByteBuffer, String>(),
new HashMap<ByteBuffer, String>(),
// The 2 following ones shouldn't be needed in CQL3
UTF8, UTF8);
for (int i = 0; i < metadata.columnCount; i++)
{
ColumnSpecification spec = metadata.names.get(i);
ByteBuffer colName = ByteBufferUtil.bytes(spec.name.toString());
schema.name_types.put(colName, UTF8);
AbstractType<?> normalizedType = spec.type instanceof ReversedType ? ((ReversedType)spec.type).baseType : spec.type;
schema.value_types.put(colName, normalizedType.toString());
}
List<CqlRow> cqlRows = new ArrayList<CqlRow>(rows.size());
for (List<ByteBuffer> row : rows)
{
List<Column> thriftCols = new ArrayList<Column>(metadata.columnCount);
for (int i = 0; i < metadata.columnCount; i++)
{
Column col = new Column(ByteBufferUtil.bytes(metadata.names.get(i).name.toString()));
col.setValue(row.get(i));
thriftCols.add(col);
}
// The key of CqlRow shoudn't be needed in CQL3
cqlRows.add(new CqlRow(ByteBufferUtil.EMPTY_BYTE_BUFFER, thriftCols));
}
CqlResult res = new CqlResult(CqlResultType.ROWS);
res.setRows(cqlRows).setSchema(schema);
return res;
}
示例10: process
import org.apache.cassandra.thrift.CqlResult; //导入依赖的package包/类
public static CqlResult process(String queryString, ThriftClientState clientState)
throws RequestValidationException, RequestExecutionException
{
logger.trace("CQL QUERY: {}", queryString);
return processStatement(getStatement(queryString),
new ExecutionContext(clientState, queryString, Collections.<ByteBuffer>emptyList()));
}
示例11: fromThriftCqlRow
import org.apache.cassandra.thrift.CqlResult; //导入依赖的package包/类
/**
* Create CFMetaData from thrift {@link CqlRow} that contains columns from schema_columnfamilies.
*
* @param columnsRes CqlRow containing columns from schema_columnfamilies.
* @return CFMetaData derived from CqlRow
*/
public static CFMetaData fromThriftCqlRow(CqlRow cf, CqlResult columnsRes)
{
UntypedResultSet.Row cfRow = new UntypedResultSet.Row(convertThriftCqlRow(cf));
List<Map<String, ByteBuffer>> cols = new ArrayList<>(columnsRes.rows.size());
for (CqlRow row : columnsRes.rows)
cols.add(convertThriftCqlRow(row));
UntypedResultSet colsRow = UntypedResultSet.create(cols);
return fromSchemaNoTriggers(cfRow, colsRow);
}
示例12: validate
import org.apache.cassandra.thrift.CqlResult; //导入依赖的package包/类
void validate(CqlResult rs)
{
switch (validationType)
{
case NOT_FAIL:
return;
case NON_ZERO:
if (rs.getRowsSize() == 0)
throw new IllegalStateException("Expected non-zero results");
break;
default:
throw new IllegalStateException("Unsupported validation type");
}
}
示例13: run
import org.apache.cassandra.thrift.CqlResult; //导入依赖的package包/类
public boolean run() throws Exception
{
CqlResult rs = client.execute_prepared_cql3_query(thriftId, partitions.get(0).getToken(), thriftArgs(), ThriftConversion.toThrift(cl));
validate(rs);
rowCount = rs.getRowsSize();
partitionCount = Math.min(1, rowCount);
return true;
}
示例14: toThriftResult
import org.apache.cassandra.thrift.CqlResult; //导入依赖的package包/类
public CqlResult toThriftResult()
{
assert metadata.names != null;
String UTF8 = "UTF8Type";
CqlMetadata schema = new CqlMetadata(new HashMap<ByteBuffer, String>(),
new HashMap<ByteBuffer, String>(),
// The 2 following ones shouldn't be needed in CQL3
UTF8, UTF8);
for (ColumnSpecification name : metadata.names)
{
ByteBuffer colName = ByteBufferUtil.bytes(name.toString());
schema.name_types.put(colName, UTF8);
AbstractType<?> normalizedType = name.type instanceof ReversedType ? ((ReversedType)name.type).baseType : name.type;
schema.value_types.put(colName, normalizedType.toString());
}
List<CqlRow> cqlRows = new ArrayList<CqlRow>(rows.size());
for (List<ByteBuffer> row : rows)
{
List<Column> thriftCols = new ArrayList<Column>(metadata.names.size());
for (int i = 0; i < metadata.names.size(); i++)
{
Column col = new Column(ByteBufferUtil.bytes(metadata.names.get(i).toString()));
col.setValue(row.get(i));
thriftCols.add(col);
}
// The key of CqlRow shoudn't be needed in CQL3
cqlRows.add(new CqlRow(ByteBufferUtil.EMPTY_BYTE_BUFFER, thriftCols));
}
CqlResult res = new CqlResult(CqlResultType.ROWS);
res.setRows(cqlRows).setSchema(schema);
return res;
}
示例15: listRelocations
import org.apache.cassandra.thrift.CqlResult; //导入依赖的package包/类
/**
* List pending token relocations for all nodes.
*
* @return
* @throws ShuffleError
*/
private Map<String, List<CqlRow>> listRelocations() throws ShuffleError
{
String cqlQuery = "SELECT token_bytes,requested_at FROM system.range_xfers";
Map<String, List<CqlRow>> results = new HashMap<String, List<CqlRow>>();
for (String host : getLiveNodes())
{
CqlResult result = executeCqlQuery(host, thriftPort, thriftFramed, cqlQuery);
results.put(host, result.getRows());
}
return results;
}