use of com.helger.genericode.v10.Row in project beam by apache.
the class BigtableIOTest method testReadingWithKeyRange.
/**
* Tests reading all rows using key ranges. Tests a prefix [), a suffix (], and a restricted range
* [] and that some properties hold across them.
*/
@Test
public void testReadingWithKeyRange() throws Exception {
final String table = "TEST-KEY-RANGE-TABLE";
final int numRows = 1001;
List<Row> testRows = makeTableData(table, numRows);
ByteKey startKey = ByteKey.copyFrom("key000000100".getBytes(StandardCharsets.UTF_8));
ByteKey endKey = ByteKey.copyFrom("key000000300".getBytes(StandardCharsets.UTF_8));
service.setupSampleRowKeys(table, numRows / 10, "key000000100".length());
// Test prefix: [beginning, startKey).
final ByteKeyRange prefixRange = ByteKeyRange.ALL_KEYS.withEndKey(startKey);
List<Row> prefixRows = filterToRange(testRows, prefixRange);
runReadTest(defaultRead.withTableId(table).withKeyRange(prefixRange), prefixRows);
// Test suffix: [startKey, end).
final ByteKeyRange suffixRange = ByteKeyRange.ALL_KEYS.withStartKey(startKey);
List<Row> suffixRows = filterToRange(testRows, suffixRange);
runReadTest(defaultRead.withTableId(table).withKeyRange(suffixRange), suffixRows);
// Test restricted range: [startKey, endKey).
final ByteKeyRange middleRange = ByteKeyRange.of(startKey, endKey);
List<Row> middleRows = filterToRange(testRows, middleRange);
runReadTest(defaultRead.withTableId(table).withKeyRange(middleRange), middleRows);
// ////// Size and content sanity checks //////////
// Prefix, suffix, middle should be non-trivial (non-zero,non-all).
assertThat(prefixRows, allOf(hasSize(lessThan(numRows)), hasSize(greaterThan(0))));
assertThat(suffixRows, allOf(hasSize(lessThan(numRows)), hasSize(greaterThan(0))));
assertThat(middleRows, allOf(hasSize(lessThan(numRows)), hasSize(greaterThan(0))));
// Prefix + suffix should be exactly all rows.
List<Row> union = Lists.newArrayList(prefixRows);
union.addAll(suffixRows);
assertThat("prefix + suffix = total", union, containsInAnyOrder(testRows.toArray(new Row[] {})));
// Suffix should contain the middle.
assertThat(suffixRows, hasItems(middleRows.toArray(new Row[] {})));
}
use of com.helger.genericode.v10.Row in project beam by apache.
the class BigtableIOTest method testReadingWithRuntimeParameterizedFilter.
/**
* Tests reading rows using a filter provided through ValueProvider.
*/
@Test
public void testReadingWithRuntimeParameterizedFilter() throws Exception {
final String table = "TEST-FILTER-TABLE";
final int numRows = 1001;
List<Row> testRows = makeTableData(table, numRows);
String regex = ".*17.*";
final KeyMatchesRegex keyPredicate = new KeyMatchesRegex(regex);
Iterable<Row> filteredRows = testRows.stream().filter(input -> {
verifyNotNull(input, "input");
return keyPredicate.apply(input.getKey());
}).collect(Collectors.toList());
RowFilter filter = RowFilter.newBuilder().setRowKeyRegexFilter(ByteString.copyFromUtf8(regex)).build();
service.setupSampleRowKeys(table, 5, 10L);
runReadTest(defaultRead.withTableId(table).withRowFilter(StaticValueProvider.of(filter)), Lists.newArrayList(filteredRows));
}
use of com.helger.genericode.v10.Row in project beam by apache.
the class BigtableServiceImplTest method testRead.
/**
* This test ensures that protobuf creation and interactions with {@link BigtableDataClient} work
* as expected.
*
* @throws IOException
* @throws InterruptedException
*/
@Test
public void testRead() throws IOException {
ByteKey start = ByteKey.copyFrom("a".getBytes(StandardCharsets.UTF_8));
ByteKey end = ByteKey.copyFrom("b".getBytes(StandardCharsets.UTF_8));
when(mockBigtableSource.getRanges()).thenReturn(Arrays.asList(ByteKeyRange.of(start, end)));
when(mockBigtableSource.getTableId()).thenReturn(StaticValueProvider.of(TABLE_ID));
@SuppressWarnings("unchecked") ResultScanner<Row> mockResultScanner = Mockito.mock(ResultScanner.class);
Row expectedRow = Row.newBuilder().setKey(ByteString.copyFromUtf8("a")).build();
when(mockResultScanner.next()).thenReturn(expectedRow).thenReturn(null);
when(mockBigtableDataClient.readRows(any(ReadRowsRequest.class))).thenReturn(mockResultScanner);
BigtableService.Reader underTest = new BigtableServiceImpl.BigtableReaderImpl(mockSession, mockBigtableSource);
underTest.start();
Assert.assertEquals(expectedRow, underTest.getCurrentRow());
Assert.assertFalse(underTest.advance());
underTest.close();
verify(mockResultScanner, times(1)).close();
verifyMetricWasSet("google.bigtable.v2.ReadRows", "ok", 1);
}
use of com.helger.genericode.v10.Row in project beam by apache.
the class BigtableServiceImplTest method testReadByteLimitBuffer.
/**
* This test checks that the buffer will stop filling up once the byte limit is reached. It will
* cancel the ScanHandler after reached the limit. This test completes one fill and contains one
* Row after the first buffer has been completed. The test cheaks the current available memory in
* the JVM and uses a percent of it to mock the original behavior. Range: [b00000, b00010)
*
* @throws IOException
*/
@Test
public void testReadByteLimitBuffer() throws IOException {
long segmentByteLimit = DEFAULT_ROW_SIZE * (SEGMENT_SIZE / 2);
int numOfRowsInsideBuffer = (int) (segmentByteLimit / DEFAULT_ROW_SIZE) + 1;
RowRange mockRowRange = generateRowRange(generateByteString(DEFAULT_PREFIX, 0), generateByteString(DEFAULT_PREFIX, SEGMENT_SIZE));
OngoingStubbing<?> stub = when(mockBigtableDataClient.readFlatRows(any(ReadRowsRequest.class), any()));
List<List<FlatRow>> expectedResults = ImmutableList.of(generateLargeSegmentResult(DEFAULT_PREFIX, 0, numOfRowsInsideBuffer), generateSegmentResult(DEFAULT_PREFIX, numOfRowsInsideBuffer, SEGMENT_SIZE - numOfRowsInsideBuffer), ImmutableList.of());
expectRowResults(stub, expectedResults);
BigtableService.Reader underTest = new BigtableServiceImpl.BigtableSegmentReaderImpl(mockSession, TABLE_ID, RowSet.newBuilder().addRowRanges(mockRowRange).build(), SEGMENT_SIZE, segmentByteLimit, RowFilter.getDefaultInstance(), mockCallMetric);
List<Row> actualResults = new ArrayList<>();
Assert.assertTrue(underTest.start());
do {
actualResults.add(underTest.getCurrentRow());
} while (underTest.advance());
Assert.assertEquals(expectedResults.stream().flatMap(Collection::stream).map(i -> FlatRowConverter.convert(i)).collect(Collectors.toList()), actualResults);
underTest.close();
Mockito.verify(mockCallMetric, Mockito.times(3)).call("ok");
}
use of com.helger.genericode.v10.Row in project molgenis-emx2 by molgenis.
the class PetStoreExample method populate.
public static void populate(Schema schema) {
final String shopviewer = "shopviewer";
final String shopmanager = "shopmanager";
final String shopowner = "shopowner";
// initual user
schema.addMember(shopmanager, "Manager");
schema.getDatabase().setUserPassword(shopmanager, shopmanager);
schema.addMember(shopviewer, "Viewer");
schema.getDatabase().setUserPassword(shopviewer, shopviewer);
schema.addMember(shopowner, "Owner");
schema.getDatabase().setUserPassword(shopowner, shopowner);
schema.getTable(CATEGORY).insert(new Row().set(NAME, "cat"), new Row().set(NAME, "dog"));
schema.getTable(TAG).insert(new Row().set(NAME, COLORS), new Row().set(NAME, "red").set(PARENT, COLORS), new Row().set(NAME, "green").set(PARENT, COLORS), new Row().set(NAME, SPECIES), new Row().set(NAME, MAMMALS).set(PARENT, SPECIES), new Row().set(NAME, "carnivorous mammals").set(PARENT, MAMMALS), new Row().set(NAME, "herbivorous mammals").set(PARENT, MAMMALS), new Row().set(NAME, "birds").set(PARENT, SPECIES));
schema.getTable(PET).insert(new Row().set(CATEGORY_COLUMN, "cat").set("name", "pooky").set(STATUS, "available").set(WEIGHT, 9.4), new Row().set(CATEGORY_COLUMN, "dog").set("name", "spike").set(STATUS, "sold").set("tags", "red,green").set(WEIGHT, 15.7));
schema.getTable(ORDER).insert(new Row().set(ORDER_ID, "1").set("pet", "pooky").set(QUANTITY, 1).set(PRICE, 9.99).set(COMPLETE, true).set(STATUS, "delivered"), new Row().set(ORDER_ID, "2").set("pet", "spike").set(PRICE, 14.99).set(QUANTITY, 7).set(COMPLETE, false).set(STATUS, "approved"));
schema.getTable(USER).insert(new Row().set("username", "bofke").set("pets", "spike,pooky"));
}
Aggregations