Search in sources :

Example 1 with AggregateGafferRowsFunction

use of uk.gov.gchq.gaffer.parquetstore.operation.handler.utilities.AggregateGafferRowsFunction in project Gaffer by gchq.

the class AggregateGafferRowsFunctionTest method mergeEntityRowsTest.

@Test
public void mergeEntityRowsTest() throws OperationException, IOException {
    final String group = "BasicEntity";
    final SchemaElementDefinition elementSchema = utils.getGafferSchema().getElement(group);
    final GafferGroupObjectConverter converter = utils.getConverter(group);
    final String[] gafferProperties = new String[elementSchema.getProperties().size()];
    elementSchema.getProperties().toArray(gafferProperties);
    final byte[] aggregatorJson = JSONSerialiser.serialise(elementSchema.getIngestAggregator());
    final AggregateGafferRowsFunction aggregator = new AggregateGafferRowsFunction(gafferProperties, true, elementSchema.getGroupBy(), utils.getColumnToPaths(group), aggregatorJson, converter);
    final GenericRowWithSchema row1 = DataGen.generateEntityRow(utils, group, "vertex", (byte) 'a', 0.2, 3f, TestUtils.getTreeSet1(), 5L, (short) 6, TestUtils.DATE, TestUtils.getFreqMap1(), null);
    final GenericRowWithSchema row2 = DataGen.generateEntityRow(utils, group, "vertex", (byte) 'c', 0.7, 4f, TestUtils.getTreeSet2(), 7L, (short) 4, TestUtils.DATE, TestUtils.getFreqMap2(), null);
    final Row merged = aggregator.call(row1, row2);
    final List<Object> actual = new ArrayList<>(11);
    for (int i = 0; i < merged.length(); i++) {
        actual.add(merged.apply(i));
    }
    final List<Object> expected = new ArrayList<>(11);
    expected.add("vertex");
    expected.add(new byte[] { (byte) 'c' });
    expected.add(0.8999999999999999);
    expected.add(7f);
    expected.add(new String[] { "A", "B", "C" });
    expected.add(12L);
    expected.add(10);
    expected.add(TestUtils.DATE.getTime());
    expected.add(JavaConversions$.MODULE$.mapAsScalaMap(TestUtils.MERGED_FREQMAP));
    expected.add(2);
    assertThat(expected).containsExactly(actual.toArray());
}
Also used : GenericRowWithSchema(org.apache.spark.sql.catalyst.expressions.GenericRowWithSchema) ArrayList(java.util.ArrayList) Row(org.apache.spark.sql.Row) AggregateGafferRowsFunction(uk.gov.gchq.gaffer.parquetstore.operation.handler.utilities.AggregateGafferRowsFunction) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition) Test(org.junit.jupiter.api.Test)

Example 2 with AggregateGafferRowsFunction

use of uk.gov.gchq.gaffer.parquetstore.operation.handler.utilities.AggregateGafferRowsFunction in project Gaffer by gchq.

the class AggregateGafferRowsFunctionTest method mergeEdgeRowsTest.

@Test
public void mergeEdgeRowsTest() throws OperationException, SerialisationException {
    final String group = "BasicEdge";
    final SchemaElementDefinition elementSchema = utils.getGafferSchema().getElement(group);
    final byte[] aggregatorJson = JSONSerialiser.serialise(elementSchema.getIngestAggregator());
    final GafferGroupObjectConverter converter = utils.getConverter(group);
    final String[] gafferProperties = new String[elementSchema.getProperties().size()];
    elementSchema.getProperties().toArray(gafferProperties);
    final AggregateGafferRowsFunction aggregator = new AggregateGafferRowsFunction(gafferProperties, false, elementSchema.getGroupBy(), utils.getColumnToPaths(group), aggregatorJson, converter);
    final GenericRowWithSchema row1 = DataGen.generateEdgeRow(utils, group, "src", "dst", true, (byte) 'a', 0.2, 3f, TestUtils.getTreeSet1(), 5L, (short) 6, TestUtils.DATE, TestUtils.getFreqMap1(), null);
    final GenericRowWithSchema row2 = DataGen.generateEdgeRow(utils, group, "src", "dst", true, (byte) 'c', 0.7, 4f, TestUtils.getTreeSet2(), 7L, (short) 4, TestUtils.DATE, TestUtils.getFreqMap2(), null);
    final Row merged = aggregator.call(row1, row2);
    final List<Object> actual = new ArrayList<>(13);
    for (int i = 0; i < merged.length(); i++) {
        actual.add(merged.apply(i));
    }
    final List<Object> expected = new ArrayList<>(13);
    expected.add("src");
    expected.add("dst");
    expected.add(true);
    expected.add(new byte[] { (byte) 'c' });
    expected.add(0.8999999999999999);
    expected.add(7f);
    expected.add(new String[] { "A", "B", "C" });
    expected.add(12L);
    expected.add(10);
    expected.add(TestUtils.DATE.getTime());
    expected.add(JavaConversions$.MODULE$.mapAsScalaMap(TestUtils.MERGED_FREQMAP));
    expected.add(2);
    assertThat(expected).containsExactly(actual.toArray());
}
Also used : GenericRowWithSchema(org.apache.spark.sql.catalyst.expressions.GenericRowWithSchema) ArrayList(java.util.ArrayList) Row(org.apache.spark.sql.Row) AggregateGafferRowsFunction(uk.gov.gchq.gaffer.parquetstore.operation.handler.utilities.AggregateGafferRowsFunction) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

ArrayList (java.util.ArrayList)2 Row (org.apache.spark.sql.Row)2 GenericRowWithSchema (org.apache.spark.sql.catalyst.expressions.GenericRowWithSchema)2 Test (org.junit.jupiter.api.Test)2 AggregateGafferRowsFunction (uk.gov.gchq.gaffer.parquetstore.operation.handler.utilities.AggregateGafferRowsFunction)2 SchemaElementDefinition (uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition)2