.withColumnRange( rangeBuilder.build() ); result = query.execute().getResult();
results = query.getRowSlice( keys ).withColumnSlice( Collections.singletonList( COLUMN_NAME )).execute() .getResult();
@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()); } }
/** * Queries for rows given an enumerated list of Cassandra row keys. */ private Iterator<Record> rowQuery(DeltaPlacement placement, List<Map.Entry<ByteBuffer, Key>> keys, ReadConsistency consistency) { // Build the list of row IDs to query for. List<ByteBuffer> rowIds = Lists.transform(keys, entryKeyFunction()); // Query for Delta & Compaction info, just the first 50 columns for now. final Rows<ByteBuffer, UUID> rows = execute(placement.getKeyspace() .prepareQuery(placement.getDeltaColumnFamily(), SorConsistencies.toAstyanax(consistency)) .getKeySlice(rowIds) .withColumnRange(_maxColumnsRange), "query %d keys from placement %s", rowIds.size(), placement.getName()); // Track metrics _randomReadMeter.mark(rowIds.size()); // Return an iterator that decodes the row results, avoiding pinning multiple decoded rows into memory at once. return decodeRows(keys, rows, _maxColumnsRange.getLimit(), consistency); }
private void testColumnCountMultipleRowKeysAndColumnRange(boolean rowDeleted) throws Exception { Collection<String> rowKeys = getRandomRowKeys(); // Get a random start column int rand = new Random().nextInt(26); char randCH = (char) ('a' + rand); String startCol = String.valueOf(randCH); Map<String, Integer> columnCountsPerRowKey = keyspace .prepareQuery(CF_COLUMN_RANGE_TEST) .getRowSlice(rowKeys) .withColumnRange(startCol, "z", false, -1) .getColumnCounts() .execute().getResult(); int charOffset = startCol.charAt(0) - 'a' + 1; int expectedColCount = 26 - charOffset + 1; Map<String, Integer> expected = new HashMap<String, Integer>(); if (!rowDeleted) { for (String key : rowKeys) { expected.put(key, expectedColCount); } } Assert.assertEquals("expected: " + expected + " colCount: " + columnCountsPerRowKey, expected, columnCountsPerRowKey); }
@Test public void testGetAllKeysPath() throws ConnectionException { LOG.info("Starting testGetAllKeysPath..."); List<String> keys = new ArrayList<String>(); for (char key = 'A'; key <= 'Z'; key++) { String keyName = Character.toString(key); keys.add(keyName); } OperationResult<Rows<String, String>> result = keyspace .prepareQuery(CF_STANDARD1) .getKeySlice(keys.toArray(new String[keys.size()])) .execute(); for (Row<String, String> row : result.getResult()) { System.out.println(row.getColumns().size()); } OperationResult<Map<String, Integer>> counts = keyspace .prepareQuery(CF_STANDARD1) .getKeySlice(keys.toArray(new String[keys.size()])) .getColumnCounts() .execute(); Assert.assertEquals(26, counts.getResult().size()); for (Entry<String, Integer> count : counts.getResult().entrySet()) { Assert.assertEquals(new Integer(26), count.getValue()); } LOG.info("Starting testGetAllKeysPath..."); }
private void testColumnCountRowRangeAndColumnSet(boolean rowDeleted) throws Exception { Collection<String> columns = getRandomColumns(new Random().nextInt(26) + 1); List<TestTokenRange> testRanges = TestUtils.getTestTokenRanges(); Map<String, Integer> expectedRowCounts = rowDeleted ? new HashMap<String, Integer>() : getExpectedRowCountsForTokenRanges(testRanges, columns.size()); Map<String, Integer> resultRowCounts = new HashMap<String, Integer>(); for (TestTokenRange testRange : testRanges) { Map<String, Integer> rowCounts = keyspace.prepareQuery(CF_COLUMN_RANGE_TEST) .getRowRange(null, null, testRange.startToken, testRange.endToken, -1) .withColumnSlice(columns) .getColumnCounts() .execute().getResult(); resultRowCounts.putAll(rowCounts); } Assert.assertEquals(expectedRowCounts, resultRowCounts); }
private void testReadMultipleRowKeysAllColumnsWithColumnCount(boolean rowDeleted) throws Exception { Map<Integer, Integer> result = keyspace.prepareQuery(CF_POPULATION) .getKeySlice(2001, 2002, 2003, 2004, 2005) .getColumnCounts() .execute().getResult(); Map<Integer, Integer> expected = new HashMap<Integer, Integer>(); if (!rowDeleted) { for (int year = 2001; year<= 2005; year++) { expected.put(year, 4); } } Assert.assertEquals(expected, result); }
private void testReadMultipleRowKeysWithAllColumns(boolean rowDeleted) throws Exception { Rows<Integer, Population> result = keyspace.prepareQuery(CF_POPULATION) .getKeySlice(2001, 2002, 2003, 2004, 2005) .execute().getResult(); if (rowDeleted) { Assert.assertTrue(result.isEmpty()); } else { checkRowResult(result, 2001, 5, SanDiego, SanFrancisco, NewYork, Seattle); } }
/** * Queries for rows given an enumerated list of Cassandra row keys. */ private Iterator<Record> rowQuery(DeltaPlacement placement, List<Map.Entry<ByteBuffer, Key>> keys, ReadConsistency consistency) { // Build the list of row IDs to query for. List<ByteBuffer> rowIds = Lists.transform(keys, entryKeyFunction()); // Query for Delta & Compaction info, just the first 50 columns for now. final Rows<ByteBuffer, UUID> rows = execute(placement.getKeyspace() .prepareQuery(placement.getDeltaColumnFamily(), SorConsistencies.toAstyanax(consistency)) .getKeySlice(rowIds) .withColumnRange(_maxColumnsRange), "query %d keys from placement %s", rowIds.size(), placement.getName()); // Track metrics _randomReadMeter.mark(rowIds.size()); // Return an iterator that decodes the row results, avoiding pinning multiple decoded rows into memory at once. return decodeRows(keys, rows, _maxColumnsRange.getLimit(), consistency); }
private void testColumnCountRowRangeAndColumnRange(boolean rowDeleted) throws Exception { // Get the random start column int rand = new Random().nextInt(26); char randCH = (char) ('a' + rand); String startColumn = String.valueOf(randCH); int expectedColCount = 'z' - startColumn.charAt(0) + 1; List<TestTokenRange> testRanges = TestUtils.getTestTokenRanges(); Map<String, Integer> expectedRowCounts = rowDeleted ? new HashMap<String, Integer>() : getExpectedRowCountsForTokenRanges(testRanges, expectedColCount); Map<String, Integer> resultRowCounts = new HashMap<String, Integer>(); for (TestTokenRange testRange : testRanges) { Map<String, Integer> rowCounts = keyspace.prepareQuery(CF_COLUMN_RANGE_TEST) .getRowRange(null, null, testRange.startToken, testRange.endToken, -1) .withColumnRange(startColumn, "z", false, -1) .getColumnCounts() .execute().getResult(); resultRowCounts.putAll(rowCounts); } Assert.assertEquals(expectedRowCounts, resultRowCounts); }
private void testColumnCountMultipleRowKeysAndColumnSet(boolean rowDeleted) throws Exception { Collection<String> rowKeys = getRandomRowKeys(); Collection<String> columns = getRandomColumns(new Random().nextInt(26) + 1); Map<String, Integer> columnCountsPerRowKey = keyspace .prepareQuery(CF_COLUMN_RANGE_TEST) .getRowSlice(rowKeys) .withColumnSlice(columns) .getColumnCounts() .execute().getResult(); Map<String, Integer> expected = new HashMap<String, Integer>(); if (!rowDeleted) { for (String key : rowKeys) { expected.put(key, columns.size()); } } Assert.assertEquals("expected: " + expected + " colCount: " + columnCountsPerRowKey, expected, columnCountsPerRowKey); }
private void testColumnCountRowRangeAndAllColumns(boolean rowDeleted) throws Exception { List<TestTokenRange> testRanges = TestUtils.getTestTokenRanges(); Map<String, Integer> expectedRowCounts = rowDeleted ? new HashMap<String, Integer>() : getExpectedRowCountsForTokenRanges(testRanges, 26); Map<String, Integer> resultRowCounts = new HashMap<String, Integer>(); for (TestTokenRange testRange : testRanges) { Map<String, Integer> rowCounts = keyspace.prepareQuery(CF_COLUMN_RANGE_TEST) .getRowRange(null, null, testRange.startToken, testRange.endToken, -1) .getColumnCounts() .execute().getResult(); resultRowCounts.putAll(rowCounts); } Assert.assertEquals(expectedRowCounts, resultRowCounts); }
.withColumnRange( rangeBuilder.build() ); result = query.execute().getResult();
.withColumnSlice( COL_VALUE ).execute().getResult();
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++; } } }
/** * Queries for rows given an enumerated list of Cassandra row keys. */ private Iterator<Record> rowQuery(DeltaPlacement placement, List<Map.Entry<ByteBuffer, Key>> keys, ReadConsistency consistency) { // Build the list of row IDs to query for. List<ByteBuffer> rowIds = Lists.transform(keys, entryKeyFunction()); // Query for Delta & Compaction info, just the first 50 columns for now. final Rows<ByteBuffer, DeltaKey> rows = execute(placement.getKeyspace() .prepareQuery(placement.getBlockedDeltaColumnFamily(), SorConsistencies.toAstyanax(consistency)) .getKeySlice(rowIds) .withColumnRange(_maxColumnsRange), "query %d keys from placement %s", rowIds.size(), placement.getName()); // Track metrics _randomReadMeter.mark(rowIds.size()); // Return an iterator that decodes the row results, avoiding pinning multiple decoded rows into memory at once. return decodeRows(keys, rows, _maxColumnsRange.getLimit(), consistency); }
.withColumnRange(compSerializer.buildRange() .withPrefix("CA") .build()) .getColumnCounts() .execute().getResult(); .withColumnRange(compSerializer.buildRange() .withPrefix("CA") .greaterThan("San Diego") .build()) .getColumnCounts() .execute().getResult(); .withColumnRange(compSerializer.buildRange() .withPrefix("WA") .withPrefix("Seattle") .withPrefix(40000) .build()) .getColumnCounts() .execute().getResult();
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); }
.withColumnRange( maxVersion, null, false, 1 ).execute().getResult() .iterator();