Search in sources :

Example 1 with GroupingTypeAttribute

use of datawave.query.transformer.GroupingTransform.GroupingTypeAttribute in project datawave by NationalSecurityAgency.

the class GroupingTest method testCountingMap.

@Test
public void testCountingMap() {
    MarkingFunctions markingFunctions = new MarkingFunctions.Default();
    GroupingTransform.GroupCountingHashMap map = new GroupingTransform.GroupCountingHashMap(markingFunctions);
    GroupingTypeAttribute attr1 = new GroupingTypeAttribute(new LcType("FOO"), new Key("FOO"), true);
    attr1.setColumnVisibility(new ColumnVisibility("A"));
    map.add(Collections.singleton(attr1));
    GroupingTypeAttribute attr2 = new GroupingTypeAttribute(new LcType("FOO"), new Key("FOO"), true);
    attr2.setColumnVisibility(new ColumnVisibility("B"));
    map.add(Collections.singleton(attr2));
    GroupingTypeAttribute attr3 = new GroupingTypeAttribute(new LcType("BAR"), new Key("BAR"), true);
    attr3.setColumnVisibility(new ColumnVisibility("C"));
    map.add(Collections.singleton(attr3));
    log.debug("map is: " + map);
    for (Map.Entry<Collection<GroupingTypeAttribute<?>>, Integer> entry : map.entrySet()) {
        // the first and only one
        Attribute<?> attr = entry.getKey().iterator().next();
        int count = entry.getValue();
        if (attr.getData().toString().equals("FOO")) {
            Assert.assertEquals(2, count);
            Assert.assertEquals(new ColumnVisibility("A&B"), attr.getColumnVisibility());
        } else if (attr.getData().toString().equals("BAR")) {
            Assert.assertEquals(1, count);
            Assert.assertEquals(new ColumnVisibility("C"), attr.getColumnVisibility());
        }
    }
}
Also used : MarkingFunctions(datawave.marking.MarkingFunctions) GroupingTypeAttribute(datawave.query.transformer.GroupingTransform.GroupingTypeAttribute) Collection(java.util.Collection) LcType(datawave.data.type.LcType) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 2 with GroupingTypeAttribute

use of datawave.query.transformer.GroupingTransform.GroupingTypeAttribute in project datawave by NationalSecurityAgency.

the class GroupingTestWithModel method testCountingMapAgain.

