Search in sources :

Example 11 with AccumuloProperties

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

the class TableUtilsTest method shouldCreateTableWithCorrectLocalityGroups.

@Test
public void shouldCreateTableWithCorrectLocalityGroups() throws Exception {
    final MockAccumuloStore store = new MockAccumuloStore();
    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();
    final AccumuloProperties props = AccumuloProperties.loadStoreProperties(StreamUtil.storeProps(TableUtilsTest.class));
    props.setTable(LOCALITY_TABLE_NAME);
    store.initialise(schema, props);
    // When
    TableUtils.createTable(store);
    final Map<String, Set<Text>> localityGroups = store.getConnection().tableOperations().getLocalityGroups(LOCALITY_TABLE_NAME);
    assertEquals(1, localityGroups.size());
    Set<Text> localityGroup = localityGroups.get(TestGroups.EDGE);
    assertEquals(1, localityGroup.size());
    assertEquals(new Text(TestGroups.EDGE), localityGroup.toArray()[0]);
}
Also used : EnumSet(java.util.EnumSet) Set(java.util.Set) MockAccumuloStore(uk.gov.gchq.gaffer.accumulostore.MockAccumuloStore) SingleUseMockAccumuloStore(uk.gov.gchq.gaffer.accumulostore.SingleUseMockAccumuloStore) AccumuloProperties(uk.gov.gchq.gaffer.accumulostore.AccumuloProperties) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Text(org.apache.hadoop.io.Text) Test(org.junit.Test)

Example 12 with AccumuloProperties

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

the class TableUtilsTest method shouldCreateTableWithAllRequiredIterators.

