Search in sources :

Example 1 with RdfDAOException

use of org.apache.rya.api.persist.RdfDAOException in project incubator-rya by apache.

the class ProspectorServiceEvalStatsDAO method getCardinality.

@Override
public double getCardinality(RdfCloudTripleStoreConfiguration conf, CARDINALITY_OF card, List<Value> val) throws RdfDAOException {
    assert conf != null && card != null && val != null;
    String triplePart = null;
    switch(card) {
        case SUBJECT:
            triplePart = TripleValueType.SUBJECT.getIndexType();
            break;
        case PREDICATE:
            triplePart = TripleValueType.PREDICATE.getIndexType();
            break;
        case OBJECT:
            triplePart = TripleValueType.OBJECT.getIndexType();
            break;
        case SUBJECTPREDICATE:
            triplePart = TripleValueType.SUBJECT_PREDICATE.getIndexType();
            break;
        case SUBJECTOBJECT:
            triplePart = TripleValueType.SUBJECT_OBJECT.getIndexType();
            break;
        case PREDICATEOBJECT:
            triplePart = TripleValueType.PREDICATE_OBJECT.getIndexType();
            break;
    }
    final String[] auths = conf.getAuths();
    final List<String> indexedValues = new ArrayList<>();
    final Iterator<Value> valueIt = val.iterator();
    while (valueIt.hasNext()) {
        indexedValues.add(valueIt.next().stringValue());
    }
    double cardinality = -1;
    try {
        final List<IndexEntry> entries = prospectorService.query(null, ProspectorConstants.COUNT, triplePart, indexedValues, null, auths);
        if (!entries.isEmpty()) {
            cardinality = entries.iterator().next().getCount();
        }
    } catch (final TableNotFoundException e) {
        throw new RdfDAOException(e);
    }
    return cardinality;
}
Also used : TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) ArrayList(java.util.ArrayList) Value(org.openrdf.model.Value) IndexEntry(org.apache.rya.prospector.domain.IndexEntry) RdfDAOException(org.apache.rya.api.persist.RdfDAOException)

Example 2 with RdfDAOException

use of org.apache.rya.api.persist.RdfDAOException in project incubator-rya by apache.

the class AccumuloNamespaceTableIterator method close.

@Override
public void close() throws RdfDAOException {
    try {
        verifyIsOpen();
        open = false;
    } catch (final IOError e) {
        throw new RdfDAOException(e);
    }
}
Also used : IOError(java.io.IOError) RdfDAOException(org.apache.rya.api.persist.RdfDAOException)

Example 3 with RdfDAOException

use of org.apache.rya.api.persist.RdfDAOException in project incubator-rya by apache.

the class AccumuloRdfEvalStatsDAO method init.

@Override
public void init() throws RdfDAOException {
    try {
        if (isInitialized()) {
            throw new IllegalStateException("Already initialized");
        }
        checkNotNull(connector);
        tableLayoutStrategy = conf.getTableLayoutStrategy();
        // evalTable = conf.get(RdfCloudTripleStoreConfiguration.CONF_TBL_EVAL, evalTable);
        // conf.set(RdfCloudTripleStoreConfiguration.CONF_TBL_EVAL, evalTable);
        final TableOperations tos = connector.tableOperations();
        AccumuloRdfUtils.createTableIfNotExist(tos, tableLayoutStrategy.getEval());
        // boolean tableExists = tos.exists(evalTable);
        // if (!tableExists)
        // tos.create(evalTable);
        isInitialized.set(true);
    } catch (final Exception e) {
        throw new RdfDAOException(e);
    }
}
Also used : TableOperations(org.apache.accumulo.core.client.admin.TableOperations) RdfDAOException(org.apache.rya.api.persist.RdfDAOException) RdfDAOException(org.apache.rya.api.persist.RdfDAOException)

Example 4 with RdfDAOException

use of org.apache.rya.api.persist.RdfDAOException in project incubator-rya by apache.

the class AccumuloRdfEvalStatsDAO method getCardinality.