@Test
public void testCountingMapAgain() {
    MarkingFunctions markingFunctions = new MarkingFunctions.Default();
    GroupingTransform.GroupCountingHashMap map = new GroupingTransform.GroupCountingHashMap(markingFunctions);
    GroupingTypeAttribute<?> attr1a = new GroupingTypeAttribute(new LcType("FOO"), new Key("NAME"), true);
    attr1a.setColumnVisibility(new ColumnVisibility("A"));
    GroupingTypeAttribute<?> attr1b = new GroupingTypeAttribute(new NumberType("5"), new Key("AGE"), true);
    attr1b.setColumnVisibility(new ColumnVisibility("C"));
    Set<GroupingTypeAttribute<?>> seta = Sets.newHashSet(attr1a, attr1b);
    map.add(seta);
    GroupingTypeAttribute<?> attr2a = new GroupingTypeAttribute(new LcType("FOO"), new Key("NAME"), true);
    attr2a.setColumnVisibility(new ColumnVisibility("B"));
    GroupingTypeAttribute<?> attr2b = new GroupingTypeAttribute(new NumberType("5"), new Key("AGE"), true);
    attr2b.setColumnVisibility(new ColumnVisibility("D"));
    Set<GroupingTypeAttribute<?>> setb = Sets.newHashSet(attr2a, attr2b);
    map.add(setb);
    // even though the ColumnVisibilities are different, the 2 collections seta and setb are 'equal' and generate the same hashCode
    Assert.assertEquals(seta.hashCode(), setb.hashCode());
    Assert.assertEquals(seta, setb);
    GroupingTypeAttribute attr3a = new GroupingTypeAttribute(new LcType("BAR"), new Key("NAME"), true);
    attr3a.setColumnVisibility(new ColumnVisibility("C"));
    GroupingTypeAttribute attr3b = new GroupingTypeAttribute(new NumberType("6"), new Key("AGE"), true);
    attr3b.setColumnVisibility(new ColumnVisibility("D"));
    map.add(Sets.newHashSet(attr3a, attr3b));
    log.debug("map is: " + map);
    for (Map.Entry<Collection<GroupingTypeAttribute<?>>, Integer> entry : map.entrySet()) {
        for (Attribute<?> attr : entry.getKey()) {
            int count = entry.getValue();
            if (attr.getData().toString().equals("FOO")) {
                Assert.assertEquals(2, count);
                // the ColumnVisibility for the key was changed to the merged value of the 2 items that were added to the map
                Assert.assertEquals(new ColumnVisibility("A&B"), attr.getColumnVisibility());
            } else if (attr.getData().toString().equals("5")) {
                Assert.assertEquals(2, count);
                // the ColumnVisibility for the key was changed to the merged value of the 2 items that were added to the map
                Assert.assertEquals(new ColumnVisibility("C&D"), attr.getColumnVisibility());
            } else if (attr.getData().toString().equals("BAR")) {
                Assert.assertEquals(1, count);
                Assert.assertEquals(new ColumnVisibility("C"), attr.getColumnVisibility());
            } else if (attr.getData().toString().equals("6")) {
                Assert.assertEquals(1, count);
                Assert.assertEquals(new ColumnVisibility("D"), attr.getColumnVisibility());
            }
        }
    }
}
Also used : MarkingFunctions(datawave.marking.MarkingFunctions) NumberType(datawave.data.type.NumberType) GroupingTypeAttribute(datawave.query.transformer.GroupingTransform.GroupingTypeAttribute) Collection(java.util.Collection) LcType(datawave.data.type.LcType) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 3 with GroupingTypeAttribute

use of datawave.query.transformer.GroupingTransform.GroupingTypeAttribute in project datawave by NationalSecurityAgency.

the class GroupingTestWithModel method testCountingMap.

@Test
public void testCountingMap() {
    MarkingFunctions markingFunctions = new MarkingFunctions.Default();
    GroupingTransform.GroupCountingHashMap map = new GroupingTransform.GroupCountingHashMap(markingFunctions);
    GroupingTypeAttribute attr1 = new GroupingTypeAttribute(new LcType("FOO"), new Key("FOO"), true);
    attr1.setColumnVisibility(new ColumnVisibility("A"));
    map.add(Collections.singleton(attr1));
    GroupingTypeAttribute attr2 = new GroupingTypeAttribute(new LcType("FOO"), new Key("FOO"), true);
    attr2.setColumnVisibility(new ColumnVisibility("B"));
    map.add(Collections.singleton(attr2));
    GroupingTypeAttribute attr3 = new GroupingTypeAttribute(new LcType("BAR"), new Key("BAR"), true);
    attr3.setColumnVisibility(new ColumnVisibility("C"));
    map.add(Collections.singleton(attr3));
    log.debug("map is: " + map);
    for (Map.Entry<Collection<GroupingTypeAttribute<?>>, Integer> entry : map.entrySet()) {
        // the first and only one
        Attribute<?> attr = entry.getKey().iterator().next();
        int count = entry.getValue();
        if (attr.getData().toString().equals("FOO")) {
            Assert.assertEquals(2, count);
            Assert.assertEquals(new ColumnVisibility("A&B"), attr.getColumnVisibility());
        } else if (attr.getData().toString().equals("BAR")) {
            Assert.assertEquals(1, count);
            Assert.assertEquals(new ColumnVisibility("C"), attr.getColumnVisibility());
        }
    }
}
Also used : MarkingFunctions(datawave.marking.MarkingFunctions) GroupingTypeAttribute(datawave.query.transformer.GroupingTransform.GroupingTypeAttribute) Collection(java.util.Collection) LcType(datawave.data.type.LcType) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 4 with GroupingTypeAttribute

use of datawave.query.transformer.GroupingTransform.GroupingTypeAttribute in project datawave by NationalSecurityAgency.

