Search in sources :

Example 11 with AccumuloRyaQueryEngine

use of org.apache.rya.accumulo.query.AccumuloRyaQueryEngine in project incubator-rya by apache.

the class CreateFluoPcj method importHistoricResultsIntoFluo.

private void importHistoricResultsIntoFluo(FluoClient fluo, FluoQuery fluoQuery, Connector accumulo, String ryaInstance) throws RyaDAOException {
    // Reuse the same set object while performing batch inserts.
    final Set<RyaStatement> queryBatch = new HashSet<>();
    // historic matches into Fluo.
    for (final StatementPatternMetadata patternMetadata : fluoQuery.getStatementPatternMetadata()) {
        // Get an iterator over all of the binding sets that match the
        // statement pattern.
        final StatementPattern pattern = FluoStringConverter.toStatementPattern(patternMetadata.getStatementPattern());
        queryBatch.add(spToRyaStatement(pattern));
    }
    // Create AccumuloRyaQueryEngine to query for historic results
    final AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration();
    conf.setTablePrefix(ryaInstance);
    conf.setAuths(getAuths(accumulo));
    try (final AccumuloRyaQueryEngine queryEngine = new AccumuloRyaQueryEngine(accumulo, conf);
        CloseableIterable<RyaStatement> queryIterable = queryEngine.query(new BatchRyaQuery(queryBatch))) {
        final Set<RyaStatement> triplesBatch = new HashSet<>();
        // Insert batches of the binding sets into Fluo.
        for (final RyaStatement ryaStatement : queryIterable) {
            if (triplesBatch.size() == spInsertBatchSize) {
                writeBatch(fluo, triplesBatch);
                triplesBatch.clear();
            }
            triplesBatch.add(ryaStatement);
        }
        if (!triplesBatch.isEmpty()) {
            writeBatch(fluo, triplesBatch);
            triplesBatch.clear();
        }
    } catch (final IOException e) {
        log.warn("Ignoring IOException thrown while closing the AccumuloRyaQueryEngine used by CreatePCJ.", e);
    }
}
Also used : StatementPattern(org.openrdf.query.algebra.StatementPattern) StatementPatternMetadata(org.apache.rya.indexing.pcj.fluo.app.query.StatementPatternMetadata) BatchRyaQuery(org.apache.rya.api.persist.query.BatchRyaQuery) RyaStatement(org.apache.rya.api.domain.RyaStatement) AccumuloRyaQueryEngine(org.apache.rya.accumulo.query.AccumuloRyaQueryEngine) IOException(java.io.IOException) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) HashSet(java.util.HashSet)

Example 12 with AccumuloRyaQueryEngine

use of org.apache.rya.accumulo.query.AccumuloRyaQueryEngine in project incubator-rya by apache.

the class AccumuloRyaDAO method init.

@Override
public void init() throws RyaDAOException {
    if (isInitialized.get()) {
        return;
    }
    try {
        checkNotNull(conf);
        checkNotNull(connector);
        if (batchWriterConfig == null) {
            batchWriterConfig = new BatchWriterConfig();
            batchWriterConfig.setMaxMemory(MAX_MEMORY);
            batchWriterConfig.setTimeout(MAX_TIME, TimeUnit.MILLISECONDS);
            batchWriterConfig.setMaxWriteThreads(NUM_THREADS);
        }
        tableLayoutStrategy = conf.getTableLayoutStrategy();
        ryaContext = RyaTripleContext.getInstance(conf);
        ryaTableMutationsFactory = new RyaTableMutationsFactory(ryaContext);
        secondaryIndexers = conf.getAdditionalIndexers();
        flushEachUpdate.set(conf.flushEachUpdate());
        final TableOperations tableOperations = connector.tableOperations();
        AccumuloRdfUtils.createTableIfNotExist(tableOperations, tableLayoutStrategy.getSpo());
        AccumuloRdfUtils.createTableIfNotExist(tableOperations, tableLayoutStrategy.getPo());
        AccumuloRdfUtils.createTableIfNotExist(tableOperations, tableLayoutStrategy.getOsp());
        AccumuloRdfUtils.createTableIfNotExist(tableOperations, tableLayoutStrategy.getNs());
        for (final AccumuloIndexer index : secondaryIndexers) {
            index.setConf(conf);
        }
        mt_bw = connector.createMultiTableBatchWriter(batchWriterConfig);
        // get the batch writers for tables
        bw_spo = mt_bw.getBatchWriter(tableLayoutStrategy.getSpo());
        bw_po = mt_bw.getBatchWriter(tableLayoutStrategy.getPo());
        bw_osp = mt_bw.getBatchWriter(tableLayoutStrategy.getOsp());
        bw_ns = mt_bw.getBatchWriter(tableLayoutStrategy.getNs());
        for (final AccumuloIndexer index : secondaryIndexers) {
            index.setConnector(connector);
            index.setMultiTableBatchWriter(mt_bw);
            index.init();
        }
        queryEngine = new AccumuloRyaQueryEngine(connector, conf);
        checkVersion();
        isInitialized.set(true);
    } catch (final Exception e) {
        throw new RyaDAOException(e);
    }
}
Also used : TableOperations(org.apache.accumulo.core.client.admin.TableOperations) AccumuloIndexer(org.apache.rya.accumulo.experimental.AccumuloIndexer) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) AccumuloRyaQueryEngine(org.apache.rya.accumulo.query.AccumuloRyaQueryEngine) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) IOException(java.io.IOException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) RyaDAOException(org.apache.rya.api.persist.RyaDAOException)

