All Downloads are FREE. Search and download functionalities are using the official Maven repository.

uk.gov.gchq.gaffer.accumulostore.performancetesting.ingest.BytesWritableMapperGenerator Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
/*
 * Copyright 2017-2023 Crown Copyright
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package uk.gov.gchq.gaffer.accumulostore.performancetesting.ingest;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.BytesWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.MapContext;

import uk.gov.gchq.gaffer.data.element.Element;
import uk.gov.gchq.gaffer.data.generator.ElementGenerator;
import uk.gov.gchq.gaffer.hdfs.operation.handler.job.factory.SampleDataForSplitPointsJobFactory;
import uk.gov.gchq.gaffer.hdfs.operation.mapper.generator.MapperGenerator;
import uk.gov.gchq.gaffer.store.schema.Schema;
import uk.gov.gchq.gaffer.store.serialiser.ElementSerialiser;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

public class BytesWritableMapperGenerator implements MapperGenerator {

    private final List singleItemList = new ArrayList<>(1);
    private ElementGenerator elementGenerator;

    public BytesWritableMapperGenerator() {
    }

    public BytesWritableMapperGenerator(final BytesWritableElementGenerator elementGenerator) {
        this.elementGenerator = elementGenerator;
    }

    private void createElementGenerator(final Configuration conf) {
        final Schema schema = Schema.fromJson(conf
                .get(SampleDataForSplitPointsJobFactory.SCHEMA)
                .getBytes(StandardCharsets.UTF_8));
        this.elementGenerator = new BytesWritableElementGenerator(new ElementSerialiser(schema));
    }

    @Override
    public Iterable getElements(final NullWritable nullWritable,
                                         final BytesWritable bytesWritable,
                                         final MapContext context) {
        if (null == elementGenerator) {
            createElementGenerator(context.getConfiguration());
        }
        singleItemList.clear();
        singleItemList.add(bytesWritable);

        elementGenerator.apply(singleItemList).forEach(System.out::println);
        return elementGenerator.apply(singleItemList);
    }

    public ElementGenerator getElementGenerator() {
        return elementGenerator;
    }

    public void setElementGenerator(final ElementGenerator elementGenerator) {
        this.elementGenerator = elementGenerator;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy