Search in sources :

Example 11 with MetadataEntry

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

the class DefaultValueIndexerTest method testSingleSimpleTags.

@Test
public void testSingleSimpleTags() {
    MetadataEntry entry = new MetadataEntry(NamespaceId.DEFAULT.app("a"), MetadataConstants.TAGS_KEY, "tag");
    Set<String> expected = new HashSet<>();
    expected.add("tag");
    expected.add(MetadataConstants.TAGS_KEY + ":tag");
    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 12 with MetadataEntry

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

the class DefaultValueIndexerTest method testMultipleSplitTags.

@Test
public void testMultipleSplitTags() {
    MetadataEntry entry = new MetadataEntry(NamespaceId.DEFAULT.app("a"), MetadataConstants.TAGS_KEY, "foo,bar baz");
    Set<String> expected = new HashSet<>();
    expected.add("foo");
    expected.add("bar");
    expected.add("baz");
    expected.add(MetadataConstants.TAGS_KEY + ":foo");
    expected.add(MetadataConstants.TAGS_KEY + ":bar");
    expected.add(MetadataConstants.TAGS_KEY + ":baz");
    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 13 with MetadataEntry

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

the class DefaultValueIndexerTest method testMultipleTags.

@Test
public void testMultipleTags() {
    MetadataEntry entry = new MetadataEntry(NamespaceId.DEFAULT.app("a"), MetadataConstants.TAGS_KEY, "t1,t2,t3");
    Set<String> expected = new HashSet<>();
    expected.add("t1");
    expected.add("t2");
    expected.add("t3");
    expected.add(MetadataConstants.TAGS_KEY + ":t1");
    expected.add(MetadataConstants.TAGS_KEY + ":t2");
    expected.add(MetadataConstants.TAGS_KEY + ":t3");
    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 14 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() {
    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(addKeyPrefixAndPropertiesField(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)

Example 15 with MetadataEntry

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

the class SchemaIndexerTest method testComplexRecord.

@Test
public void testComplexRecord() {
    Schema complexSchema = Schema.recordOf("record1", Schema.Field.of("map1", Schema.mapOf(Schema.recordOf("record21", // 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)))), Schema.arrayOf(Schema.recordOf("record22", Schema.Field.of("a", // Map<array<byte[]>, Map<boolean,byte[]> a
    Schema.mapOf(Schema.arrayOf(Schema.of(Schema.Type.BYTES)), Schema.mapOf(Schema.of(Schema.Type.BOOLEAN), Schema.of(Schema.Type.BYTES)))))))), Schema.Field.of("i", Schema.nullableOf(Schema.of(Schema.Type.INT))), Schema.Field.of("j", Schema.unionOf(Schema.of(Schema.Type.INT), Schema.of(Schema.Type.LONG), Schema.of(Schema.Type.NULL))));
    Schema anotherComplexSchema = Schema.arrayOf(Schema.of(Schema.Type.STRING));
    Schema superComplexSchema = Schema.unionOf(complexSchema, anotherComplexSchema, Schema.of(Schema.Type.NULL));
    Set<String> expected = ImmutableSet.of("map1", "map1:MAP", "record21", "record21:RECORD", "x", "x:STRING", "y", "y:ARRAY", "z", "z:MAP", "record22", "record22:RECORD", "a", "a:MAP", "i", "i:INT", "j", "j:UNION", "record1", "record1:RECORD");
    SchemaIndexer indexer = new SchemaIndexer();
    DatasetId datasetInstance = new DatasetId("ns1", "ds1");
    Set<String> actual = indexer.getIndexes(new MetadataEntry(datasetInstance, KEY, superComplexSchema.toString()));
    Assert.assertEquals(addKeyPrefixAndPropertiesField(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)28 MetadataEntry (io.cdap.cdap.data2.metadata.dataset.MetadataEntry)26 HashSet (java.util.HashSet)14 DatasetId (io.cdap.cdap.proto.id.DatasetId)8 ArrayList (java.util.ArrayList)8 MetadataEntry (co.cask.cdap.data2.metadata.dataset.MetadataEntry)7 ImmutableMap (com.google.common.collect.ImmutableMap)6 Schema (io.cdap.cdap.api.data.schema.Schema)6 MetadataEntity (io.cdap.cdap.api.metadata.MetadataEntity)6 MDSKey (io.cdap.cdap.data2.dataset2.lib.table.MDSKey)6 HashMap (java.util.HashMap)5 LinkedHashSet (java.util.LinkedHashSet)5 Map (java.util.Map)5 Put (io.cdap.cdap.api.dataset.table.Put)4 Row (io.cdap.cdap.api.dataset.table.Row)4 Indexer (io.cdap.cdap.data2.metadata.indexer.Indexer)4 InvertedValueIndexer (io.cdap.cdap.data2.metadata.indexer.InvertedValueIndexer)4 Schema (co.cask.cdap.api.data.schema.Schema)3 DatasetId (co.cask.cdap.proto.id.DatasetId)3 LinkedList (java.util.LinkedList)3