Example 13 with AccumuloRyaQueryEngine

use of org.apache.rya.accumulo.query.AccumuloRyaQueryEngine in project incubator-rya by apache.

the class AccumuloRyaDAOTest method testSameLiteralStringTypes.

@Test
public void testSameLiteralStringTypes() throws Exception {
    RyaURI cpu = new RyaURI(litdupsNS + "cpu");
    RyaURI loadPerc = new RyaURI(litdupsNS + "loadPerc");
    RyaType longLit = new RyaType(XMLSchema.LONG, "10");
    RyaType strLit = new RyaType(XMLSchema.STRING, new String(RyaContext.getInstance().serializeType(longLit)[0]));
    RyaStatement expected = new RyaStatement(cpu, loadPerc, longLit);
    dao.add(expected);
    dao.add(new RyaStatement(cpu, loadPerc, strLit));
    AccumuloRyaQueryEngine queryEngine = dao.getQueryEngine();
    CloseableIteration<RyaStatement, RyaDAOException> query = queryEngine.query(new RyaStatement(cpu, loadPerc, longLit), conf);
    assertTrue(query.hasNext());
    RyaStatement next = query.next();
    assertEquals(new Long(longLit.getData()), new Long(next.getObject().getData()));
    assertEquals(longLit.getDataType(), next.getObject().getDataType());
    assertFalse(query.hasNext());
    query.close();
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) RyaStatement(org.apache.rya.api.domain.RyaStatement) AccumuloRyaQueryEngine(org.apache.rya.accumulo.query.AccumuloRyaQueryEngine) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) RyaType(org.apache.rya.api.domain.RyaType) Test(org.junit.Test)

Example 14 with AccumuloRyaQueryEngine

use of org.apache.rya.accumulo.query.AccumuloRyaQueryEngine in project incubator-rya by apache.

the class AccumuloRyaDAOTest method testQueryDates.

