Refine search
@Override public String getStatusMessage(final String pluginName) { final ScopedRowKey<String> rowKey = ScopedRowKey.fromKey( STATIC_ID, pluginName); try { return keyspace.prepareQuery( CF_MIGRATION_INFO ).getKey( rowKey ).getColumn( COL_STATUS_MESSAGE ) .execute().getResult().getStringValue(); } //swallow, it doesn't exist catch ( NotFoundException nfe ) { return null; } catch ( ConnectionException e ) { throw new DataMigrationException( "Unable to retrieve status", e ); } }
keyspace.prepareQuery( cf ).setConsistencyLevel( consistencyLevel ).getKeySlice( rowKeys ) .withColumnRange( rangeBuilder.build() ); result = query.execute().getResult();
@Override public KeyIterator getKeys(KeyRangeQuery query, StoreTransaction txh) throws BackendException { // this query could only be done when byte-ordering partitioner is used // because Cassandra operates on tokens internally which means that even contiguous // range of keys (e.g. time slice) with random partitioner could produce disjoint set of tokens // returning ambiguous results to the user. Partitioner partitioner = storeManager.getPartitioner(); if (partitioner != Partitioner.BYTEORDER) throw new PermanentBackendException("getKeys(KeyRangeQuery could only be used with byte-ordering partitioner."); ByteBuffer start = query.getKeyStart().asByteBuffer(), end = query.getKeyEnd().asByteBuffer(); RowSliceQuery rowSlice = keyspace.prepareQuery(columnFamily) .setConsistencyLevel(getTx(txh).getReadConsistencyLevel().getAstyanax()) .withRetryPolicy(retryPolicy.duplicate()) .getKeyRange(start, end, null, null, Integer.MAX_VALUE); // Astyanax is bad at builder pattern :( rowSlice.withColumnRange(query.getSliceStart().asByteBuffer(), query.getSliceEnd().asByteBuffer(), false, query.getLimit()); // Omit final the query's keyend from the result, if present in result final Rows<ByteBuffer, ByteBuffer> r; try { r = ((OperationResult<Rows<ByteBuffer, ByteBuffer>>) rowSlice.execute()).getResult(); } catch (ConnectionException e) { throw new TemporaryBackendException(e); } Iterator<Row<ByteBuffer, ByteBuffer>> i = Iterators.filter(r.iterator(), new KeySkipPredicate(query.getKeyEnd().asByteBuffer())); return new RowIterator(i, query); }
@Override public Optional<Long> getMaxVersion( final ApplicationScope scope, final Id node ) { ValidationUtils.validateApplicationScope( scope ); ValidationUtils.verifyIdentity( node ); ColumnFamilyQuery<ScopedRowKey<Id>, Boolean> query = keyspace.prepareQuery( GRAPH_DELETE ).setConsistencyLevel( fig.getReadCL() ); Column<Boolean> result = null; try { result = query.getKey( ScopedRowKey.fromKey( scope.getApplication(), node ) ).getColumn( COLUMN_NAME ).execute() .getResult(); } catch(NotFoundException nfe){ //swallow, there's just no column return Optional.absent(); } catch ( ConnectionException e ) { throw new RuntimeException( "Unable to connect to casandra", e ); } return Optional.of( result.getLongValue() ); }
keyspace.prepareQuery( GRAPH_DELETE ).setConsistencyLevel( fig.getReadCL() ); results = query.getRowSlice( keys ).withColumnSlice( Collections.singletonList( COLUMN_NAME )).execute() .getResult(); Column<Boolean> column = row.getColumns().getColumnByName( COLUMN_NAME ); versions.put( row.getKey().getKey(), column.getLongValue() );
@Override public Health getHealth() { try { ColumnFamily<String, String> CF_SYSTEM_LOCAL = new ColumnFamily<String, String>( "system.local", StringSerializer.get(), StringSerializer.get(), StringSerializer.get() ); OperationResult<CqlResult<String, String>> result = keyspace.prepareQuery( CF_SYSTEM_LOCAL ) .setConsistencyLevel(ConsistencyLevel.CL_ONE) .withCql( "SELECT now() FROM system.local;" ) .execute(); if ( result.getResult().getRows().size() > 0 ) { return Health.GREEN; } } catch ( ConnectionException ex ) { logger.error( "Error connecting to Cassandra", ex ); } return Health.RED; } }
if ( keyspace.describeKeyspace().getColumnFamily( CF_NAME ) == null ) { keyspace.createColumnFamily( testCf, null ); MutationBatch batch = keyspace.prepareMutationBatch(); Column<String> col = keyspace.prepareQuery( testCf ).getKey( key ).getColumn( colname ).execute().getResult(); assertEquals( colname, col.getName() ); assertEquals( colvalue, col.getStringValue() ); keyspace.prepareQuery( testCf ).getKey( key ).getColumn( colname ).execute().getResult(); batch.execute(); col = keyspace.prepareQuery( testCf ).getKey( key ).getColumn( colname ).execute().getResult(); assertEquals( colname, col.getName() ); assertEquals( colvalue, col.getStringValue() ); col = keyspace.prepareQuery( testCf ).getKey( key ).getColumn( colname ).execute().getResult(); assertEquals( colname, col.getName() ); keyspace.prepareQuery( testCf ).getKey( key ).getColumn( colname ).execute().getResult();
if ( keyspace.describeKeyspace().getColumnFamily( "test" ) == null ) { keyspace.createColumnFamily( cf, new HashMap<String, Object>() ); final long timestamp = 100l; MutationBatch batch = keyspace.prepareMutationBatch().withConsistencyLevel( ConsistencyLevel.CL_QUORUM ) .setTimestamp( timestamp ); Column<String> column = keyspace.prepareQuery( cf ).getKey( rowKey ).getColumn( colName ).execute().getResult(); assertEquals( colName, column.getName() ); assertTrue( column.getBooleanValue() ); column = keyspace.prepareQuery( cf ).getKey( rowKey ).getColumn( colName ).execute().getResult(); fail( "I shouldn't return a value" ); column = keyspace.prepareQuery( cf ).getKey( rowKey ).getColumn( colName ).execute().getResult(); fail( "I shouldn't return a value" );
private void verifyPresent(Keyspace ks, int rowKey) throws ConnectionException { ColumnList<Long> result = ks.prepareQuery(CF_DUAL_WRITES).getRow(rowKey).execute().getResult(); if (result.isEmpty()) { throw new RuntimeException("Row: " + rowKey + " missing from keysapce: " + ks.getKeyspaceName()); } else { System.out.println("Verified Row: " + rowKey + " present in ks: " + ks.getKeyspaceName()); } }
@Test public void testCqlCount() throws Exception { LOG.info("CQL Test"); OperationResult<CqlResult<String, String>> result = keyspace .prepareQuery(CF_STANDARD1) .withCql("SELECT count(*) FROM astyanaxunittests.standard1 where KEY='A';") .execute(); long count = result.getResult().getNumber(); LOG.info("CQL Count: " + count); Assert.assertTrue(0 <= count); }
latestEntityColumns = keyspace.prepareQuery( CF_ENTITY_LOG ).getKeySlice( rowKeys ) .withColumnRange( maxVersion, null, false, 1 ).execute().getResult() .iterator(); if ( columns.size() == 0 ) { continue; final Column<UUID> column = columns.getColumnByIndex( 0 ); final UUID version = column.getName(); final StageStatus stageStatus = column.getValue( SER );
return keyspace.prepareQuery( CF_ENTITY_DATA ).getKeySlice( scopedRowKeys ) .withColumnSlice( COL_VALUE ).execute().getResult(); if ( columns.size() == 0 ) { continue; final Column<Boolean> column = columns.getColumnByIndex( 0 );
private void testSingleRowAllColumnsColumnCountQuery(boolean rowDeleted) throws Exception { int expected = rowDeleted ? 0 : columnNames.size(); for (int i=0; i<TestRowCount; i++) { int count = keyspace.prepareQuery(CF_USER_INFO).getRow("acct_" + i).getCount().execute().getResult().intValue(); Assert.assertEquals(expected, count); } }
@Override public ByteBuffer readChunk(String objectName, int chunkId) throws Exception { return keyspace.prepareQuery(cf).setConsistencyLevel(readConsistencyLevel).withRetryPolicy(retryPolicy) .getKey(getRowKey(objectName, chunkId)).getColumn(getColumnName(Columns.DATA)).execute().getResult() .getByteBufferValue(); }
@Override public int getSystemVersion() { try { return keyspace.prepareQuery( CF_MIGRATION_INFO ).getKey( LEGACY_ROW_KEY ).getColumn( COLUMN_VERSION ) .execute().getResult().getIntegerValue(); } //swallow, it doesn't exist catch ( NotFoundException nfe ) { return 0; } catch ( ConnectionException e ) { throw new DataMigrationException( "Unable to retrieve status", e ); } }
throw new PermanentBackendException("This operation is only allowed when random partitioner (md5 or murmur3) is used."); AllRowsQuery allRowsQuery = keyspace.prepareQuery(columnFamily).getAllRows(); result = ((OperationResult<Rows<ByteBuffer, ByteBuffer>>) op).getResult(); } catch (ConnectionException e) { throw new PermanentBackendException(e);
@Override public ObjectMetadata readMetadata(String objectName) throws Exception, NotFoundException { ColumnList<String> columns = keyspace.prepareQuery(cf).getKey(objectName).execute().getResult(); if (columns.isEmpty()) { throw new NotFoundException(objectName); } return new ObjectMetadata().setObjectSize(columns.getLongValue(getColumnName(Columns.OBJECTSIZE), null)) .setChunkSize(columns.getIntegerValue(getColumnName(Columns.CHUNKSIZE), null)) .setChunkCount(columns.getIntegerValue(getColumnName(Columns.CHUNKCOUNT), null)) .setAttributes(columns.getStringValue(getColumnName(Columns.ATTRIBUTES), null)); }
@Test public void testColumnSlice() throws ConnectionException { OperationResult<ColumnList<String>> r1 = keyspace .prepareQuery(CF_STANDARD1).getKey("A") .withColumnSlice("a", "b").execute(); Assert.assertEquals(2, r1.getResult().size()); }
private void testReadRowRangeAllColumnsWithColumnCount(boolean rowDeleted) throws Exception { List<TestRange> testRanges = getTestRanges(); TestRange range = testRanges.get(0); Map<Integer, Integer> result = keyspace.prepareQuery(CF_POPULATION) .getKeyRange(null, null, range.start, range.end, 100) .getColumnCounts() .execute().getResult(); Map<Integer, Integer> expected = new HashMap<Integer, Integer>(); if (!rowDeleted) { for (Integer year : range.expectedRowKeys) { expected.put(year, 4); } } Assert.assertEquals(expected, result); }
@Test public void testGetSingleKeyAsync() throws Exception { Future<OperationResult<ColumnList<String>>> future = keyspace.prepareQuery(CF_STANDARD1).getKey("A").executeAsync(); ColumnList<String> result = future.get(1000, TimeUnit.MILLISECONDS).getResult(); Assert.assertFalse(result.isEmpty()); }