Search in sources :

Example 6 with SingleUseMiniAccumuloStore

use of uk.gov.gchq.gaffer.accumulostore.SingleUseMiniAccumuloStore in project Gaffer by gchq.

the class AccumuloStoreRelationTest method testBuildScanSpecifyColumnsAndFiltersWithView.

private void testBuildScanSpecifyColumnsAndFiltersWithView(final View view, final String[] requiredColumns, final Filter[] filters, final Predicate<Element> returnElement) throws OperationException, StoreException {
    // Given
    final SparkSession sparkSession = SparkSessionProvider.getSparkSession();
    final Schema schema = getSchema();
    final AccumuloStore store = new SingleUseMiniAccumuloStore();
    store.initialise("graphId", schema, PROPERTIES);
    addElements(store);
    // When
    final AccumuloStoreRelation relation = new AccumuloStoreRelation(SparkContextUtil.createContext(new User(), sparkSession), Collections.emptyList(), view, store, null);
    final RDD<Row> rdd = relation.buildScan(requiredColumns, filters);
    final Row[] returnedElements = (Row[]) rdd.collect();
    // Then
    // - Actual results are:
    final Set<Row> results = new HashSet<>(Arrays.asList(returnedElements));
    // - Expected results are:
    final SchemaToStructTypeConverter schemaConverter = new SchemaToStructTypeConverter(schema, view, new ArrayList<>());
    final ConvertElementToRow elementConverter = new ConvertElementToRow(new LinkedHashSet<>(Arrays.asList(requiredColumns)), schemaConverter.getPropertyNeedsConversion(), schemaConverter.getConverterByProperty());
    final Set<Row> expectedRows = new HashSet<>();
    Streams.toStream(getElements()).filter(returnElement).map(elementConverter::apply).forEach(expectedRows::add);
    assertEquals(expectedRows, results);
}
Also used : SparkSession(org.apache.spark.sql.SparkSession) User(uk.gov.gchq.gaffer.user.User) Schema(uk.gov.gchq.gaffer.store.schema.Schema) SingleUseMiniAccumuloStore(uk.gov.gchq.gaffer.accumulostore.SingleUseMiniAccumuloStore) SingleUseMiniAccumuloStore(uk.gov.gchq.gaffer.accumulostore.SingleUseMiniAccumuloStore) AccumuloStore(uk.gov.gchq.gaffer.accumulostore.AccumuloStore) ConvertElementToRow(uk.gov.gchq.gaffer.spark.operation.dataframe.ConvertElementToRow) Row(org.apache.spark.sql.Row) SchemaToStructTypeConverter(uk.gov.gchq.gaffer.spark.operation.dataframe.converter.schema.SchemaToStructTypeConverter) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) ConvertElementToRow(uk.gov.gchq.gaffer.spark.operation.dataframe.ConvertElementToRow)

Example 7 with SingleUseMiniAccumuloStore

use of uk.gov.gchq.gaffer.accumulostore.SingleUseMiniAccumuloStore in project Gaffer by gchq.

the class AccumuloStoreRelationTest method shouldReturnEmptyDataFrameWithNoResultsFromFilter.

