Search in sources :

Example 1 with PartitionQuery

use of org.apache.gora.query.PartitionQuery in project gora by apache.

the class FileBackedDataStoreBase method getPartitions.

@Override
public List<PartitionQuery<K, T>> getPartitions(Query<K, T> query) throws IOException {
    List<InputSplit> splits = null;
    List<PartitionQuery<K, T>> queries = null;
    splits = GoraMapReduceUtils.getSplits(getConf(), inputPath);
    queries = new ArrayList<>(splits.size());
    for (InputSplit split : splits) {
        queries.add(new FileSplitPartitionQuery<>(query, (FileSplit) split));
    }
    return queries;
}
Also used : FileSplit(org.apache.hadoop.mapreduce.lib.input.FileSplit) InputSplit(org.apache.hadoop.mapreduce.InputSplit) PartitionQuery(org.apache.gora.query.PartitionQuery) FileSplitPartitionQuery(org.apache.gora.query.impl.FileSplitPartitionQuery)

Example 2 with PartitionQuery

use of org.apache.gora.query.PartitionQuery in project gora by apache.

the class TestGoraInputFormat method testGetSplits.

/**
 * First, asserts that the attempt to obtain splits results in
 * greater than 0 splits which can be used for computation.
 * We then check that the partition query (obtained by using the
 * splits) has the same fields as we would expect by directly
 * accessing the fields of an Employee object.
 * @throws IOException
 * @throws InterruptedException
 */
@Test
@SuppressWarnings("rawtypes")
public void testGetSplits() throws IOException, InterruptedException {
    List<InputSplit> splits = getInputSplits();
    assertTrue(splits.size() > 0);
    InputSplit split = splits.get(0);
    PartitionQuery query = ((GoraInputSplit) split).getQuery();
    assertTrue(Arrays.equals(getEmployeeFieldNames(), query.getFields()));
}
Also used : InputSplit(org.apache.hadoop.mapreduce.InputSplit) PartitionQuery(org.apache.gora.query.PartitionQuery) Test(org.junit.Test)

Example 3 with PartitionQuery

use of org.apache.gora.query.PartitionQuery in project gora by apache.

the class CassandraStore method getPartitions.

/**
 * {@inheritDoc}
 */
@Override
public List<PartitionQuery<K, T>> getPartitions(Query<K, T> query) throws GoraException {
    try {
        List<PartitionQuery<K, T>> partitions = new ArrayList<>();
        PartitionWSQueryImpl<K, T> pqi = new PartitionWSQueryImpl<>(query);
        pqi.setDataStore(this);
        partitions.add(pqi);
        return partitions;
    } catch (Exception e) {
        throw new GoraException(e);
    }
}
Also used : PartitionWSQueryImpl(org.apache.gora.query.ws.impl.PartitionWSQueryImpl) GoraException(org.apache.gora.util.GoraException) ArrayList(java.util.ArrayList) PartitionQuery(org.apache.gora.query.PartitionQuery) IOException(java.io.IOException) GoraException(org.apache.gora.util.GoraException)

Example 4 with PartitionQuery

use of org.apache.gora.query.PartitionQuery in project gora by apache.

the class PigGoraInputFormat method getSplits.

@Override
public List<InputSplit> getSplits(JobContext context) throws IOException, InterruptedException {
    List<PartitionQuery<K, T>> partitionsQueries = this.dataStore.getPartitions(query);
    List<InputSplit> splits = new ArrayList<>(partitionsQueries.size());
    for (PartitionQuery<K, T> queryForSplit : partitionsQueries) {
        splits.add(new GoraInputSplit(context.getConfiguration(), queryForSplit));
    }
    return splits;
}
Also used : GoraInputSplit(org.apache.gora.mapreduce.GoraInputSplit) ArrayList(java.util.ArrayList) PartitionQuery(org.apache.gora.query.PartitionQuery) InputSplit(org.apache.hadoop.mapreduce.InputSplit) GoraInputSplit(org.apache.gora.mapreduce.GoraInputSplit)

Example 5 with PartitionQuery

use of org.apache.gora.query.PartitionQuery in project gora by apache.

the class JCacheStore method getPartitions.

@Override
public List<PartitionQuery<K, T>> getPartitions(Query<K, T> query) throws IOException {
    List<PartitionQuery<K, T>> partitions = new ArrayList<>();
    try {
        Member[] clusterMembers = new Member[hazelcastInstance.getCluster().getMembers().size()];
        this.hazelcastInstance.getCluster().getMembers().toArray(clusterMembers);
        for (Member member : clusterMembers) {
            JCacheResult<K, T> result = ((JCacheResult<K, T>) query.execute());
            ConcurrentSkipListSet<K> memberOwnedCacheEntries = new ConcurrentSkipListSet<>();
            while (result.next()) {
                K key = result.getKey();
                Partition partition = hazelcastInstance.getPartitionService().getPartition(key);
                if (partition.getOwner().getUuid().equals(member.getUuid())) {
                    memberOwnedCacheEntries.add(key);
                }
            }
            PartitionQueryImpl<K, T> partition = new PartitionQueryImpl<>(query, memberOwnedCacheEntries.first(), memberOwnedCacheEntries.last(), member.getSocketAddress().getHostString());
            partition.setConf(this.getConf());
            partitions.add(partition);
        }
    } catch (java.lang.Exception ex) {
        LOG.error("Exception occurred while partitioning the query based on Hazelcast partitions.", ex);
        return null;
    }
    LOG.info("Query is partitioned to {} number of partitions.", partitions.size());
    return partitions;
}
Also used : Partition(com.hazelcast.core.Partition) PartitionQueryImpl(org.apache.gora.query.impl.PartitionQueryImpl) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) ArrayList(java.util.ArrayList) PartitionQuery(org.apache.gora.query.PartitionQuery) Member(com.hazelcast.core.Member)

Aggregations

PartitionQuery (org.apache.gora.query.PartitionQuery)8 ArrayList (java.util.ArrayList)5 InputSplit (org.apache.hadoop.mapreduce.InputSplit)3 IOException (java.io.IOException)2 PartitionQueryImpl (org.apache.gora.query.impl.PartitionQueryImpl)2 GoraException (org.apache.gora.util.GoraException)2 Member (com.hazelcast.core.Member)1 Partition (com.hazelcast.core.Partition)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 InetAddress (java.net.InetAddress)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 ConcurrentSkipListSet (java.util.concurrent.ConcurrentSkipListSet)1 AccumuloException (org.apache.accumulo.core.client.AccumuloException)1 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)1 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)1 TableDeletedException (org.apache.accumulo.core.client.TableDeletedException)1 TableExistsException (org.apache.accumulo.core.client.TableExistsException)1 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)1