@Nullable private NamespacedEntityId toComponent(MDSKey.Splitter splitter, ProgramId program) { char marker = (char) splitter.getInt(); switch (marker) { case NONE_MARKER: return null; default: throw new IllegalStateException("Invalid row with component marker " + marker); } }
@Nullable private NamespacedEntityId toComponent(MDSKey.Splitter splitter, ProgramId program) { char marker = (char) splitter.getInt(); switch (marker) { case NONE_MARKER: return null; case FLOWLET_MARKER : return program.flowlet(splitter.getString()); default: throw new IllegalStateException("Invalid row with component marker " + marker); } }
private Relation toRelation(Row row) { Map<Character, EntityId> rowInfo = new HashMap<>(4); MDSKey.Splitter splitter = new MDSKey(row.getRow()).split(); char marker = (char) splitter.getInt(); LOG.trace("Got marker {}", marker); EntityId id1 = toEntityId(splitter, marker); LOG.trace("Got id1 {}", id1); rowInfo.put(marker, id1); splitter.skipLong(); // inverted time - not required for relation marker = (char) splitter.getInt(); LOG.trace("Got marker {}", marker); EntityId id2 = toEntityId(splitter, marker); LOG.trace("Got id2 {}", id1); rowInfo.put(marker, id2); RunId runId = RunIds.fromString(splitter.getString()); LOG.trace("Got runId {}", runId); AccessType accessType = AccessType.fromType((char) splitter.getInt()); LOG.trace("Got access type {}", accessType); DatasetId datasetInstance = (DatasetId) rowInfo.get(DATASET_MARKER); LOG.trace("Got datasetInstance {}", datasetInstance); ProgramId program = (ProgramId) rowInfo.get(PROGRAM_MARKER); LOG.trace("Got program {}", program); NamespacedEntityId component = toComponent(splitter, program); LOG.trace("Got component {}", component); return new Relation(datasetInstance, program, accessType, runId, component == null ? Collections.emptySet() : Collections.singleton(component)); }
char marker = (char) splitter.getInt(); LOG.trace("Got marker {}", marker); EntityId id1 = toEntityId(splitter, marker); marker = (char) splitter.getInt(); LOG.trace("Got marker {}", marker); EntityId id2 = toEntityId(splitter, marker); AccessType accessType = AccessType.fromType((char) splitter.getInt()); LOG.trace("Got access type {}", accessType);
switch (Objects.requireNonNull(type)) { case INTEGER: int intVal = splitter.getInt(); builder.put(key, intVal); keys.add(Fields.intField(key, intVal));
private RowKey parseRow(Row row) { ProgramId program; NamespacedEntityId data; RunId runId; MDSKey.Splitter splitter = new MDSKey(row.getRow()).split(); char marker = (char) splitter.getInt(); LOG.trace("Got marker {}", marker); switch (marker) { case PROGRAM_MARKER: program = (ProgramId) toEntityId(splitter, marker); splitter.skipLong(); // inverted start time marker = (char) splitter.getInt(); data = toEntityId(splitter, marker); // data runId = RunIds.fromString(splitter.getString()); return new RowKey(program, data, runId); case DATASET_MARKER: case STREAM_MARKER: data = toEntityId(splitter, marker); splitter.skipLong(); // inverted start time marker = (char) splitter.getInt(); program = (ProgramId) toEntityId(splitter, marker); // program runId = RunIds.fromString(splitter.getString()); return new RowKey(program, data, runId); default: throw new IllegalStateException("Invalid row with marker " + marker); } }
private RowKey parseRow(Row row) { ProgramId program; NamespacedEntityId data; RunId runId; MDSKey.Splitter splitter = new MDSKey(row.getRow()).split(); char marker = (char) splitter.getInt(); LOG.trace("Got marker {}", marker); switch (marker) { case PROGRAM_MARKER: program = (ProgramId) toEntityId(splitter, marker); splitter.skipLong(); // inverted start time marker = (char) splitter.getInt(); data = toEntityId(splitter, marker); // data runId = RunIds.fromString(splitter.getString()); return new RowKey(program, data, runId); case DATASET_MARKER: data = toEntityId(splitter, marker); splitter.skipLong(); // inverted start time marker = (char) splitter.getInt(); program = (ProgramId) toEntityId(splitter, marker); // program runId = RunIds.fromString(splitter.getString()); return new RowKey(program, data, runId); default: throw new IllegalStateException("Invalid row with marker " + marker); } }
@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 testAppend() { MDSKey mdsKey1 = new MDSKey.Builder().add("ab").add(3L).add(new byte[]{'x', 'y'}).build(); MDSKey mdsKey2 = new MDSKey.Builder().add("bd").add(5).append(mdsKey1).add(new byte[]{'z', 'z'}).build(); MDSKey mdsKey3 = new MDSKey.Builder().add(2).add(new byte[]{'w'}).append(mdsKey2).add(8L).build(); // Assert MDSKey.Splitter splitter = mdsKey3.split(); Assert.assertEquals(2, splitter.getInt()); Assert.assertArrayEquals(new byte[]{'w'}, splitter.getBytes()); Assert.assertEquals("bd", splitter.getString()); Assert.assertEquals(5, splitter.getInt()); Assert.assertEquals("ab", splitter.getString()); Assert.assertEquals(3L, splitter.getLong()); Assert.assertArrayEquals(new byte[]{'x', 'y'}, splitter.getBytes()); Assert.assertArrayEquals(new byte[]{'z', 'z'}, splitter.getBytes()); Assert.assertEquals(8L, splitter.getLong()); } }
@Test public void testSkipLongAndInt() { MDSKey.Builder builder = new MDSKey.Builder(); builder.add("part1"); builder.add(2L); builder.add(3L); builder.add(4); builder.add(5); MDSKey mdsKey = builder.build(); MDSKey.Splitter splitter = mdsKey.split(); Assert.assertEquals("part1", splitter.getString()); splitter.skipLong(); Assert.assertEquals(3L, splitter.getLong()); splitter.skipInt(); Assert.assertEquals(5, splitter.getInt()); }