@Test
public void shouldReturnEmptyDataFrameWithNoResultsFromFilter() throws StoreException, OperationException {
    // Given
    final SparkSession sparkSession = SparkSessionProvider.getSparkSession();
    final Schema schema = getSchema();
    final View view = getViewFromSchema(schema);
    final AccumuloStore store = new SingleUseMiniAccumuloStore();
    store.initialise("graphId", schema, PROPERTIES);
    addElements(store);
    final String[] requiredColumns = new String[1];
    requiredColumns[0] = "property1";
    final Filter[] filters = new Filter[1];
    filters[0] = new EqualTo("group", "abc");
    // When
    final AccumuloStoreRelation relation = new AccumuloStoreRelation(SparkContextUtil.createContext(new User(), sparkSession), Collections.emptyList(), view, store, null);
    final RDD<Row> rdd = relation.buildScan(requiredColumns, filters);
    // Then
    assertThat(rdd.isEmpty()).isTrue();
}
Also used : SparkSession(org.apache.spark.sql.SparkSession) User(uk.gov.gchq.gaffer.user.User) Schema(uk.gov.gchq.gaffer.store.schema.Schema) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) SingleUseMiniAccumuloStore(uk.gov.gchq.gaffer.accumulostore.SingleUseMiniAccumuloStore) EqualTo(org.apache.spark.sql.sources.EqualTo) Filter(org.apache.spark.sql.sources.Filter) SingleUseMiniAccumuloStore(uk.gov.gchq.gaffer.accumulostore.SingleUseMiniAccumuloStore) AccumuloStore(uk.gov.gchq.gaffer.accumulostore.AccumuloStore) ConvertElementToRow(uk.gov.gchq.gaffer.spark.operation.dataframe.ConvertElementToRow) Row(org.apache.spark.sql.Row) Test(org.junit.jupiter.api.Test)

Example 8 with SingleUseMiniAccumuloStore

use of uk.gov.gchq.gaffer.accumulostore.SingleUseMiniAccumuloStore in project Gaffer by gchq.

the class AccumuloSampleDataForSplitPointsJobFactoryTest method getStoreConfiguredWith.

@Override
protected Store getStoreConfiguredWith(final Class<JSONSerialiser> jsonSerialiserClass, final String jsonSerialiserModules, final Boolean strictJson) throws IOException, StoreException {
    final AccumuloStore store = new SingleUseMiniAccumuloStore();
    final Schema schema = Schema.fromJson(StreamUtil.schemas(AccumuloSampleDataForSplitPointsJobFactoryTest.class));
    super.configureStoreProperties(PROPERTIES, jsonSerialiserClass, jsonSerialiserModules, strictJson);
    store.initialise("graphId", schema, PROPERTIES);
    final FileSystem fileSystem = FileSystem.getLocal(new Configuration());
    fileSystem.mkdirs(new Path(outputDir));
    fileSystem.mkdirs(new Path(splitsDir));
    return store;
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) Schema(uk.gov.gchq.gaffer.store.schema.Schema) FileSystem(org.apache.hadoop.fs.FileSystem) SingleUseMiniAccumuloStore(uk.gov.gchq.gaffer.accumulostore.SingleUseMiniAccumuloStore) AccumuloStore(uk.gov.gchq.gaffer.accumulostore.AccumuloStore) SingleUseMiniAccumuloStore(uk.gov.gchq.gaffer.accumulostore.SingleUseMiniAccumuloStore)

Example 9 with SingleUseMiniAccumuloStore

use of uk.gov.gchq.gaffer.accumulostore.SingleUseMiniAccumuloStore in project Gaffer by gchq.

the class TableUtilsTest method shouldCreateTableWithCorrectLocalityGroups.

@Test
public void shouldCreateTableWithCorrectLocalityGroups() throws Exception {
    final AccumuloStore store = new SingleUseMiniAccumuloStore();
    final Schema schema = new Schema.Builder().type(TestTypes.ID_STRING, String.class).type(TestTypes.DIRECTED_TRUE, Boolean.class).edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().source(TestTypes.ID_STRING).destination(TestTypes.ID_STRING).directed(TestTypes.DIRECTED_TRUE).build()).build();
    store.initialise(LOCALITY_GRAPH_ID, schema, PROPERTIES);
    // When
    TableUtils.createTable(store);
    final Map<String, Set<Text>> localityGroups = store.getConnection().tableOperations().getLocalityGroups(LOCALITY_GRAPH_ID);
    assertThat(localityGroups).hasSize(1);
    Set<Text> localityGroup = localityGroups.get(TestGroups.EDGE);
    assertThat(localityGroup).hasSize(1);
    assertEquals(new Text(TestGroups.EDGE), localityGroup.toArray()[0]);
}
Also used : EnumSet(java.util.EnumSet) Set(java.util.Set) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Text(org.apache.hadoop.io.Text) MiniAccumuloStore(uk.gov.gchq.gaffer.accumulostore.MiniAccumuloStore) SingleUseMiniAccumuloStore(uk.gov.gchq.gaffer.accumulostore.SingleUseMiniAccumuloStore) AccumuloStore(uk.gov.gchq.gaffer.accumulostore.AccumuloStore) SingleUseMiniAccumuloStore(uk.gov.gchq.gaffer.accumulostore.SingleUseMiniAccumuloStore) Test(org.junit.jupiter.api.Test)

