DatasetTupleTranslator extends AbstractTupleTranslator<Dataset> { @Override public ITupleReference getTupleFromMetadataEntity(Dataset dataset) throws HyracksDataException { OrderedListBuilder listBuilder = new OrderedListBuilder(); ArrayBackedValueStorage itemValue = new ArrayBackedValueStorage(); String dataverseCanonicalName = dataset.getDataverseName().getCanonicalForm(); tupleBuilder.reset(); aString.setValue(dataverseCanonicalName); stringSerde.serialize(aString, tupleBuilder.getDataOutput()); tupleBuilder.addFieldEndOffset(); aString.setValue(dataset.getDatasetName()); stringSerde.serialize(aString, tupleBuilder.getDataOutput()); tupleBuilder.addFieldEndOffset(); recordBuilder.reset(MetadataRecordTypes.DATASET_RECORDTYPE); fieldValue.reset(); aString.setValue(dataverseCanonicalName); stringSerde.serialize(aString, fieldValue.getDataOutput()); recordBuilder.addField(MetadataRecordTypes.DATASET_ARECORD_DATAVERSENAME_FIELD_INDEX, fieldValue); fieldValue.reset(); aString.setValue(dataset.getDatasetName()); stringSerde.serialize(aString, fieldValue.getDataOutput()); recordBuilder.addField(MetadataRecordTypes.DATASET_ARECORD_DATASETNAME_FIELD_INDEX, fieldValue); fieldValue.reset(); aString.setValue(dataset.getItemTypeDataverseName().getCanonicalForm()); stringSerde.serialize(aString, fieldValue.getDataOutput()); recordBuilder.addField(MetadataRecordTypes.DATASET_ARECORD_DATATYPEDATAVERSENAME_FIELD_INDEX, fieldValue); fieldValue.reset(); aString.setValue(dataset.getItemTypeName()); stringSerde.serialize(aString, fieldValue.getDataOutput()); recordBuilder.addField(MetadataRecordTypes.DATASET_ARECORD_DATATYPENAME_FIELD_INDEX, fieldValue); fieldValue.reset(); aString.setValue(dataset.getDatasetType().toString()); stringSerde.serialize(aString, fieldValue.getDataOutput()); recordBuilder.addField(MetadataRecordTypes.DATASET_ARECORD_DATASETTYPE_FIELD_INDEX, fieldValue); fieldValue.reset(); aString.setValue(dataset.getNodeGroupName()); stringSerde.serialize(aString, fieldValue.getDataOutput()); recordBuilder.addField(MetadataRecordTypes.DATASET_ARECORD_GROUPNAME_FIELD_INDEX, fieldValue); writeCompactionPolicy(dataset.getDatasetType(), dataset.getCompactionPolicy(), dataset.getCompactionPolicyProperties(), listBuilder, itemValue); fieldValue.reset(); writeDatasetDetailsRecordType(recordBuilder, dataset, fieldValue.getDataOutput()); UnorderedListBuilder uListBuilder = new UnorderedListBuilder(); uListBuilder.reset((AUnorderedListType) MetadataRecordTypes.DATASET_RECORDTYPE .getFieldTypes()[MetadataRecordTypes.DATASET_ARECORD_HINTS_FIELD_INDEX]); for (Map.Entry<String, String> property : dataset.getHints().entrySet()) { String name = property.getKey(); String value = property.getValue(); itemValue.reset(); writeDatasetHintRecord(name, value, itemValue.getDataOutput()); uListBuilder.addItem(itemValue); } fieldValue.reset(); uListBuilder.write(fieldValue.getDataOutput(), true); recordBuilder.addField(MetadataRecordTypes.DATASET_ARECORD_HINTS_FIELD_INDEX, fieldValue); fieldValue.reset(); aString.setValue(Calendar.getInstance().getTime().toString()); stringSerde.serialize(aString, fieldValue.getDataOutput()); recordBuilder.addField(MetadataRecordTypes.DATASET_ARECORD_TIMESTAMP_FIELD_INDEX, fieldValue); fieldValue.reset(); aInt32.setValue(dataset.getDatasetId()); int32Serde.serialize(aInt32, fieldValue.getDataOutput()); recordBuilder.addField(MetadataRecordTypes.DATASET_ARECORD_DATASETID_FIELD_INDEX, fieldValue); fieldValue.reset(); aInt32.setValue(dataset.getPendingOp()); int32Serde.serialize(aInt32, fieldValue.getDataOutput()); recordBuilder.addField(MetadataRecordTypes.DATASET_ARECORD_PENDINGOP_FIELD_INDEX, fieldValue); writeOpenFields(dataset); recordBuilder.write(tupleBuilder.getDataOutput(), true); tupleBuilder.addFieldEndOffset(); tuple.reset(tupleBuilder.getFieldEndOffsets(), tupleBuilder.getByteArray()); return tuple; } protected  DatasetTupleTranslator(boolean getTuple); @Override ITupleReference getTupleFromMetadataEntity(Dataset dataset);  }
@Test public void test() throws AlgebricksException, IOException { Integer[] indicators = { 0, 1, null }; for (Integer indicator : indicators) { Map<String, String> compactionPolicyProperties = new HashMap<>(); compactionPolicyProperties.put("max-mergable-component-size", "1073741824"); compactionPolicyProperties.put("max-tolerance-component-count", "3"); InternalDatasetDetails details = new InternalDatasetDetails(FileStructure.BTREE, PartitioningStrategy.HASH, Collections.singletonList(Collections.singletonList("row_id")), Collections.singletonList(Collections.singletonList("row_id")), indicator == null ? null : Collections.singletonList(indicator), Collections.singletonList(BuiltinType.AINT64), false, null, null); Dataset dataset = new Dataset(DataverseName.createSinglePartName("test"), "log", DataverseName.createSinglePartName("foo"), "LogType", DataverseName.createSinglePartName("CB"), "MetaType", "DEFAULT_NG_ALL_NODES", "prefix", compactionPolicyProperties, details, Collections.emptyMap(), DatasetType.INTERNAL, 115, 0, CompressionManager.NONE); DatasetTupleTranslator dtTranslator = new DatasetTupleTranslator(true); ITupleReference tuple = dtTranslator.getTupleFromMetadataEntity(dataset); Dataset deserializedDataset = dtTranslator.getMetadataEntityFromTuple(tuple); Assert.assertEquals(dataset.getMetaItemTypeDataverseName(), deserializedDataset.getMetaItemTypeDataverseName()); Assert.assertEquals(dataset.getMetaItemTypeName(), deserializedDataset.getMetaItemTypeName()); if (indicator == null) { Assert.assertEquals(Collections.singletonList(new Integer(0)), ((InternalDatasetDetails) deserializedDataset.getDatasetDetails()).getKeySourceIndicator()); } else { Assert.assertEquals(((InternalDatasetDetails) dataset.getDatasetDetails()).getKeySourceIndicator(), ((InternalDatasetDetails) deserializedDataset.getDatasetDetails()).getKeySourceIndicator()); } } }