Search in sources :

Example 1 with MetadataNode

use of org.apache.asterix.metadata.MetadataNode in project asterixdb by apache.

the class IndexTupleTranslatorTest method test.

@Test
public void test() throws MetadataException, 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, Collections.emptyList(), false);
        Dataset dataset = new Dataset("test", "d1", "foo", "LogType", "CB", "MetaType", "DEFAULT_NG_ALL_NODES", "prefix", compactionPolicyProperties, details, Collections.emptyMap(), DatasetType.INTERNAL, 115, 0);
        Index index = new Index("test", "d1", "i1", IndexType.BTREE, Collections.singletonList(Collections.singletonList("row_id")), indicator == null ? null : Collections.singletonList(indicator), Collections.singletonList(BuiltinType.AINT64), -1, false, false, 0);
        MetadataNode mockMetadataNode = mock(MetadataNode.class);
        when(mockMetadataNode.getDatatype(any(), anyString(), anyString())).thenReturn(new Datatype("test", "d1", new ARecordType("", new String[] { "row_id" }, new IAType[] { BuiltinType.AINT64 }, true), true));
        when(mockMetadataNode.getDataset(any(), anyString(), anyString())).thenReturn(dataset);
        IndexTupleTranslator idxTranslator = new IndexTupleTranslator(null, mockMetadataNode, true);
        ITupleReference tuple = idxTranslator.getTupleFromMetadataEntity(index);
        Index deserializedIndex = idxTranslator.getMetadataEntityFromTuple(tuple);
        if (indicator == null) {
            Assert.assertEquals(Collections.singletonList(new Integer(0)), deserializedIndex.getKeyFieldSourceIndicators());
        } else {
            Assert.assertEquals(index.getKeyFieldSourceIndicators(), deserializedIndex.getKeyFieldSourceIndicators());
        }
    }
}
Also used : HashMap(java.util.HashMap) Dataset(org.apache.asterix.metadata.entities.Dataset) InternalDatasetDetails(org.apache.asterix.metadata.entities.InternalDatasetDetails) Index(org.apache.asterix.metadata.entities.Index) Matchers.anyString(org.mockito.Matchers.anyString) MetadataNode(org.apache.asterix.metadata.MetadataNode) Datatype(org.apache.asterix.metadata.entities.Datatype) ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference) ARecordType(org.apache.asterix.om.types.ARecordType) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 MetadataNode (org.apache.asterix.metadata.MetadataNode)1 Dataset (org.apache.asterix.metadata.entities.Dataset)1 Datatype (org.apache.asterix.metadata.entities.Datatype)1 Index (org.apache.asterix.metadata.entities.Index)1 InternalDatasetDetails (org.apache.asterix.metadata.entities.InternalDatasetDetails)1 ARecordType (org.apache.asterix.om.types.ARecordType)1 ITupleReference (org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1