results = query.getRowSlice( keys ).withColumnSlice( Collections.singletonList( COLUMN_NAME )).execute() .getResult();
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); }
private void testColumnCountMultipleRowKeysAndAllColumns(boolean rowDeleted) throws Exception { Collection<String> rowKeys = getRandomRowKeys(); Map<String, Integer> columnCountsPerRowKey = keyspace .prepareQuery(CF_COLUMN_RANGE_TEST) .getRowSlice(rowKeys) .getColumnCounts() .execute().getResult(); Map<String, Integer> expected = new HashMap<String, Integer>(); if (!rowDeleted) { for (String key : rowKeys) { expected.put(key, 26); } } Assert.assertEquals("expected: " + expected + " colCount: " + columnCountsPerRowKey, expected, columnCountsPerRowKey); }
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); }
@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()); } }
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++; } } }
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()); }
.getRowSlice(rowKeys) .withColumnSlice(columns) .execute().getResult();
@Test public void testRowKeysColumnSetQuery() throws Exception { keyspace.prepareQuery(CF_USER_INFO) .withCaching(true) .getRowSlice("acct_0", "acct_1", "acct_2", "acct_3") .withColumnSlice("firstname", "lastname", "age") .execute(); Rows<String, String> result = keyspace.prepareQuery(CF_USER_INFO) .withCaching(true) .getRowSlice("acct_4", "acct_5", "acct_6", "acct_7") .withColumnSlice("firstname", "lastname", "age") .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(3 == row.getColumns().size()); } }
.getRowSlice(rowKeys) .withColumnRange(columns) .execute().getResult();
Rows<String, String> rows = keyspace.prepareQuery(CF_ACCOUNTS).getRowSlice(keys).withColumnSlice("user", "pswd").execute().getResult(); if (rowDeleted) { Assert.assertTrue(rows.isEmpty()); rows = keyspace.prepareQuery(CF_ACCOUNTS).getRowSlice(keys).withColumnSlice("user").execute().getResult(); if (rowDeleted) { Assert.assertTrue(rows.isEmpty()); rows = keyspace.prepareQuery(CF_ACCOUNTS).getRowSlice(keys).withColumnSlice("pswd").execute().getResult(); if (rowDeleted) { Assert.assertTrue(rows.isEmpty());
@Test public void testRowKeysColumnRangeQuery() throws Exception { keyspace.prepareQuery(CF_ROW_RANGE) .withCaching(true) .getRowSlice("A", "B", "C", "D") .withColumnRange(new CqlRangeBuilder<String>() .setStart("a") .setEnd("c") .build()) .execute(); Rows<String, String> result = keyspace.prepareQuery(CF_ROW_RANGE) .withCaching(true) .getRowSlice("E", "F", "G", "H") .withColumnRange(new CqlRangeBuilder<String>() .setStart("d") .setEnd("h") .build()) .execute() .getResult(); Assert.assertNotNull(result); Assert.assertTrue(4 == result.size()); for (Row<String, String> row : result) { int rowNo = row.getKey().charAt(0) - 'A'; Assert.assertTrue(rowNo >= 4); Assert.assertTrue(rowNo <= 7); Assert.assertTrue(5 == row.getColumns().size()); } }
result = keyspace.prepareQuery(keyIndexColumnFamily) .setConsistencyLevel(consistencyLevel) .getRowSlice(uniqueKeys.keySet()) .withColumnRange(metadataSerializer.buildRange() .greaterThanEquals((byte)MessageMetadataEntryType.Unique.ordinal())
Rows<String, String> result = keyspace.prepareQuery(CF_STANDARD1).getRowSlice("1", "2", "3").execute().getResult();