Search in sources :

Example 16 with MetadataEntry

use of io.cdap.cdap.data2.metadata.dataset.MetadataEntry in project cdap by caskdata.

the class SchemaIndexerTest method testInvalidSchema.

@Test
public void testInvalidSchema() {
    String invalidSchema = "an invalid schema";
    Set<String> expected = ImmutableSet.of("an", "invalid", "schema", "an invalid schema");
    SchemaIndexer indexer = new SchemaIndexer();
    DatasetId datasetInstance = new DatasetId("ns1", "ds1");
    Set<String> actual = indexer.getIndexes(new MetadataEntry(datasetInstance, KEY, invalidSchema));
    Assert.assertEquals(addKeyPrefixAndPropertiesField(expected), actual);
}
Also used : MetadataEntry(io.cdap.cdap.data2.metadata.dataset.MetadataEntry) DatasetId(io.cdap.cdap.proto.id.DatasetId) Test(org.junit.Test)

Example 17 with MetadataEntry

use of io.cdap.cdap.data2.metadata.dataset.MetadataEntry in project cdap by caskdata.

the class SchemaIndexerTest method testSimpleRecord.

@Test
public void testSimpleRecord() throws Exception {
    Schema simpleSchema = Schema.recordOf("record1", // String x
    Schema.Field.of("x", Schema.of(Schema.Type.STRING)), // String[] y
    Schema.Field.of("y", Schema.arrayOf(Schema.of(Schema.Type.STRING))), // Map<byte[],double> z
    Schema.Field.of("z", Schema.mapOf(Schema.of(Schema.Type.BYTES), Schema.of(Schema.Type.DOUBLE))));
    Set<String> expected = ImmutableSet.of("record1", "record1:RECORD", "x", "x:STRING", "y", "y:ARRAY", "z", "z:MAP");
    SchemaIndexer indexer = new SchemaIndexer();
    DatasetId datasetInstance = new DatasetId("ns1", "ds1");
    Set<String> actual = indexer.getIndexes(new MetadataEntry(datasetInstance, KEY, simpleSchema.toString()));
    Assert.assertEquals(addKeyPrefix(expected), actual);
}
Also used : Schema(co.cask.cdap.api.data.schema.Schema) MetadataEntry(co.cask.cdap.data2.metadata.dataset.MetadataEntry) DatasetId(co.cask.cdap.proto.id.DatasetId) Test(org.junit.Test)

Example 18 with MetadataEntry

use of io.cdap.cdap.data2.metadata.dataset.MetadataEntry in project cdap by caskdata.

the class InvertedValueIndexerTest method testSimple.

@Test
public void testSimple() {
    List<String> inputs = ImmutableList.of("134342", "435ert5", "trdfrw", "_bfcfd", "r34_r3", "cgsdfgs)dfd", "gfsgfd2345245234", "dfsgs");
    // expected is reverse sorted input
    List<String> expected = new ArrayList<>(inputs);
    Collections.sort(expected, Collections.<String>reverseOrder());
    List<String> invertedIndexes = new ArrayList<>();
    for (String input : inputs) {
        invertedIndexes.add(Iterables.getOnlyElement(indexer.getIndexes(new MetadataEntry(ns, "dontcare", input))));
    }
    // inverted indexes sorted in ascending order
    Collections.sort(invertedIndexes);
    for (int i = 0; i < invertedIndexes.size(); i++) {
        String invertedIndex = invertedIndexes.get(i);
        String original = Iterables.getOnlyElement(indexer.getIndexes(new MetadataEntry(ns, "dontcare", invertedIndex)));
        Assert.assertEquals(expected.get(i), original);
    }
}
Also used : ArrayList(java.util.ArrayList) MetadataEntry(io.cdap.cdap.data2.metadata.dataset.MetadataEntry) Test(org.junit.Test)

Example 19 with MetadataEntry

use of io.cdap.cdap.data2.metadata.dataset.MetadataEntry in project cdap by caskdata.

the class DefaultValueIndexerTest method testSimpleProperty.

@Test
public void testSimpleProperty() {
    MetadataEntry entry = new MetadataEntry(NamespaceId.DEFAULT.app("a"), "key", "val");
    Set<String> expected = new HashSet<>();
    expected.add("val");
    expected.add("key:val");
    expected.add("properties:key");
    Assert.assertEquals(expected, indexer.getIndexes(entry));
}
Also used : MetadataEntry(io.cdap.cdap.data2.metadata.dataset.MetadataEntry) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 20 with MetadataEntry

use of io.cdap.cdap.data2.metadata.dataset.MetadataEntry in project cdap by caskdata.

the class SchemaIndexerTest method testSimpleSchema.

@Test
public void testSimpleSchema() {
    Schema simpleSchema = Schema.of(Schema.Type.INT);
    Set<String> expected = Collections.singleton("properties:schema");
    SchemaIndexer indexer = new SchemaIndexer();
    DatasetId datasetInstance = new DatasetId("ns1", "ds1");
    Set<String> actual = indexer.getIndexes(new MetadataEntry(datasetInstance, KEY, simpleSchema.toString()));
    Assert.assertEquals(expected, actual);
}
Also used : Schema(io.cdap.cdap.api.data.schema.Schema) MetadataEntry(io.cdap.cdap.data2.metadata.dataset.MetadataEntry) DatasetId(io.cdap.cdap.proto.id.DatasetId) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)16 MetadataEntry (io.cdap.cdap.data2.metadata.dataset.MetadataEntry)13 MetadataEntry (co.cask.cdap.data2.metadata.dataset.MetadataEntry)7 HashSet (java.util.HashSet)7 ArrayList (java.util.ArrayList)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 DatasetId (io.cdap.cdap.proto.id.DatasetId)4 Schema (co.cask.cdap.api.data.schema.Schema)3 DatasetId (co.cask.cdap.proto.id.DatasetId)3 Schema (io.cdap.cdap.api.data.schema.Schema)3 MetadataEntity (io.cdap.cdap.api.metadata.MetadataEntity)3 MDSKey (io.cdap.cdap.data2.dataset2.lib.table.MDSKey)3 HashMap (java.util.HashMap)3 LinkedHashSet (java.util.LinkedHashSet)3 Map (java.util.Map)3 NamespacedEntityId (co.cask.cdap.proto.id.NamespacedEntityId)2 Put (io.cdap.cdap.api.dataset.table.Put)2 Row (io.cdap.cdap.api.dataset.table.Row)2 Indexer (io.cdap.cdap.data2.metadata.indexer.Indexer)2 InvertedValueIndexer (io.cdap.cdap.data2.metadata.indexer.InvertedValueIndexer)2