@Override
public double getCardinality(final AccumuloRdfConfiguration conf, final RdfEvalStatsDAO.CARDINALITY_OF card, final List<Value> val, final Resource context) throws RdfDAOException {
    try {
        final Authorizations authorizations = conf.getAuthorizations();
        final Scanner scanner = connector.createScanner(tableLayoutStrategy.getEval(), authorizations);
        Text cfTxt = null;
        if (CARDINALITY_OF.SUBJECT.equals(card)) {
            cfTxt = SUBJECT_CF_TXT;
        } else if (CARDINALITY_OF.PREDICATE.equals(card)) {
            cfTxt = PRED_CF_TXT;
        } else if (CARDINALITY_OF.OBJECT.equals(card)) {
            // cfTxt = OBJ_CF_TXT;     //TODO: How do we do object cardinality
            return Double.MAX_VALUE;
        } else if (CARDINALITY_OF.SUBJECTOBJECT.equals(card)) {
            cfTxt = SUBJECTOBJECT_CF_TXT;
        } else if (CARDINALITY_OF.SUBJECTPREDICATE.equals(card)) {
            cfTxt = SUBJECTPRED_CF_TXT;
        } else if (CARDINALITY_OF.PREDICATEOBJECT.equals(card)) {
            cfTxt = PREDOBJECT_CF_TXT;
        } else {
            throw new IllegalArgumentException("Not right Cardinality[" + card + "]");
        }
        Text cq = EMPTY_TEXT;
        if (context != null) {
            cq = new Text(context.stringValue().getBytes(StandardCharsets.UTF_8));
        }
        scanner.fetchColumn(cfTxt, cq);
        final Iterator<Value> vals = val.iterator();
        String compositeIndex = vals.next().stringValue();
        while (vals.hasNext()) {
            compositeIndex += DELIM + vals.next().stringValue();
        }
        scanner.setRange(new Range(new Text(compositeIndex.getBytes(StandardCharsets.UTF_8))));
        final Iterator<Map.Entry<Key, org.apache.accumulo.core.data.Value>> iter = scanner.iterator();
        if (iter.hasNext()) {
            return Double.parseDouble(new String(iter.next().getValue().get(), StandardCharsets.UTF_8));
        }
    } catch (final Exception e) {
        throw new RdfDAOException(e);
    }
    // default
    return -1;
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range) RdfDAOException(org.apache.rya.api.persist.RdfDAOException) Value(org.openrdf.model.Value) RdfDAOException(org.apache.rya.api.persist.RdfDAOException)

Example 5 with RdfDAOException

use of org.apache.rya.api.persist.RdfDAOException in project incubator-rya by apache.

the class AccumuloSelectivityEvalDAO method init.

@Override
public void init() throws RdfDAOException {
    try {
        if (isInitialized()) {
            throw new IllegalStateException("Already initialized");
        }
        if (!resd.isInitialized()) {
            resd.init();
        }
        checkNotNull(connector);
        tableLayoutStrategy = conf.getTableLayoutStrategy();
        TableOperations tos = connector.tableOperations();
        AccumuloRdfUtils.createTableIfNotExist(tos, tableLayoutStrategy.getSelectivity());
        AccumuloRdfUtils.createTableIfNotExist(tos, tableLayoutStrategy.getProspects());
        initialized = true;
    } catch (Exception e) {
        throw new RdfDAOException(e);
    }
}
Also used : TableOperations(org.apache.accumulo.core.client.admin.TableOperations) RdfDAOException(org.apache.rya.api.persist.RdfDAOException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) RdfDAOException(org.apache.rya.api.persist.RdfDAOException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) AccumuloException(org.apache.accumulo.core.client.AccumuloException)

Aggregations

RdfDAOException (org.apache.rya.api.persist.RdfDAOException)5 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)2 TableOperations (org.apache.accumulo.core.client.admin.TableOperations)2 Value (org.openrdf.model.Value)2 IOError (java.io.IOError)1 ArrayList (java.util.ArrayList)1 AccumuloException (org.apache.accumulo.core.client.AccumuloException)1 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)1 Scanner (org.apache.accumulo.core.client.Scanner)1 Range (org.apache.accumulo.core.data.Range)1 Authorizations (org.apache.accumulo.core.security.Authorizations)1 Text (org.apache.hadoop.io.Text)1 IndexEntry (org.apache.rya.prospector.domain.IndexEntry)1