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;
}
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);
}
}
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);
}
}
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;
}
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);
}
}
Aggregations