@Test
public void testQueryDates() throws Exception {
    RyaURI cpu = new RyaURI(litdupsNS + "cpu");
    RyaURI loadPerc = new RyaURI(litdupsNS + "loadPerc");
    // How handles local time
    RyaType uri0 = new RyaType(XMLSchema.DATETIME, "1960-01-01");
    // See Magadan Time
    RyaType uri1 = new RyaType(XMLSchema.DATETIME, "1992-01-01T+10:00");
    // How it handles UTC.
    RyaType uri2 = new RyaType(XMLSchema.DATETIME, "2000-01-01TZ");
    RyaType uri3 = new RyaType(XMLSchema.DATETIME, "2000-01-01T00:00:01.111Z");
    // duplicate
    RyaType uri4 = new RyaType(XMLSchema.DATETIME, "2000-01-01T00:00:01.111Z");
    RyaType uri5 = new RyaType(XMLSchema.DATETIME, "2000-01-01T00:00:01-00:00");
    // duplicate
    RyaType uri6 = new RyaType(XMLSchema.DATETIME, "2000-01-01T00:00:01Z");
    RyaType uri7 = new RyaType(XMLSchema.DATETIME, "-2000-01-01T00:00:01Z");
    RyaType uri8 = new RyaType(XMLSchema.DATETIME, "111-01-01T00:00:01Z");
    RyaType uri9 = new RyaType(XMLSchema.DATETIME, "12345-01-01T00:00:01Z");
    dao.add(new RyaStatement(cpu, loadPerc, uri0));
    dao.add(new RyaStatement(cpu, loadPerc, uri1));
    dao.add(new RyaStatement(cpu, loadPerc, uri2));
    dao.add(new RyaStatement(cpu, loadPerc, uri3));
    dao.add(new RyaStatement(cpu, loadPerc, uri4));
    dao.add(new RyaStatement(cpu, loadPerc, uri5));
    dao.add(new RyaStatement(cpu, loadPerc, uri6));
    dao.add(new RyaStatement(cpu, loadPerc, uri7));
    dao.add(new RyaStatement(cpu, loadPerc, uri8));
    dao.add(new RyaStatement(cpu, loadPerc, uri9));
    AccumuloRyaQueryEngine queryEngine = dao.getQueryEngine();
    Collection<RyaStatement> coll = new ArrayList();
    coll.add(new RyaStatement(null, loadPerc, uri0));
    coll.add(new RyaStatement(null, loadPerc, uri1));
    coll.add(new RyaStatement(null, loadPerc, uri2));
    CloseableIteration<RyaStatement, RyaDAOException> iter = queryEngine.batchQuery(coll, conf);
    int count = 0;
    while (iter.hasNext()) {
        count++;
        iter.next();
    }
    iter.close();
    assertEquals("Three time zones should be normalized when stored, then normalized same when queried.", 3, count);
    // now use batchscanner
    AccumuloRdfConfiguration queryConf = new AccumuloRdfConfiguration(conf);
    queryConf.setMaxRangesForScanner(2);
    coll = new ArrayList();
    coll.add(new RyaStatement(null, loadPerc, uri0));
    coll.add(new RyaStatement(null, loadPerc, uri1));
    coll.add(new RyaStatement(null, loadPerc, uri2));
    coll.add(new RyaStatement(null, loadPerc, uri3));
    coll.add(new RyaStatement(null, loadPerc, uri4));
    coll.add(new RyaStatement(null, loadPerc, uri5));
    coll.add(new RyaStatement(null, loadPerc, uri6));
    coll.add(new RyaStatement(null, loadPerc, uri7));
    coll.add(new RyaStatement(null, loadPerc, uri8));
    coll.add(new RyaStatement(null, loadPerc, uri9));
    iter = queryEngine.batchQuery(coll, queryConf);
    count = 0;
    while (iter.hasNext()) {
        count++;
        iter.next();
    }
    iter.close();
    assertEquals("Variety of time specs, including BC, pre-1970, duplicate pair ovewrite,future, 3 digit year.", 8, count);
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) ArrayList(java.util.ArrayList) RyaStatement(org.apache.rya.api.domain.RyaStatement) AccumuloRyaQueryEngine(org.apache.rya.accumulo.query.AccumuloRyaQueryEngine) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) RyaType(org.apache.rya.api.domain.RyaType) Test(org.junit.Test)

Example 15 with AccumuloRyaQueryEngine

use of org.apache.rya.accumulo.query.AccumuloRyaQueryEngine in project incubator-rya by apache.

the class AccumuloRyaDAOTest method testAddValue.

@Test
public void testAddValue() throws Exception {
    RyaURI cpu = new RyaURI(litdupsNS + "cpu");
    RyaURI loadPerc = new RyaURI(litdupsNS + "loadPerc");
    RyaURI uri1 = new RyaURI(litdupsNS + "uri1");
    String myval = "myval";
    byte[] columnVis = null;
    dao.add(new RyaStatement(cpu, loadPerc, uri1, null, null, columnVis, myval.getBytes()));
    AccumuloRyaQueryEngine queryEngine = dao.getQueryEngine();
    CloseableIteration<RyaStatement, RyaDAOException> iter = queryEngine.query(new RyaStatement(cpu, loadPerc, null), conf);
    assertTrue(iter.hasNext());
    assertEquals(myval, new String(iter.next().getValue()));
    iter.close();
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) RyaStatement(org.apache.rya.api.domain.RyaStatement) AccumuloRyaQueryEngine(org.apache.rya.accumulo.query.AccumuloRyaQueryEngine) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) Test(org.junit.Test)

Aggregations

AccumuloRyaQueryEngine (org.apache.rya.accumulo.query.AccumuloRyaQueryEngine)16 RyaStatement (org.apache.rya.api.domain.RyaStatement)14 RyaURI (org.apache.rya.api.domain.RyaURI)12 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)12 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)5 RyaType (org.apache.rya.api.domain.RyaType)4 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)3 IOException (java.io.IOException)2 AccumuloException (org.apache.accumulo.core.client.AccumuloException)2 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)2 AccumuloRyaDAO (org.apache.rya.accumulo.AccumuloRyaDAO)2 HashSet (java.util.HashSet)1 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)1 Connector (org.apache.accumulo.core.client.Connector)1 Instance (org.apache.accumulo.core.client.Instance)1 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)1 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)1 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)1 ZooKeeperInstance (org.apache.accumulo.core.client.ZooKeeperInstance)1