Search in sources :

Example 41 with FreqMap

use of uk.gov.gchq.gaffer.types.FreqMap in project Gaffer by gchq.

the class FreqMapSerialiserTest method getHistoricSerialisationPairs.

@Override
public Pair<FreqMap, byte[]>[] getHistoricSerialisationPairs() {
    final FreqMap freqMap = new FreqMap();
    freqMap.put("x", 10L);
    freqMap.put("y", 5L);
    freqMap.put("z", 20L);
    return new Pair[] { new Pair(freqMap, new byte[] { 120, 0, 10, 0, 121, 0, 5, 0, 122, 0, 20 }) };
}
Also used : FreqMap(uk.gov.gchq.gaffer.types.FreqMap) Pair(uk.gov.gchq.gaffer.commonutil.pair.Pair)

Example 42 with FreqMap

use of uk.gov.gchq.gaffer.types.FreqMap in project Gaffer by gchq.

the class FreqMapPredicatorTest method shouldFilterMapWithMultipleResults.

@Test
public void shouldFilterMapWithMultipleResults() {
    // given
    final Regex predicate = new Regex("^\\wo\\w$");
    final FreqMapPredicator fRegexPredicator = new FreqMapPredicator(predicate);
    // when
    final FreqMap fRegex = fRegexPredicator.apply(freqMap);
    // then
    assertEquals(fRegex.size(), 2);
    assertTrue(fRegex.containsKey("cow"));
    assertTrue(fRegex.containsKey("dog"));
}
Also used : Regex(uk.gov.gchq.koryphe.impl.predicate.Regex) FreqMap(uk.gov.gchq.gaffer.types.FreqMap) Test(org.junit.jupiter.api.Test)

Example 43 with FreqMap

use of uk.gov.gchq.gaffer.types.FreqMap in project Gaffer by gchq.

the class FreqMapPredicatorTest method shouldNotMutateOriginalValue.

@Test
public void shouldNotMutateOriginalValue() {
    // given
    final Regex predicate = new Regex("^\\wo\\w$");
    final FreqMapPredicator fRegexPredicator = new FreqMapPredicator(predicate);
    // when
    final FreqMap fRegex = fRegexPredicator.apply(freqMap);
    // then
    assertEquals(fRegex.size(), 2);
    assertTrue(fRegex.containsKey("cow"));
    assertTrue(fRegex.containsKey("dog"));
    assertEquals(freqMap.size(), 4);
    assertTrue(freqMap.containsKey("cat"));
    assertTrue(freqMap.containsKey("dog"));
    assertTrue(freqMap.containsKey("catdog"));
    assertTrue(freqMap.containsKey("cow"));
}
Also used : Regex(uk.gov.gchq.koryphe.impl.predicate.Regex) FreqMap(uk.gov.gchq.gaffer.types.FreqMap) Test(org.junit.jupiter.api.Test)

Example 44 with FreqMap

use of uk.gov.gchq.gaffer.types.FreqMap in project Gaffer by gchq.

the class FreqMapPredicatorTest method initFreqMap.

@BeforeEach
public void initFreqMap() {
    this.freqMap = new FreqMap();
    freqMap.upsert("cat");
    freqMap.upsert("cat");
    freqMap.upsert("dog");
    freqMap.upsert("cow");
    freqMap.upsert("cow");
    freqMap.upsert("catdog");
    freqMap.upsert("catdog");
    freqMap.upsert("catdog");
    freqMap.upsert("cat");
    freqMap.upsert("cat");
}
Also used : FreqMap(uk.gov.gchq.gaffer.types.FreqMap) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 45 with FreqMap

use of uk.gov.gchq.gaffer.types.FreqMap in project Gaffer by gchq.

the class IterableToFreqMapTest method shouldIncrementTheValueOfTheKeyByOne.

@Test
public void shouldIncrementTheValueOfTheKeyByOne() {
    // Given
    Iterable<String> strings = (Iterable<String>) Arrays.asList("one", "one");
    final IterableToFreqMap iterableToFreqMap = new IterableToFreqMap();
    // When
    FreqMap result = iterableToFreqMap.apply(strings);
    // Then
    HashMap<String, Long> input = new HashMap<>();
    input.put("one", 2L);
    FreqMap expected = new FreqMap(input);
    assertEquals(expected, result);
}
Also used : FreqMap(uk.gov.gchq.gaffer.types.FreqMap) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test) FunctionTest(uk.gov.gchq.koryphe.function.FunctionTest)

Aggregations

FreqMap (uk.gov.gchq.gaffer.types.FreqMap)62 Test (org.junit.jupiter.api.Test)29 ArrayList (java.util.ArrayList)9 Edge (uk.gov.gchq.gaffer.data.element.Edge)9 Entity (uk.gov.gchq.gaffer.data.element.Entity)9 Date (java.util.Date)6 Schema (uk.gov.gchq.gaffer.store.schema.Schema)6 FunctionTest (uk.gov.gchq.koryphe.function.FunctionTest)6 Configuration (org.apache.hadoop.conf.Configuration)5 FileSystem (org.apache.hadoop.fs.FileSystem)5 Path (org.apache.hadoop.fs.Path)5 Row (org.apache.spark.sql.Row)5 SparkSession (org.apache.spark.sql.SparkSession)5 WrappedArray (scala.collection.mutable.WrappedArray)5 Element (uk.gov.gchq.gaffer.data.element.Element)5 HashMap (java.util.HashMap)4 Key (org.apache.accumulo.core.data.Key)4 Test (org.junit.Test)4 EdgeId (uk.gov.gchq.gaffer.data.element.id.EdgeId)4 ElementId (uk.gov.gchq.gaffer.data.element.id.ElementId)4