the class GroupingTest method testCountingMapAgain.

@Test
public void testCountingMapAgain() {
    MarkingFunctions markingFunctions = new MarkingFunctions.Default();
    GroupingTransform.GroupCountingHashMap map = new GroupingTransform.GroupCountingHashMap(markingFunctions);
    GroupingTypeAttribute<?> attr1a = new GroupingTypeAttribute(new LcType("FOO"), new Key("NAME"), true);
    attr1a.setColumnVisibility(new ColumnVisibility("A"));
    GroupingTypeAttribute<?> attr1b = new GroupingTypeAttribute(new NumberType("5"), new Key("AGE"), true);
    attr1b.setColumnVisibility(new ColumnVisibility("C"));
    Set<GroupingTypeAttribute<?>> seta = Sets.newHashSet(attr1a, attr1b);
    map.add(seta);
    GroupingTypeAttribute<?> attr2a = new GroupingTypeAttribute(new LcType("FOO"), new Key("NAME"), true);
    attr2a.setColumnVisibility(new ColumnVisibility("B"));
    GroupingTypeAttribute<?> attr2b = new GroupingTypeAttribute(new NumberType("5"), new Key("AGE"), true);
    attr2b.setColumnVisibility(new ColumnVisibility("D"));
    Set<GroupingTypeAttribute<?>> setb = Sets.newHashSet(attr2a, attr2b);
    map.add(setb);
    // even though the ColumnVisibilities are different, the 2 collections seta and setb are 'equal' and generate the same hashCode
    Assert.assertEquals(seta.hashCode(), setb.hashCode());
    Assert.assertEquals(seta, setb);
    GroupingTypeAttribute attr3a = new GroupingTypeAttribute(new LcType("BAR"), new Key("NAME"), true);
    attr3a.setColumnVisibility(new ColumnVisibility("C"));
    GroupingTypeAttribute attr3b = new GroupingTypeAttribute(new NumberType("6"), new Key("AGE"), true);
    attr3b.setColumnVisibility(new ColumnVisibility("D"));
    map.add(Sets.newHashSet(attr3a, attr3b));
    log.debug("map is: " + map);
    for (Map.Entry<Collection<GroupingTypeAttribute<?>>, Integer> entry : map.entrySet()) {
        for (Attribute<?> attr : entry.getKey()) {
            int count = entry.getValue();
            if (attr.getData().toString().equals("FOO")) {
                Assert.assertEquals(2, count);
                // the ColumnVisibility for the key was changed to the merged value of the 2 items that were added to the map
                Assert.assertEquals(new ColumnVisibility("A&B"), attr.getColumnVisibility());
            } else if (attr.getData().toString().equals("5")) {
                Assert.assertEquals(2, count);
                // the ColumnVisibility for the key was changed to the merged value of the 2 items that were added to the map
                Assert.assertEquals(new ColumnVisibility("C&D"), attr.getColumnVisibility());
            } else if (attr.getData().toString().equals("BAR")) {
                Assert.assertEquals(1, count);
                Assert.assertEquals(new ColumnVisibility("C"), attr.getColumnVisibility());
            } else if (attr.getData().toString().equals("6")) {
                Assert.assertEquals(1, count);
                Assert.assertEquals(new ColumnVisibility("D"), attr.getColumnVisibility());
            }
        }
    }
}
Also used : MarkingFunctions(datawave.marking.MarkingFunctions) NumberType(datawave.data.type.NumberType) GroupingTypeAttribute(datawave.query.transformer.GroupingTransform.GroupingTypeAttribute) Collection(java.util.Collection) LcType(datawave.data.type.LcType) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)4 LcType (datawave.data.type.LcType)4 MarkingFunctions (datawave.marking.MarkingFunctions)4 GroupingTypeAttribute (datawave.query.transformer.GroupingTransform.GroupingTypeAttribute)4 Collection (java.util.Collection)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Key (org.apache.accumulo.core.data.Key)4 ColumnVisibility (org.apache.accumulo.core.security.ColumnVisibility)4 Test (org.junit.Test)4 NumberType (datawave.data.type.NumberType)2