public List<ApplicationId> getAllAppVersionsAppIds(String namespaceId, String appId) { List<ApplicationId> appIds = new ArrayList<>(); for (MDSKey key : listKV(new MDSKey.Builder().add(TYPE_APP_META, namespaceId, appId).build(), ApplicationMeta.class).keySet()) { MDSKey.Splitter splitter = key.split(); splitter.skipBytes(); // skip recordType splitter.skipBytes(); // skip namespaceId splitter.skipBytes(); // skip appId String versionId = splitter.hasRemaining() ? splitter.getString() : ApplicationId.DEFAULT_VERSION; appIds.add(new NamespaceId(namespaceId).app(appId, versionId)); } return appIds; }
public List<ApplicationId> getAllAppVersionsAppIds(String namespaceId, String appId) { List<ApplicationId> appIds = new ArrayList<>(); for (MDSKey key : listKV(new MDSKey.Builder().add(TYPE_APP_META, namespaceId, appId).build(), ApplicationMeta.class).keySet()) { MDSKey.Splitter splitter = key.split(); splitter.skipBytes(); // skip recordType splitter.skipBytes(); // skip namespaceId splitter.skipBytes(); // skip appId String versionId = splitter.hasRemaining() ? splitter.getString() : ApplicationId.DEFAULT_VERSION; appIds.add(new NamespaceId(namespaceId).app(appId, versionId)); } return appIds; }
String value = keySplitter.getString(); MetadataEntity.Builder builder = MetadataEntity.builder(); while (keySplitter.hasRemaining()) { if (keySplitter.hasRemaining()) { value = keySplitter.getString(); } else {
String value = keySplitter.getString(); MetadataEntity.Builder builder = MetadataEntity.builder(); while (keySplitter.hasRemaining()) { if (keySplitter.hasRemaining()) { value = keySplitter.getString(); } else {
static String extractMetadataKey(byte[] rowKey) { MDSKey.Splitter keySplitter = new MDSKey(rowKey).split(); // The rowkey is // [rowPrefix][targetType][targetId][key] for value rows and // [rowPrefix][targetType][targetId][key][index] for value index rows // Skip rowPrefix keySplitter.skipBytes(); // Skip targetType keySplitter.skipString(); // targetId are key-value par so always in set of two. For value row we will end up with only string in end ([key]) // and for index row we will have two strings in end ([key][index]). String key = null; while (keySplitter.hasRemaining()) { key = keySplitter.getString(); if (keySplitter.hasRemaining()) { keySplitter.skipString(); } else { break; } } return key; }
static String extractMetadataKey(byte[] rowKey) { MDSKey.Splitter keySplitter = new MDSKey(rowKey).split(); // The rowkey is // [rowPrefix][targetType][targetId][key] for value rows and // [rowPrefix][targetType][targetId][key][index] for value index rows // Skip rowPrefix keySplitter.skipBytes(); // Skip targetType keySplitter.skipString(); // targetId are key-value par so always in set of two. For value row we will end up with only string in end ([key]) // and for index row we will have two strings in end ([key][index]). String key = null; while (keySplitter.hasRemaining()) { key = keySplitter.getString(); if (keySplitter.hasRemaining()) { keySplitter.skipString(); } else { break; } } return key; }
@Test public void getGetIntOverflow() { MDSKey.Builder builder = new MDSKey.Builder(); builder.add(1); builder.add(2); builder.add(3); MDSKey mdsKey = builder.build(); MDSKey.Splitter splitter = mdsKey.split(); Assert.assertEquals(1, splitter.getInt()); Assert.assertEquals(2, splitter.getInt()); Assert.assertEquals(3, splitter.getInt()); // splitter.getInt will fail due to there only being 3 parts in the key try { splitter.getInt(); Assert.fail(); } catch (BufferUnderflowException expected) { Assert.assertFalse(splitter.hasRemaining()); } }
@Test public void testSkipStringAndBytes() { MDSKey.Builder builder = new MDSKey.Builder(); builder.add("part1"); builder.add("part2"); builder.add("part3"); byte[] bytesToSkip = new byte[] { 0x1 }; byte[] bytesToCheck = new byte[] { 0x2 }; builder.add(bytesToSkip); builder.add(bytesToCheck); MDSKey mdsKey = builder.build(); MDSKey.Splitter splitter = mdsKey.split(); Assert.assertEquals("part1", splitter.getString()); splitter.skipString(); Assert.assertEquals("part3", splitter.getString()); splitter.skipBytes(); Assert.assertTrue(splitter.hasRemaining()); Assert.assertTrue(Bytes.equals(bytesToCheck, splitter.getBytes())); Assert.assertFalse(splitter.hasRemaining()); }
@Test public void testGetMDSIndexKey() { MDSKey mdsIndexKey = MetadataKey.createIndexRowKey(new ApplicationId("ns1", "app1").toMetadataEntity(), "key1", "value1"); MDSKey.Splitter split = mdsIndexKey.split(); // skip value key bytes split.skipBytes(); // assert target type Assert.assertEquals(MetadataEntity.APPLICATION, split.getString()); // assert key-value pairs Assert.assertEquals(MetadataEntity.NAMESPACE, split.getString()); Assert.assertEquals("ns1", split.getString()); Assert.assertEquals(MetadataEntity.APPLICATION, split.getString()); Assert.assertEquals("app1", split.getString()); Assert.assertEquals("key1", split.getString()); Assert.assertEquals("value1", split.getString()); Assert.assertFalse(split.hasRemaining()); } }
@Test public void testGetMDSValueKey() { MDSKey mdsValueKey = MetadataKey.createValueRowKey(new ApplicationId("ns1", "app1").toMetadataEntity(), "key1"); MDSKey.Splitter split = mdsValueKey.split(); // skip value key bytes split.skipBytes(); // assert target type is application Assert.assertEquals(MetadataEntity.APPLICATION, split.getString()); // assert key-value pairs Assert.assertEquals(MetadataEntity.NAMESPACE, split.getString()); Assert.assertEquals("ns1", split.getString()); Assert.assertEquals(MetadataEntity.APPLICATION, split.getString()); Assert.assertEquals("app1", split.getString()); Assert.assertEquals("key1", split.getString()); // asert that there is nothing more left in the key Assert.assertFalse(split.hasRemaining()); }