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)); }
rowInfo.put(marker, id1); splitter.skipLong(); // inverted time - not required for relation
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); } }
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); } }
@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()); }
/** * Deserialize and return {@link ProgramRunId} from rowKey */ private ProgramRunId getProgramRunIdFromRowKey(byte[] rowKey) { MDSKey.Splitter splitter = new MDSKey(rowKey).split(); // get namespace String namespace = splitter.getString(); // skip timestamp splitter.skipLong(); // now read the programRunId fields, create and return ProgramRunId return new ProgramRunId(namespace, splitter.getString(), ProgramType.valueOf(splitter.getString()), splitter.getString(), splitter.getString()); } }
/** * Deserialize and return {@link ProgramRunId} from rowKey */ private ProgramRunId getProgramRunIdFromRowKey(byte[] rowKey) { MDSKey.Splitter splitter = new MDSKey(rowKey).split(); // get namespace String namespace = splitter.getString(); // skip timestamp splitter.skipLong(); // now read the programRunId fields, create and return ProgramRunId return new ProgramRunId(namespace, splitter.getString(), ProgramType.valueOf(splitter.getString()), splitter.getString(), splitter.getString()); } }