use of org.apache.rya.api.domain.RyaType in project incubator-rya by apache.
the class Upgrade322ToolTest method testUpgrade.
public void testUpgrade() throws Exception {
Upgrade322Tool.main(new String[] { "-Dac.mock=true", "-Dac.instance=" + instance, "-Dac.username=" + user, "-Dac.pwd=" + pwd, "-Drdf.tablePrefix=" + tablePrefix });
final AccumuloRdfConfiguration configuration = new AccumuloRdfConfiguration();
configuration.setTablePrefix(tablePrefix);
final AccumuloRyaDAO ryaDAO = new AccumuloRyaDAO();
ryaDAO.setConnector(connector);
ryaDAO.setConf(configuration);
ryaDAO.init();
final AccumuloRyaQueryEngine queryEngine = ryaDAO.getQueryEngine();
TestUtils.verify(new RyaStatement(new RyaURI("http://here/2010/tracked-data-provenance/ns#uuid10"), new RyaURI("http://here/2010/tracked-data-provenance/ns#booleanLit"), new RyaType(XMLSchema.BOOLEAN, "true")), queryEngine);
TestUtils.verify(new RyaStatement(new RyaURI("http://here/2010/tracked-data-provenance/ns#uuid10"), new RyaURI("http://here/2010/tracked-data-provenance/ns#longLit"), new RyaType(XMLSchema.LONG, "10")), queryEngine);
TestUtils.verify(new RyaStatement(new RyaURI("http://here/2010/tracked-data-provenance/ns#uuid10"), new RyaURI("http://here/2010/tracked-data-provenance/ns#intLit"), new RyaType(XMLSchema.INTEGER, "10")), queryEngine);
TestUtils.verify(new RyaStatement(new RyaURI("http://here/2010/tracked-data-provenance/ns#uuid10"), new RyaURI("http://here/2010/tracked-data-provenance/ns#byteLit"), new RyaType(XMLSchema.BYTE, "10")), queryEngine);
TestUtils.verify(new RyaStatement(new RyaURI("http://here/2010/tracked-data-provenance/ns#uuid10"), new RyaURI("http://here/2010/tracked-data-provenance/ns#doubleLit"), new RyaType(XMLSchema.DOUBLE, "10.0")), queryEngine);
TestUtils.verify(new RyaStatement(new RyaURI("http://here/2010/tracked-data-provenance/ns#uuid10"), new RyaURI("http://here/2010/tracked-data-provenance/ns#dateLit"), new RyaType(XMLSchema.DATETIME, "2011-07-12T06:00:00.000Z")), queryEngine);
TestUtils.verify(new RyaStatement(new RyaURI("http://here/2010/tracked-data-provenance/ns#uuid10"), new RyaURI("http://here/2010/tracked-data-provenance/ns#stringLit"), new RyaType("stringLit")), queryEngine);
TestUtils.verify(new RyaStatement(new RyaURI("http://here/2010/tracked-data-provenance/ns#uuid10"), new RyaURI("http://here/2010/tracked-data-provenance/ns#uriLit"), new RyaURI("http://here/2010/tracked-data-provenance/ns" + "#objectuuid1")), queryEngine);
TestUtils.verify(new RyaStatement(new RyaURI("urn:org.apache.rya/2012/05#rts"), new RyaURI("urn:org.apache.rya/2012/05#version"), new RyaType("3.0.0")), queryEngine);
}
use of org.apache.rya.api.domain.RyaType in project incubator-rya by apache.
the class RyaTypeWritable method equals.
/**
* Tests for equality using the equals method of the enclosed RyaType.
* @param o Object to compare with
* @return true if both objects are RyaTypeWritables containing equivalent
* RyaTypes.
*/
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o == null || !(o instanceof RyaTypeWritable)) {
return false;
}
RyaType rtThis = ryatype;
RyaType rtOther = ((RyaTypeWritable) o).ryatype;
if (rtThis == null) {
return rtOther == null;
} else {
return rtThis.equals(rtOther);
}
}
use of org.apache.rya.api.domain.RyaType in project incubator-rya by apache.
the class StarQuery method setValue.
private TextColumn setValue(final TextColumn tc, final Value v) throws RyaTypeResolverException {
final String cq = tc.getColumnQualifier().toString();
final String[] cqArray = cq.split("\u0000");
if (cqArray[0].equals("subject")) {
// RyaURI subjURI = (RyaURI) RdfToRyaConversions.convertValue(v);
tc.setColumnQualifier(new Text("subject" + "\u0000" + v.stringValue()));
tc.setIsPrefix(false);
} else if (cqArray[0].equals("object")) {
final RyaType objType = RdfToRyaConversions.convertValue(v);
final byte[][] b1 = RyaContext.getInstance().serializeType(objType);
final byte[] b2 = Bytes.concat("object".getBytes(StandardCharsets.UTF_8), "\u0000".getBytes(StandardCharsets.UTF_8), b1[0], b1[1]);
tc.setColumnQualifier(new Text(b2));
tc.setIsPrefix(false);
} else {
throw new IllegalStateException("Invalid direction!");
}
return tc;
}
use of org.apache.rya.api.domain.RyaType in project incubator-rya by apache.
the class StarQuery method nodeToTextColumn.
// assumes nodes forms valid star query with only one common variable
// assumes nodes and commonVar has been set
private TextColumn nodeToTextColumn(final StatementPattern node, final int i) throws RyaTypeResolverException {
final RyaContext rc = RyaContext.getInstance();
final Var subjVar = node.getSubjectVar();
final Var predVar = node.getPredicateVar();
final Var objVar = node.getObjectVar();
final RyaURI predURI = (RyaURI) RdfToRyaConversions.convertValue(node.getPredicateVar().getValue());
// assumes StatementPattern contains at least on variable
if (subjVar.isConstant()) {
if (commonVarConstant()) {
varPos.put(objVar.getName(), i);
return new TextColumn(new Text(predURI.getData()), new Text("object"));
} else {
return new TextColumn(new Text(predURI.getData()), new Text("subject" + "\u0000" + subjVar.getValue().stringValue()));
}
} else if (objVar.isConstant()) {
if (commonVarConstant()) {
varPos.put(subjVar.getName(), i);
return new TextColumn(new Text(predURI.getData()), new Text("subject"));
} else {
isCommonVarURI = true;
final RyaType objType = RdfToRyaConversions.convertValue(objVar.getValue());
final byte[][] b1 = rc.serializeType(objType);
final byte[] b2 = Bytes.concat("object".getBytes(StandardCharsets.UTF_8), "\u0000".getBytes(StandardCharsets.UTF_8), b1[0], b1[1]);
return new TextColumn(new Text(predURI.getData()), new Text(b2));
}
} else {
if (subjVar.getName().equals(commonVarName)) {
isCommonVarURI = true;
varPos.put(objVar.getName(), i);
final TextColumn tc = new TextColumn(new Text(predURI.getData()), new Text("object"));
tc.setIsPrefix(true);
return tc;
} else {
varPos.put(subjVar.getName(), i);
final TextColumn tc = new TextColumn(new Text(predURI.getData()), new Text("subject"));
tc.setIsPrefix(true);
return tc;
}
}
}
use of org.apache.rya.api.domain.RyaType in project incubator-rya by apache.
the class EntityQueryNode method findBindings.
private List<BindingSet> findBindings(final BindingSet bindingSet) throws QueryEvaluationException {
final MapBindingSet resultSet = new MapBindingSet();
try {
final ConvertingCursor<TypedEntity> entitiesCursor;
final String subj;
// If the subject needs to be filled in, check if the subject variable is in the binding set.
if (subjectIsConstant) {
// if it is, fetch that value and then fetch the entity for the subject.
subj = subjectConstant.get();
entitiesCursor = entities.search(Optional.of(new RyaURI(subj)), type, properties);
} else {
entitiesCursor = entities.search(Optional.empty(), type, properties);
}
while (entitiesCursor.hasNext()) {
final TypedEntity typedEntity = entitiesCursor.next();
final ImmutableCollection<Property> properties = typedEntity.getProperties();
// ensure properties match and only add properties that are in the statement patterns to the binding set
for (final RyaURI key : objectVariables.keySet()) {
final Optional<RyaType> prop = typedEntity.getPropertyValue(new RyaURI(key.getData()));
if (prop.isPresent()) {
final RyaType type = prop.get();
final String bindingName = objectVariables.get(key).getName();
resultSet.addBinding(bindingName, ValueFactoryImpl.getInstance().createLiteral(type.getData()));
}
}
}
} catch (final EntityStorageException e) {
throw new QueryEvaluationException("Failed to evaluate the binding set", e);
}
bindingSet.forEach(new Consumer<Binding>() {
@Override
public void accept(final Binding binding) {
resultSet.addBinding(binding);
}
});
final List<BindingSet> list = new ArrayList<>();
list.add(resultSet);
return list;
}
Aggregations