Example 10 with SingleUseMiniAccumuloStore

use of uk.gov.gchq.gaffer.accumulostore.SingleUseMiniAccumuloStore in project Gaffer by gchq.

the class TableUtilsTest method shouldCreateTableWithAllRequiredIterators.

@Test
public void shouldCreateTableWithAllRequiredIterators() throws Exception {
    // Given
    final AccumuloStore store = new SingleUseMiniAccumuloStore();
    final Schema schema = new Schema.Builder().type(TestTypes.ID_STRING, new TypeDefinition.Builder().aggregateFunction(new StringConcat()).clazz(String.class).build()).type(TestTypes.DIRECTED_TRUE, Boolean.class).edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().source(TestTypes.ID_STRING).destination(TestTypes.ID_STRING).directed(TestTypes.DIRECTED_TRUE).build()).build();
    store.initialise(GRAPH_ID, schema, PROPERTIES);
    // When
    TableUtils.createTable(store);
    // Then - this call will check the table is configured properly
    TableUtils.ensureTableExists(store);
}
Also used : StringConcat(uk.gov.gchq.koryphe.impl.binaryoperator.StringConcat) Schema(uk.gov.gchq.gaffer.store.schema.Schema) MiniAccumuloStore(uk.gov.gchq.gaffer.accumulostore.MiniAccumuloStore) SingleUseMiniAccumuloStore(uk.gov.gchq.gaffer.accumulostore.SingleUseMiniAccumuloStore) AccumuloStore(uk.gov.gchq.gaffer.accumulostore.AccumuloStore) SingleUseMiniAccumuloStore(uk.gov.gchq.gaffer.accumulostore.SingleUseMiniAccumuloStore) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

SingleUseMiniAccumuloStore (uk.gov.gchq.gaffer.accumulostore.SingleUseMiniAccumuloStore)12 AccumuloStore (uk.gov.gchq.gaffer.accumulostore.AccumuloStore)10 Schema (uk.gov.gchq.gaffer.store.schema.Schema)10 Test (org.junit.jupiter.api.Test)6 MiniAccumuloStore (uk.gov.gchq.gaffer.accumulostore.MiniAccumuloStore)5 HashSet (java.util.HashSet)4 Row (org.apache.spark.sql.Row)4 SparkSession (org.apache.spark.sql.SparkSession)4 ConvertElementToRow (uk.gov.gchq.gaffer.spark.operation.dataframe.ConvertElementToRow)4 User (uk.gov.gchq.gaffer.user.User)4 LinkedHashSet (java.util.LinkedHashSet)3 SchemaToStructTypeConverter (uk.gov.gchq.gaffer.spark.operation.dataframe.converter.schema.SchemaToStructTypeConverter)3 StoreException (uk.gov.gchq.gaffer.store.StoreException)3 StringConcat (uk.gov.gchq.koryphe.impl.binaryoperator.StringConcat)3 Exists (uk.gov.gchq.koryphe.impl.predicate.Exists)3 EnumSet (java.util.EnumSet)2 FileSystem (org.apache.hadoop.fs.FileSystem)2 Path (org.apache.hadoop.fs.Path)2 Text (org.apache.hadoop.io.Text)2 AccumuloRuntimeException (uk.gov.gchq.gaffer.accumulostore.key.AccumuloRuntimeException)2