Refine search
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 );
/** * Execute the query again and set the reuslts */ private void advanceIterator() { //run producing the values within a hystrix command. This way we'll time out if the read takes too long try { sourceIterator = rowQuery.execute().getResult().iterator(); } catch ( ConnectionException e ) { throw new RuntimeException( "Unable to get next page", e ); } } }
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 );
@Test public void testGetSingleKey() throws ConnectionException { for (char key = 'A'; key <= 'Z'; key++) { String keyName = Character.toString(key); OperationResult<ColumnList<String>> result = keyspace.prepareQuery(CF_STANDARD1).getKey(keyName).execute(); Assert.assertNotNull(result.getResult()); Assert.assertFalse(result.getResult().isEmpty()); } }
private void performSimpleRowQueryForRow(String rowKey, boolean rowDeleted, String expectedChar) throws Exception { ColumnList<String> result = keyspace.prepareQuery(CF_ACCOUNTS).getRow(rowKey).execute().getResult(); if (rowDeleted) { Assert.assertTrue(result.isEmpty()); } else { Assert.assertFalse(result.isEmpty()); Column<String> col = result.getColumnByName("user"); Assert.assertEquals("user" + expectedChar, col.getStringValue()); col = result.getColumnByName("pswd"); Assert.assertEquals("pswd" + expectedChar, col.getStringValue()); } }
@Test public void testHasValue() throws Exception { MutationBatch m = keyspace.prepareMutationBatch(); m.withRow(CF_USER_INFO, "acct1234") .putColumn("firstname", "john", null) .putColumn("lastname", "smith", null) .putColumn("address", "555 Elm St", null) .putColumn("age", 30, null) .putEmptyColumn("empty"); m.execute(); ColumnList<String> response = keyspace.prepareQuery(CF_USER_INFO).getRow("acct1234").execute().getResult(); Assert.assertEquals("firstname", response.getColumnByName("firstname").getName()); Assert.assertEquals("firstname", response.getColumnByName("firstname").getName()); Assert.assertEquals("john", response.getColumnByName("firstname").getStringValue()); Assert.assertEquals("john", response.getColumnByName("firstname").getStringValue()); Assert.assertEquals(true, response.getColumnByName("firstname").hasValue()); Assert.assertEquals(false, response.getColumnByName("empty").hasValue()); }
/** * Perform a single read operation * * @param key * @return * @throws Exception This could throw exceptions when there are exceptions in read path */ @Override public String readSingle(String key) throws Exception { ColumnList<Integer> result = keyspace.prepareQuery(this.CF) .setConsistencyLevel(ConsistencyLevel.valueOf(config.getReadConsistencyLevel())) .getRow(key) .execute().getResult(); if (!result.isEmpty()) { if (result.size() < (config.getColsPerRow())) { throw new Exception("Num Cols returned not ok " + result.size()); } } else { return CacheMiss; } return ResultOK; }
@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)); }
/** * Read from a {@link CassandraNode} using the Astyanax API. * @throws ConnectionException */ public void readData(String keyspaceName) throws ConnectionException { // Create context AstyanaxContext<Keyspace> context = newAstyanaxContextForKeyspace(keyspaceName); try { Keyspace keyspace = context.getEntity(); // Query data OperationResult<ColumnList<String>> query = keyspace.prepareQuery(sampleColumnFamily) .getKey("one") .execute(); assertEquals(query.getHost().getHostName(), hostname); assertTrue(query.getLatency() > 0L); ColumnList<String> columns = query.getResult(); assertEquals(columns.size(), 2); // Lookup columns in response by name String name = columns.getColumnByName("name").getStringValue(); assertEquals(name, "Alice"); // Iterate through the columns for (Column<String> c : columns) { assertTrue(ImmutableList.of("name", "company").contains(c.getName())); } } finally { context.shutdown(); } }
private void performRowSliceQueryWithAllColumns(boolean rowDeleted) throws Exception { List<String> keys = new ArrayList<String>(); for (char keyName = 'A'; keyName <= 'Z'; keyName++) { keys.add(Character.toString(keyName)); } int index = 0; Rows<String, String> rows = keyspace.prepareQuery(CF_ACCOUNTS).getRowSlice(keys).execute().getResult(); if (rowDeleted) { Assert.assertTrue(rows.isEmpty()); } else { Assert.assertFalse(rows.isEmpty()); for (com.netflix.astyanax.model.Row<String, String> row : rows) { Assert.assertEquals(keys.get(index),row.getKey()); ColumnList<String> cols = row.getColumns(); Assert.assertFalse(cols.isEmpty()); Column<String> col = cols.getColumnByName("user"); Assert.assertEquals("user" + keys.get(index), col.getStringValue()); col = cols.getColumnByName("pswd"); Assert.assertEquals("pswd" + keys.get(index), col.getStringValue()); index++; } } }
@Test public void testRowRangeAllColumnsQuery() throws Exception { String startToken = Murmur3Partitioner.get().getTokenForKey(StringSerializer.get().fromString("A")); String endToken = Murmur3Partitioner.get().getTokenForKey(StringSerializer.get().fromString("G")); keyspace.prepareQuery(CF_ROW_RANGE) .withCaching(true) .getRowRange(null, null, startToken, endToken, 10) .execute(); Rows<String, String> result = keyspace.prepareQuery(CF_ROW_RANGE) .withCaching(true) .getRowRange(null, null, startToken, endToken, 10) .execute() .getResult(); Assert.assertNotNull(result); Assert.assertTrue(3 == result.size()); for (Row<String, String> row : result) { Assert.assertTrue(26 == row.getColumns().size()); } }
public void read(int empId) { OperationResult<ColumnList<String>> result; try { result = keyspace.prepareQuery(EMP_CF) .getKey(empId) .execute(); ColumnList<String> cols = result.getResult(); logger.debug("read: isEmpty: "+cols.isEmpty()); for(Iterator<Column<String>> i = cols.iterator(); i.hasNext(); ) { Column<String> c = i.next(); Object v = null; logger.debug("- emp id: "+cols.getIntegerValue(COL_NAME_EMPID, null)); logger.debug("- dept: "+cols.getIntegerValue(COL_NAME_DEPTID, null)); logger.debug("- firstName: "+cols.getStringValue(COL_NAME_FIRST_NAME, null)); logger.debug("- lastName: "+cols.getStringValue(COL_NAME_LAST_NAME, null));
@Test public void runRowCopyTest() throws Exception { MutationBatch m = keyspace.prepareMutationBatch(); m.withRow(CF_ROW_COPY, 10).putColumn("c1", 1).putColumn("c2", 2); m.execute(); ColumnList<String> result = keyspace.prepareQuery(CF_ROW_COPY).getRow(10).execute().getResult(); Column<String> column = result.getColumnByIndex(0); Assert.assertEquals("c1", column.getName()); Assert.assertEquals(1, column.getIntegerValue()); column = result.getColumnByIndex(1); Assert.assertEquals("c2", column.getName()); Assert.assertEquals(2, column.getIntegerValue()); keyspace.prepareQuery(CF_ROW_COPY).getRow(10).copyTo(CF_ROW_COPY2, 11).execute(); ColumnList<String> result2 = keyspace.prepareQuery(CF_ROW_COPY2).getRow(11).execute().getResult(); column = result2.getColumnByIndex(0); Assert.assertEquals("c1", column.getName()); Assert.assertEquals(1, column.getIntegerValue()); column = result2.getColumnByIndex(1); Assert.assertEquals("c2", column.getName()); Assert.assertEquals(2, column.getIntegerValue()); } }
.prepareQuery(CF_DIRECT) .withCql("INSERT INTO astyanaxunittests.cfdirect (key, column1, value) VALUES (?,?,?)"); .prepareQuery(CF_DIRECT) .withRetryPolicy(new RetryNTimes(5)) .withCql("SELECT * FROM astyanaxunittests.cfdirect;") .execute(); Assert.assertTrue(result.getResult().hasRows()); Assert.assertEquals(10, result.getResult().getRows().size()); Assert.assertFalse(result.getResult().hasNumber()); Row<Integer, String> row = result.getResult().getRows().getRow(i); Assert.assertTrue(i == row.getKey()); Assert.assertEquals(3, row.getColumns().size()); Integer key = row.getColumns().getIntegerValue("key", null); Assert.assertTrue(Integer.valueOf(""+i) == key); String column1 = row.getColumns().getStringValue("column1", null); Assert.assertEquals(""+i, column1); Long value = row.getColumns().getLongValue("value", null); Assert.assertTrue(Long.valueOf(""+i) == value); .prepareQuery(CF_DIRECT) .withCql("SELECT count(*) FROM astyanaxunittests.cfdirect;").execute(); Assert.assertFalse(result.getResult().hasRows());
@Test public void testSingleColumnMutation() throws Exception { keyspace.prepareColumnMutation(CF_SINGLE_COLUMN, 1L, "1").putValue("11", null).execute(); keyspace.prepareColumnMutation(CF_SINGLE_COLUMN, 1L, "2").putValue("22", null).execute(); keyspace.prepareColumnMutation(CF_SINGLE_COLUMN, 1L, "3").putValue("33", null).execute(); ColumnList<String> result = keyspace.prepareQuery(CF_SINGLE_COLUMN).getRow(1L).execute().getResult(); Assert.assertTrue(3 == result.size()); Assert.assertEquals("11", result.getColumnByName("1").getStringValue()); Assert.assertEquals("22", result.getColumnByName("2").getStringValue()); Assert.assertEquals("33", result.getColumnByName("3").getStringValue()); keyspace.prepareColumnMutation(CF_SINGLE_COLUMN, 1L, "2").putEmptyColumn(null).execute(); keyspace.prepareColumnMutation(CF_SINGLE_COLUMN, 1L, "3").deleteColumn().execute(); result = keyspace.prepareQuery(CF_SINGLE_COLUMN).getRow(1L).execute().getResult(); Assert.assertTrue(2 == result.size()); Assert.assertEquals("11", result.getColumnByName("1").getStringValue()); Assert.assertNull(result.getColumnByName("2").getStringValue()); } }
@Test public void testSingleRowColumnSliceQueryWithCollection() throws Exception { for (int i=0; i<TestRowCount; i++) { ColumnList<String> result = keyspace.prepareQuery(CF_USER_INFO) .withCaching(true) .getRow("acct_" + i) .withColumnSlice("firstname", "lastname", "address", "age") .execute() .getResult(); Assert.assertNotNull(result); Assert.assertTrue(4 == result.size()); Assert.assertEquals("john_" + i, result.getColumnByName("firstname").getStringValue()); Assert.assertEquals("smith_" + i, result.getColumnByName("lastname").getStringValue()); Assert.assertEquals("john smith address " + i, result.getColumnByName("address").getStringValue()); Assert.assertTrue(30 + i == result.getColumnByName("age").getIntegerValue()); } }
private void testRowKeysWithAllColumns(boolean rowDeleted) throws Exception { Set<String> rowKeys = getRandomRowKeys(); Rows<String, String> rows = keyspace.prepareQuery(CF_COLUMN_RANGE_TEST).getRowSlice(rowKeys).execute().getResult(); if (rowDeleted) { Assert.assertTrue(rows.isEmpty()); return; } Assert.assertFalse(rows.isEmpty()); int rowKeysSize = rowKeys.size(); for (Row<String, String> row : rows) { boolean isPresent = rowKeys.remove(row.getKey()); Assert.assertTrue("Extraneous row: " + row.getKey(), isPresent); ColumnList<String> colList = row.getColumns(); Assert.assertEquals(26, colList.size()); for(int index=0; index<26; index++) { Column<String> col = colList.getColumnByIndex(index); Assert.assertTrue(String.valueOf((char)('a' + index)).equals(col.getName())); Assert.assertEquals(index + 1, col.getIntegerValue()); } } Assert.assertEquals(rowKeysSize, rows.size()); }
ColumnList<String> response = keyspace.prepareQuery(CF_USER_INFO).getRow("acct_" + i).execute().getResult(); Assert.assertTrue(response.isEmpty()); continue; Assert.assertFalse(response.isEmpty()); List<String> columnNameList = new ArrayList<String>(response.getColumnNames()); Collections.sort(columnNameList); Iterator<Column<String>> iter = response.iterator(); Iterator<String> columnNameIter = columnNames.iterator(); while (iter.hasNext()) {
@Test public void testRowKeysAllColumnsQuery() throws Exception { keyspace.prepareQuery(CF_USER_INFO) .withCaching(true) .getRowSlice("acct_0", "acct_1", "acct_2", "acct_3") .execute(); Rows<String, String> result = keyspace.prepareQuery(CF_USER_INFO) .withCaching(true) .getRowSlice("acct_4", "acct_5", "acct_6", "acct_7") .execute() .getResult(); Assert.assertNotNull(result); Assert.assertTrue(4 == result.size()); for (Row<String, String> row : result) { int rowNo = Integer.parseInt(row.getKey().substring("acct_".length())); Assert.assertTrue(rowNo >= 4); Assert.assertTrue(rowNo <= 7); Assert.assertTrue(13 == row.getColumns().size()); } }
.getKey(slabId) .withColumnRange(start, Constants.OPEN_SLAB_MARKER, false, Integer.MAX_VALUE)); boolean hasOpenSlabMarker = !eventColumns.isEmpty() && eventColumns.getColumnByIndex(eventColumns.size() - 1).getName() == Constants.OPEN_SLAB_MARKER; boolean stale = open && !recent && !hasOpenSlabMarker; if (stale) {