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; }
MDSKey.Splitter keySplitter = new MDSKey(rowKey).split(); keySplitter.skipBytes();
keySplitter.skipBytes();
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 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()); }
private String extractFieldName(byte[] columnKey) { MDSKey.Splitter keySplitter = new MDSKey(columnKey).split(); // The key is // [outgoing prefix (o)][EndPoint:Namespace][EndPoint:Name][fieldName] // skip prefix keySplitter.skipBytes(); // Skip namespace keySplitter.skipString(); // skip dataset name keySplitter.skipString(); return keySplitter.getString(); } }
private String extractFieldName(byte[] columnKey) { MDSKey.Splitter keySplitter = new MDSKey(columnKey).split(); // The key is // [outgoing prefix (o)][EndPoint:Namespace][EndPoint:Name][fieldName] // skip prefix keySplitter.skipBytes(); // Skip namespace keySplitter.skipString(); // skip dataset name keySplitter.skipString(); return keySplitter.getString(); } }
static String getNamespaceId(MDSKey key) { MDSKey.Splitter keySplitter = key.split(); // The rowkey is // [rowPrefix][targetType][targetId][key] for value rows and // [rowPrefix][targetType][targetId][key][index] for value index rows // so skip the first two. keySplitter.skipBytes(); keySplitter.skipString(); // We are getting the first part of [targetId] which always be the namespace id. return keySplitter.getString(); }
static NamespacedEntityId getNamespacedIdFromKey(String type, 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 // so skip the first two. keySplitter.skipBytes(); keySplitter.skipString(); return EntityIdKeyHelper.getTargetIdIdFromKey(keySplitter, type); }
static MetadataEntity extractMetadataEntityFromKey(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 // so skip the first keySplitter.skipBytes(); return getTargetIdIdFromKey(keySplitter); }
static String extractTargetType(byte[] rowKey) { MDSKey.Splitter keySplitter = new MDSKey(rowKey).split(); // skip rowPrefix keySplitter.skipBytes(); // return targetType return keySplitter.getString(); }
/** * skips the next String part in the splitter * @throws BufferUnderflowException if there is no String as expected */ public void skipString() { skipBytes(); }
static String extractTargetType(byte[] rowKey) { MDSKey.Splitter keySplitter = new MDSKey(rowKey).split(); // skip rowPrefix keySplitter.skipBytes(); // return targetType return keySplitter.getString(); }
static MetadataEntity extractMetadataEntityFromKey(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 // so skip the first keySplitter.skipBytes(); return getTargetIdIdFromKey(keySplitter); }
/** * skips the next String part in the splitter * @throws BufferUnderflowException if there is no String as expected */ public void skipString() { skipBytes(); }