本文整理汇总了Java中org.apache.cassandra.cql3.UntypedResultSet类的典型用法代码示例。如果您正苦于以下问题:Java UntypedResultSet类的具体用法?Java UntypedResultSet怎么用?Java UntypedResultSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UntypedResultSet类属于org.apache.cassandra.cql3包,在下文中一共展示了UntypedResultSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: list
import org.apache.cassandra.cql3.UntypedResultSet; //导入依赖的package包/类
public Set<PermissionDetails> list(AuthenticatedUser performer, Set<Permission> permissions, IResource resource, String of)
throws RequestValidationException, RequestExecutionException
{
if (!performer.isSuper() && !performer.getName().equals(of))
throw new UnauthorizedException(String.format("You are not authorized to view %s's permissions",
of == null ? "everyone" : of));
Set<PermissionDetails> details = new HashSet<PermissionDetails>();
for (UntypedResultSet.Row row : process(buildListQuery(resource, of)))
{
if (row.has(PERMISSIONS))
{
for (String p : row.getSet(PERMISSIONS, UTF8Type.instance))
{
Permission permission = Permission.valueOf(p);
if (permissions.contains(permission))
details.add(new PermissionDetails(row.getString(USERNAME),
DataResource.fromName(row.getString(RESOURCE)),
permission));
}
}
}
return details;
}
示例2: from
import org.apache.cassandra.cql3.UntypedResultSet; //导入依赖的package包/类
public static TabularData from(UntypedResultSet resultSet) throws OpenDataException
{
TabularDataSupport result = new TabularDataSupport(TABULAR_TYPE);
for (UntypedResultSet.Row row : resultSet)
{
UUID id = row.getUUID(ITEM_NAMES[0]);
String ksName = row.getString(ITEM_NAMES[1]);
String cfName = row.getString(ITEM_NAMES[2]);
long compactedAt = row.getLong(ITEM_NAMES[3]);
long bytesIn = row.getLong(ITEM_NAMES[4]);
long bytesOut = row.getLong(ITEM_NAMES[5]);
Map<Integer, Long> rowMerged = row.getMap(ITEM_NAMES[6], Int32Type.instance, LongType.instance);
result.put(new CompositeDataSupport(COMPOSITE_TYPE, ITEM_NAMES,
new Object[]{ id.toString(), ksName, cfName, compactedAt, bytesIn, bytesOut,
"{" + FBUtilities.toString(rowMerged) + "}" }));
}
return result;
}
示例3: migrateIndexInterval
import org.apache.cassandra.cql3.UntypedResultSet; //导入依赖的package包/类
/** Migrates index_interval values to min_index_interval and sets index_interval to null */
private static void migrateIndexInterval()
{
for (UntypedResultSet.Row row : executeOnceInternal(String.format("SELECT * FROM system.%s", SCHEMA_COLUMNFAMILIES_CF)))
{
if (!row.has("index_interval"))
continue;
logger.debug("Migrating index_interval to min_index_interval");
CFMetaData table = CFMetaData.fromSchema(row);
String query = String.format("SELECT writetime(type) FROM system.%s WHERE keyspace_name = ? AND columnfamily_name = ?", SCHEMA_COLUMNFAMILIES_CF);
long timestamp = executeOnceInternal(query, table.ksName, table.cfName).one().getLong("writetime(type)");
try
{
table.toSchema(timestamp).apply();
}
catch (ConfigurationException e)
{
// shouldn't happen
}
}
}
示例4: migrateCachingOption
import org.apache.cassandra.cql3.UntypedResultSet; //导入依赖的package包/类
private static void migrateCachingOption()
{
for (UntypedResultSet.Row row : executeOnceInternal(String.format("SELECT * FROM system.%s", SCHEMA_COLUMNFAMILIES_CF)))
{
if (!row.has("caching"))
continue;
if (!CachingOptions.isLegacy(row.getString("caching")))
continue;
try
{
CachingOptions caching = CachingOptions.fromString(row.getString("caching"));
CFMetaData table = CFMetaData.fromSchema(row);
logger.info("Migrating caching option {} to {} for {}.{}", row.getString("caching"), caching.toString(), table.ksName, table.cfName);
String query = String.format("SELECT writetime(type) FROM system.%s WHERE keyspace_name = ? AND columnfamily_name = ?", SCHEMA_COLUMNFAMILIES_CF);
long timestamp = executeOnceInternal(query, table.ksName, table.cfName).one().getLong("writetime(type)");
table.toSchema(timestamp).apply();
}
catch (ConfigurationException e)
{
// shouldn't happen
}
}
}
示例5: filterOutRedundantRowsForSparse
import org.apache.cassandra.cql3.UntypedResultSet; //导入依赖的package包/类
private static Iterable<UntypedResultSet.Row> filterOutRedundantRowsForSparse(UntypedResultSet columnRows, boolean isSuper, boolean isCompound)
{
Collection<UntypedResultSet.Row> filteredRows = new ArrayList<>();
for (UntypedResultSet.Row columnRow : columnRows)
{
String kind = columnRow.getString("type");
if ("compact_value".equals(kind))
continue;
if ("clustering_key".equals(kind))
{
int position = columnRow.has("component_index") ? columnRow.getInt("component_index") : 0;
if (isSuper && position != 0)
continue;
if (!isSuper && !isCompound)
continue;
}
filteredRows.add(columnRow);
}
return filteredRows;
}
示例6: loadPaxosState
import org.apache.cassandra.cql3.UntypedResultSet; //导入依赖的package包/类
public static PaxosState loadPaxosState(ByteBuffer key, CFMetaData metadata)
{
String req = "SELECT * FROM system.%s WHERE row_key = ? AND cf_id = ?";
UntypedResultSet results = executeInternal(String.format(req, PAXOS_CF), key, metadata.cfId);
if (results.isEmpty())
return new PaxosState(key, metadata);
UntypedResultSet.Row row = results.one();
Commit promised = row.has("in_progress_ballot")
? new Commit(key, row.getUUID("in_progress_ballot"), ArrayBackedSortedColumns.factory.create(metadata))
: Commit.emptyCommit(key, metadata);
// either we have both a recently accepted ballot and update or we have neither
Commit accepted = row.has("proposal")
? new Commit(key, row.getUUID("proposal_ballot"), ColumnFamily.fromBytes(row.getBytes("proposal")))
: Commit.emptyCommit(key, metadata);
// either most_recent_commit and most_recent_commit_at will both be set, or neither
Commit mostRecent = row.has("most_recent_commit")
? new Commit(key, row.getUUID("most_recent_commit_at"), ColumnFamily.fromBytes(row.getBytes("most_recent_commit")))
: Commit.emptyCommit(key, metadata);
return new PaxosState(promised, accepted, mostRecent);
}
示例7: fromSchema
import org.apache.cassandra.cql3.UntypedResultSet; //导入依赖的package包/类
/**
* Deserialize only Keyspace attributes without nested ColumnFamilies
*
* @param row Keyspace attributes in serialized form
*
* @return deserialized keyspace without cf_defs
*/
public static KSMetaData fromSchema(Row row, Iterable<CFMetaData> cfms, UTMetaData userTypes)
{
UntypedResultSet.Row result = QueryProcessor.resultify("SELECT * FROM system.schema_keyspaces", row).one();
try
{
return new KSMetaData(result.getString("keyspace_name"),
AbstractReplicationStrategy.getClass(result.getString("strategy_class")),
fromJsonMap(result.getString("strategy_options")),
result.getBoolean("durable_writes"),
cfms,
userTypes);
}
catch (ConfigurationException e)
{
throw new RuntimeException(e);
}
}
示例8: testInvalidSearch
import org.apache.cassandra.cql3.UntypedResultSet; //导入依赖的package包/类
@Test
public void testInvalidSearch() throws IOException
{
Mutation rm;
rm = new Mutation("PerRowSecondaryIndex", ByteBufferUtil.bytes("k4"));
rm.add("Indexed1", Util.cellname("indexed"), ByteBufferUtil.bytes("foo"), 1);
rm.apply();
// test we can search:
UntypedResultSet result = QueryProcessor.executeInternal("SELECT * FROM \"PerRowSecondaryIndex\".\"Indexed1\" WHERE indexed = 'foo'");
assertEquals(1, result.size());
// test we can't search if the searcher doesn't validate the expression:
try
{
QueryProcessor.executeInternal("SELECT * FROM \"PerRowSecondaryIndex\".\"Indexed1\" WHERE indexed = 'invalid'");
fail("Query should have been invalid!");
}
catch (Exception e)
{
assertTrue(e instanceof InvalidRequestException || (e.getCause() != null && (e.getCause() instanceof InvalidRequestException)));
}
}
示例9: shouldImportCqlTable
import org.apache.cassandra.cql3.UntypedResultSet; //导入依赖的package包/类
@Test
/*
* The schema is
* CREATE TABLE cql_keyspace.table1 (k int PRIMARY KEY, v1 text, v2 int)
* */
public void shouldImportCqlTable() throws IOException, URISyntaxException
{
String cql_keyspace = "cql_keyspace";
String cql_table = "table1";
String jsonUrl = resourcePath("CQLTable.json");
File tempSS = tempSSTableFile(cql_keyspace, cql_table);
new SSTableImport(true).importJson(jsonUrl, cql_keyspace, cql_table, tempSS.getPath());
SSTableReader reader = SSTableReader.open(Descriptor.fromFilename(tempSS.getPath()));
Keyspace.open(cql_keyspace).getColumnFamilyStore(cql_table).addSSTable(reader);
UntypedResultSet result = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s", cql_keyspace, cql_table));
assertThat(result.size(), is(2));
assertThat(result, hasItem(withElements(1, "NY", 1980)));
assertThat(result, hasItem(withElements(2, "CA", 2014)));
reader.selfRef().release();
}
示例10: withElements
import org.apache.cassandra.cql3.UntypedResultSet; //导入依赖的package包/类
private static Matcher<UntypedResultSet.Row> withElements(final int key, final String v1, final int v2) {
return new TypeSafeMatcher<UntypedResultSet.Row>()
{
@Override
public boolean matchesSafely(Row input)
{
if (!input.has("k") || !input.has("v1") || !input.has("v2"))
return false;
return input.getInt("k") == key
&& input.getString("v1").equals(v1)
&& input.getInt("v2") == v2;
}
@Override
public void describeTo(Description description)
{
description.appendText(String.format("a row containing: %s, %s, %s", key, v1, v2));
}
};
}
示例11: loadDcRackInfo
import org.apache.cassandra.cql3.UntypedResultSet; //导入依赖的package包/类
/**
* Return a map of IP addresses containing a map of dc and rack info
*/
public static Map<InetAddress, Map<String,String>> loadDcRackInfo()
{
Map<InetAddress, Map<String, String>> result = new HashMap<InetAddress, Map<String, String>>();
for (UntypedResultSet.Row row : processInternal("SELECT peer, data_center, rack from system." + PEERS_CF))
{
InetAddress peer = row.getInetAddress("peer");
if (row.has("data_center") && row.has("rack"))
{
Map<String, String> dcRack = new HashMap<String, String>();
dcRack.put("data_center", row.getString("data_center"));
dcRack.put("rack", row.getString("rack"));
result.put(peer, dcRack);
}
}
return result;
}
示例12: hasRegularColumns
import org.apache.cassandra.cql3.UntypedResultSet; //导入依赖的package包/类
private static boolean hasRegularColumns(Iterable<UntypedResultSet.Row> columnRows)
{
for (UntypedResultSet.Row row : columnRows)
{
/*
* We need to special case and ignore the empty compact column (pre-3.0, COMPACT STORAGE, primary-key only tables),
* since deserializeKind() will otherwise just return a REGULAR.
* We want the proper EmptyType regular column to be added by addDefinitionForUpgrade(), so we need
* checkNeedsUpgrade() to return true in this case.
* See CASSANDRA-9874.
*/
if (isEmptyCompactValueColumn(row))
return false;
if (deserializeKind(row.getString("type")) == ColumnDefinition.Kind.REGULAR)
return true;
}
return false;
}
示例13: getSSTableReadMeter
import org.apache.cassandra.cql3.UntypedResultSet; //导入依赖的package包/类
/**
* Returns a RestorableMeter tracking the average read rate of a particular SSTable, restoring the last-seen rate
* from values in system.sstable_activity if present.
* @param keyspace the keyspace the sstable belongs to
* @param table the table the sstable belongs to
* @param generation the generation number for the sstable
*/
public static RestorableMeter getSSTableReadMeter(String keyspace, String table, int generation)
{
String cql = "SELECT * FROM %s WHERE keyspace_name='%s' and columnfamily_name='%s' and generation=%d";
UntypedResultSet results = processInternal(String.format(cql,
SSTABLE_ACTIVITY_CF,
keyspace,
table,
generation));
if (results.isEmpty())
return new RestorableMeter();
UntypedResultSet.Row row = results.one();
double m15rate = row.getDouble("rate_15m");
double m120rate = row.getDouble("rate_120m");
return new RestorableMeter(m15rate, m120rate);
}
示例14: replayAllFailedBatches
import org.apache.cassandra.cql3.UntypedResultSet; //导入依赖的package包/类
private void replayAllFailedBatches() throws ExecutionException, InterruptedException
{
if (!isReplaying.compareAndSet(false, true))
return;
logger.debug("Started replayAllFailedBatches");
try
{
for (UntypedResultSet.Row row : process("SELECT id, written_at FROM %s.%s", Keyspace.SYSTEM_KS, SystemKeyspace.BATCHLOG_CF))
if (System.currentTimeMillis() > row.getLong("written_at") + TIMEOUT)
replayBatch(row.getUUID("id"));
cleanup();
}
finally
{
isReplaying.set(false);
}
logger.debug("Finished replayAllFailedBatches");
}
示例15: readTableMetadata
import org.apache.cassandra.cql3.UntypedResultSet; //导入依赖的package包/类
private static CFMetaData readTableMetadata(String keyspaceName, String tableName)
{
String tableQuery = format("SELECT * FROM %s.%s WHERE keyspace_name = ? AND columnfamily_name = ?",
SystemKeyspace.NAME,
SystemKeyspace.LEGACY_COLUMNFAMILIES);
UntypedResultSet.Row tableRow = query(tableQuery, keyspaceName, tableName).one();
String columnsQuery = format("SELECT * FROM %s.%s WHERE keyspace_name = ? AND columnfamily_name = ?",
SystemKeyspace.NAME,
SystemKeyspace.LEGACY_COLUMNS);
UntypedResultSet columnRows = query(columnsQuery, keyspaceName, tableName);
String triggersQuery = format("SELECT * FROM %s.%s WHERE keyspace_name = ? AND columnfamily_name = ?",
SystemKeyspace.NAME,
SystemKeyspace.LEGACY_TRIGGERS);
UntypedResultSet triggerRows = query(triggersQuery, keyspaceName, tableName);
return decodeTableMetadata(tableRow, columnRows, triggerRows);
}