@Test
public void shouldCreateTableWithAllRequiredIterators() throws Exception {
    // Given
    final MockAccumuloStore store = new MockAccumuloStore();
    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();
    final AccumuloProperties props = AccumuloProperties.loadStoreProperties(StreamUtil.storeProps(TableUtilsTest.class));
    props.setTable(TABLE_NAME);
    store.initialise(schema, props);
    // When
    TableUtils.createTable(store);
    // Then
    final Map<String, EnumSet<IteratorScope>> itrs = store.getConnection().tableOperations().listIterators(TABLE_NAME);
    assertEquals(2, itrs.size());
    final EnumSet<IteratorScope> validator = itrs.get(AccumuloStoreConstants.VALIDATOR_ITERATOR_NAME);
    assertEquals(EnumSet.allOf(IteratorScope.class), validator);
    final IteratorSetting validatorSetting = store.getConnection().tableOperations().getIteratorSetting(TABLE_NAME, AccumuloStoreConstants.VALIDATOR_ITERATOR_NAME, IteratorScope.majc);
    assertEquals(AccumuloStoreConstants.VALIDATOR_ITERATOR_PRIORITY, validatorSetting.getPriority());
    assertEquals(ValidatorFilter.class.getName(), validatorSetting.getIteratorClass());
    final Map<String, String> validatorOptions = validatorSetting.getOptions();
    assertNotNull(Schema.fromJson(validatorOptions.get(AccumuloStoreConstants.SCHEMA).getBytes(CommonConstants.UTF_8)).getEdge(TestGroups.EDGE));
    assertEquals(ByteEntityAccumuloElementConverter.class.getName(), validatorOptions.get(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS));
    final EnumSet<IteratorScope> aggregator = itrs.get(AccumuloStoreConstants.AGGREGATOR_ITERATOR_NAME);
    assertEquals(EnumSet.allOf(IteratorScope.class), aggregator);
    final IteratorSetting aggregatorSetting = store.getConnection().tableOperations().getIteratorSetting(TABLE_NAME, AccumuloStoreConstants.AGGREGATOR_ITERATOR_NAME, IteratorScope.majc);
    assertEquals(AccumuloStoreConstants.AGGREGATOR_ITERATOR_PRIORITY, aggregatorSetting.getPriority());
    assertEquals(AggregatorIterator.class.getName(), aggregatorSetting.getIteratorClass());
    final Map<String, String> aggregatorOptions = aggregatorSetting.getOptions();
    assertNotNull(Schema.fromJson(aggregatorOptions.get(AccumuloStoreConstants.SCHEMA).getBytes(CommonConstants.UTF_8)).getEdge(TestGroups.EDGE));
    assertEquals(ByteEntityAccumuloElementConverter.class.getName(), aggregatorOptions.get(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS));
    final Map<String, String> tableProps = new HashMap<>();
    for (final Map.Entry<String, String> entry : store.getConnection().tableOperations().getProperties(TABLE_NAME)) {
        tableProps.put(entry.getKey(), entry.getValue());
    }
    assertEquals(0, Integer.parseInt(tableProps.get(Property.TABLE_FILE_REPLICATION.getKey())));
}
Also used : StringConcat(uk.gov.gchq.gaffer.function.aggregate.StringConcat) MockAccumuloStore(uk.gov.gchq.gaffer.accumulostore.MockAccumuloStore) SingleUseMockAccumuloStore(uk.gov.gchq.gaffer.accumulostore.SingleUseMockAccumuloStore) AccumuloProperties(uk.gov.gchq.gaffer.accumulostore.AccumuloProperties) HashMap(java.util.HashMap) Schema(uk.gov.gchq.gaffer.store.schema.Schema) EnumSet(java.util.EnumSet) AggregatorIterator(uk.gov.gchq.gaffer.accumulostore.key.impl.AggregatorIterator) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) ValidatorFilter(uk.gov.gchq.gaffer.accumulostore.key.impl.ValidatorFilter) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) ByteEntityAccumuloElementConverter(uk.gov.gchq.gaffer.accumulostore.key.core.impl.byteEntity.ByteEntityAccumuloElementConverter) IteratorScope(org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 13 with AccumuloProperties

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

the class TableUtilsTest method shouldCreateTableCorrectlyIfSchemaContainsNoAggregators.

@Test
public void shouldCreateTableCorrectlyIfSchemaContainsNoAggregators() throws Exception {
    // Given
    final MockAccumuloStore store = new MockAccumuloStore();
    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();
    final AccumuloProperties props = AccumuloProperties.loadStoreProperties(StreamUtil.storeProps(TableUtilsTest.class));
    props.setTable(NO_AGGREGATORS_TABLE_NAME);
    store.initialise(schema, props);
    // When
    TableUtils.createTable(store);
    // Then
    final Map<String, EnumSet<IteratorScope>> itrs = store.getConnection().tableOperations().listIterators(NO_AGGREGATORS_TABLE_NAME);
    assertEquals(1, itrs.size());
    final EnumSet<IteratorScope> validator = itrs.get(AccumuloStoreConstants.VALIDATOR_ITERATOR_NAME);
    assertEquals(EnumSet.allOf(IteratorScope.class), validator);
    final IteratorSetting validatorSetting = store.getConnection().tableOperations().getIteratorSetting(NO_AGGREGATORS_TABLE_NAME, AccumuloStoreConstants.VALIDATOR_ITERATOR_NAME, IteratorScope.majc);
    assertEquals(AccumuloStoreConstants.VALIDATOR_ITERATOR_PRIORITY, validatorSetting.getPriority());
    assertEquals(ValidatorFilter.class.getName(), validatorSetting.getIteratorClass());
    final Map<String, String> validatorOptions = validatorSetting.getOptions();
    assertNotNull(Schema.fromJson(validatorOptions.get(AccumuloStoreConstants.SCHEMA).getBytes(CommonConstants.UTF_8)).getEdge(TestGroups.EDGE));
    assertEquals(ByteEntityAccumuloElementConverter.class.getName(), validatorOptions.get(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS));
    final EnumSet<IteratorScope> aggregator = itrs.get(AccumuloStoreConstants.AGGREGATOR_ITERATOR_NAME);
    assertNull(aggregator);
    final IteratorSetting aggregatorSetting = store.getConnection().tableOperations().getIteratorSetting(NO_AGGREGATORS_TABLE_NAME, AccumuloStoreConstants.AGGREGATOR_ITERATOR_NAME, IteratorScope.majc);
    assertNull(aggregatorSetting);
    final Map<String, String> tableProps = new HashMap<>();
    for (final Map.Entry<String, String> entry : store.getConnection().tableOperations().getProperties(NO_AGGREGATORS_TABLE_NAME)) {
        tableProps.put(entry.getKey(), entry.getValue());
    }
    assertEquals(0, Integer.parseInt(tableProps.get(Property.TABLE_FILE_REPLICATION.getKey())));
}
Also used : MockAccumuloStore(uk.gov.gchq.gaffer.accumulostore.MockAccumuloStore) SingleUseMockAccumuloStore(uk.gov.gchq.gaffer.accumulostore.SingleUseMockAccumuloStore) AccumuloProperties(uk.gov.gchq.gaffer.accumulostore.AccumuloProperties) HashMap(java.util.HashMap) Schema(uk.gov.gchq.gaffer.store.schema.Schema) EnumSet(java.util.EnumSet) ValidatorFilter(uk.gov.gchq.gaffer.accumulostore.key.impl.ValidatorFilter) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) ByteEntityAccumuloElementConverter(uk.gov.gchq.gaffer.accumulostore.key.core.impl.byteEntity.ByteEntityAccumuloElementConverter) IteratorScope(org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 14 with AccumuloProperties

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

the class TableUtilsTest method shouldThrowExceptionIfTableNameIsNotSpecified.

@Test(expected = AccumuloRuntimeException.class)
public void shouldThrowExceptionIfTableNameIsNotSpecified() throws StoreException {
    // Given
    final Schema schema = new Schema.Builder().type("int", Integer.class).type("string", String.class).type("boolean", Boolean.class).edge("EDGE", new SchemaEdgeDefinition.Builder().source("string").destination("string").directed("boolean").build()).build();
    final AccumuloProperties properties = new AccumuloProperties();
    properties.setStoreClass(SingleUseMockAccumuloStore.class.getName());
    final AccumuloStore store = new AccumuloStore();
    store.initialise(schema, properties);
    // When
    TableUtils.ensureTableExists(store);
    fail("The expected exception was not thrown.");
}
Also used : SingleUseMockAccumuloStore(uk.gov.gchq.gaffer.accumulostore.SingleUseMockAccumuloStore) AccumuloProperties(uk.gov.gchq.gaffer.accumulostore.AccumuloProperties) Schema(uk.gov.gchq.gaffer.store.schema.Schema) AccumuloStore(uk.gov.gchq.gaffer.accumulostore.AccumuloStore) MockAccumuloStore(uk.gov.gchq.gaffer.accumulostore.MockAccumuloStore) SingleUseMockAccumuloStore(uk.gov.gchq.gaffer.accumulostore.SingleUseMockAccumuloStore) Test(org.junit.Test)

Example 15 with AccumuloProperties

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

the class AccumuloAddElementsFromHdfsJobFactoryTest method shouldSetNumberOfReducersBetweenMinAndMaxSpecified.

@Test
public void shouldSetNumberOfReducersBetweenMinAndMaxSpecified() throws IOException, StoreException, OperationException {
    // Given
    final MockAccumuloStore store = new MockAccumuloStore();
    final Schema schema = Schema.fromJson(StreamUtil.schemas(AccumuloAddElementsFromHdfsJobFactoryTest.class));
    final AccumuloProperties properties = AccumuloProperties.loadStoreProperties(StreamUtil.storeProps(AccumuloAddElementsFromHdfsJobFactoryTest.class));
    store.initialise(schema, properties);
    final JobConf localConf = createLocalConf();
    final FileSystem fs = FileSystem.getLocal(localConf);
    fs.mkdirs(new Path(outputDir));
    fs.mkdirs(new Path(splitsDir));
    final BufferedWriter writer = new BufferedWriter(new FileWriter(splitsFile));
    for (int i = 100; i < 200; i++) {
        writer.write(i + "\n");
    }
    writer.close();
    final SplitTable splitTable = new SplitTable.Builder().inputPath(splitsFile).build();
    store.execute(splitTable, new User());
    final AccumuloAddElementsFromHdfsJobFactory factory = new AccumuloAddElementsFromHdfsJobFactory();
    final Job job = Job.getInstance(localConf);
    // When
    AddElementsFromHdfs operation = new AddElementsFromHdfs.Builder().outputPath(outputDir).mapperGenerator(TextMapperGeneratorImpl.class).option(AccumuloStoreConstants.OPERATION_BULK_IMPORT_MIN_REDUCERS, "10").option(AccumuloStoreConstants.OPERATION_BULK_IMPORT_MAX_REDUCERS, "20").option(AccumuloStoreConstants.OPERATION_HDFS_SPLITS_FILE_PATH, "target/data/splits.txt").build();
    factory.setupJobConf(localConf, operation, store);
    factory.setupJob(job, operation, store);
    // Then
    assertTrue(job.getNumReduceTasks() >= 10);
    assertTrue(job.getNumReduceTasks() <= 20);
    // When
    operation = new AddElementsFromHdfs.Builder().outputPath(outputDir).mapperGenerator(TextMapperGeneratorImpl.class).option(AccumuloStoreConstants.OPERATION_BULK_IMPORT_MIN_REDUCERS, "100").option(AccumuloStoreConstants.OPERATION_BULK_IMPORT_MAX_REDUCERS, "200").option(AccumuloStoreConstants.OPERATION_HDFS_SPLITS_FILE_PATH, "target/data/splits.txt").build();
    factory.setupJobConf(localConf, operation, store);
    factory.setupJob(job, operation, store);
    // Then
    assertTrue(job.getNumReduceTasks() >= 100);
    assertTrue(job.getNumReduceTasks() <= 200);
    // When
    operation = new AddElementsFromHdfs.Builder().outputPath(outputDir).mapperGenerator(TextMapperGeneratorImpl.class).option(AccumuloStoreConstants.OPERATION_BULK_IMPORT_MIN_REDUCERS, "1000").option(AccumuloStoreConstants.OPERATION_BULK_IMPORT_MAX_REDUCERS, "2000").option(AccumuloStoreConstants.OPERATION_HDFS_SPLITS_FILE_PATH, "target/data/splits.txt").build();
    factory.setupJobConf(localConf, operation, store);
    factory.setupJob(job, operation, store);
    // Then
    assertTrue(job.getNumReduceTasks() >= 1000);
    assertTrue(job.getNumReduceTasks() <= 2000);
}
Also used : Path(org.apache.hadoop.fs.Path) AddElementsFromHdfs(uk.gov.gchq.gaffer.hdfs.operation.AddElementsFromHdfs) User(uk.gov.gchq.gaffer.user.User) MockAccumuloStore(uk.gov.gchq.gaffer.accumulostore.MockAccumuloStore) AccumuloProperties(uk.gov.gchq.gaffer.accumulostore.AccumuloProperties) Schema(uk.gov.gchq.gaffer.store.schema.Schema) FileWriter(java.io.FileWriter) BufferedWriter(java.io.BufferedWriter) FileSystem(org.apache.hadoop.fs.FileSystem) SplitTable(uk.gov.gchq.gaffer.accumulostore.operation.hdfs.operation.SplitTable) Job(org.apache.hadoop.mapreduce.Job) JobConf(org.apache.hadoop.mapred.JobConf) Test(org.junit.Test)

Aggregations

AccumuloProperties (uk.gov.gchq.gaffer.accumulostore.AccumuloProperties)15 Schema (uk.gov.gchq.gaffer.store.schema.Schema)13 MockAccumuloStore (uk.gov.gchq.gaffer.accumulostore.MockAccumuloStore)11 Test (org.junit.Test)9 SingleUseMockAccumuloStore (uk.gov.gchq.gaffer.accumulostore.SingleUseMockAccumuloStore)9 User (uk.gov.gchq.gaffer.user.User)7 FileSystem (org.apache.hadoop.fs.FileSystem)5 Path (org.apache.hadoop.fs.Path)5 JobConf (org.apache.hadoop.mapred.JobConf)5 AccumuloStore (uk.gov.gchq.gaffer.accumulostore.AccumuloStore)5 BufferedWriter (java.io.BufferedWriter)4 HashSet (java.util.HashSet)4 Job (org.apache.hadoop.mapreduce.Job)4 AddElementsFromHdfs (uk.gov.gchq.gaffer.hdfs.operation.AddElementsFromHdfs)4 FileWriter (java.io.FileWriter)3 EnumSet (java.util.EnumSet)3 LinkedHashSet (java.util.LinkedHashSet)3 Row (org.apache.spark.sql.Row)3 SQLContext (org.apache.spark.sql.SQLContext)3 SplitTable (uk.gov.gchq.gaffer.accumulostore.operation.hdfs.operation.SplitTable)3