use of org.apache.rya.api.domain.RyaURI in project incubator-rya by apache.
the class MongoDbSmartUriIT method testUpdate.
@Test
public void testUpdate() throws SmartUriException {
smartUriConverter.storeEntity(BOB_ENTITY);
// New properties to add
final RyaURI hasNickName = createRyaUri("hasNickName");
final RyaURI hasWindowOffice = createRyaUri("hasWindowOffice");
final Entity.Builder builder = Entity.builder(BOB_ENTITY);
builder.setProperty(PERSON_TYPE_URI, new Property(HAS_AGE, shortRyaType((short) 41)));
builder.setProperty(PERSON_TYPE_URI, new Property(hasNickName, stringRyaType("Bobby")));
builder.setProperty(EMPLOYEE_TYPE_URI, new Property(HAS_POSITION_TITLE, stringRyaType("Assistant Regional Manager")));
builder.setProperty(EMPLOYEE_TYPE_URI, new Property(hasWindowOffice, booleanRyaType(true)));
builder.setVersion(BOB_ENTITY.getVersion() + 1);
builder.rebuildSmartUri();
final Entity newBobEntity = builder.build();
smartUriConverter.updateEntity(BOB_ENTITY, newBobEntity);
final Entity resultEntity = smartUriConverter.queryEntity(BOB_ENTITY.getSubject());
assertEquals(newBobEntity.getVersion(), resultEntity.getVersion());
assertEquals(newBobEntity.lookupTypeProperty(PERSON_TYPE, HAS_AGE), resultEntity.lookupTypeProperty(PERSON_TYPE, HAS_AGE));
assertEquals(newBobEntity.lookupTypeProperty(PERSON_TYPE, hasNickName), resultEntity.lookupTypeProperty(PERSON_TYPE, hasNickName));
assertEquals(newBobEntity.lookupTypeProperty(EMPLOYEE_TYPE, HAS_POSITION_TITLE), resultEntity.lookupTypeProperty(EMPLOYEE_TYPE, HAS_POSITION_TITLE));
assertEquals(newBobEntity.lookupTypeProperty(EMPLOYEE_TYPE, hasWindowOffice), resultEntity.lookupTypeProperty(EMPLOYEE_TYPE, hasWindowOffice));
assertEquals(newBobEntity.getSmartUri(), resultEntity.getSmartUri());
final String resultUriString = resultEntity.getSmartUri().stringValue();
assertTrue(resultUriString.contains(getRyaUriLocalName(hasWindowOffice)));
assertTrue(resultUriString.contains(getRyaUriLocalName(hasNickName)));
}
use of org.apache.rya.api.domain.RyaURI in project incubator-rya by apache.
the class MongoEntityIndexIT method setupTypes.
private void setupTypes(MongoEntityIndexer indexer) throws Exception {
final TypeStorage typeStore = indexer.getTypeStorage();
// Add some Types to the storage.
final Type cat = new Type(new RyaURI("urn:cat"), ImmutableSet.<RyaURI>builder().add(new RyaURI("urn:numLegs")).add(new RyaURI("urn:eye")).add(new RyaURI("urn:species")).build());
final Type dog = new Type(new RyaURI("urn:dog"), ImmutableSet.<RyaURI>builder().add(new RyaURI("urn:numLegs")).add(new RyaURI("urn:eye")).add(new RyaURI("urn:species")).build());
final Type icecream = new Type(new RyaURI("urn:icecream"), ImmutableSet.<RyaURI>builder().add(new RyaURI("urn:brand")).add(new RyaURI("urn:flavor")).add(new RyaURI("urn:cost")).build());
final Type person = new Type(new RyaURI("urn:person"), ImmutableSet.<RyaURI>builder().add(new RyaURI("urn:name")).add(new RyaURI("urn:age")).add(new RyaURI("urn:eye")).build());
typeStore.create(cat);
typeStore.create(dog);
typeStore.create(icecream);
typeStore.create(person);
}
use of org.apache.rya.api.domain.RyaURI in project incubator-rya by apache.
the class MongoEntityIndexIT method ensureInEntityStore_Test.
@Test
public void ensureInEntityStore_Test() throws Exception {
final Sail sail = RyaSailFactory.getInstance(conf);
SailRepositoryConnection conn = new SailRepository(sail).getConnection();
conn.begin();
try (MongoEntityIndexer indexer = new MongoEntityIndexer()) {
indexer.setConf(conf);
indexer.init();
setupTypes(indexer);
addStatements(conn);
final EntityStorage entities = indexer.getEntityStorage();
final RyaURI subject = new RyaURI("urn:alice");
final Optional<Entity> alice = entities.get(subject);
assertTrue(alice.isPresent());
} finally {
conn.close();
}
}
use of org.apache.rya.api.domain.RyaURI in project incubator-rya by apache.
the class AccumuloIndexingConfigurationTest method testBuilderFromProperties.
@Test
public void testBuilderFromProperties() throws FileNotFoundException, IOException {
String prefix = "rya_";
String auth = "U";
String visibility = "U";
String user = "user";
String password = "password";
String instance = "instance";
String zookeeper = "zookeeper";
boolean useMock = false;
boolean useComposite = true;
boolean usePrefixHash = true;
boolean useInference = true;
boolean displayPlan = false;
boolean useMetadata = true;
Set<RyaURI> metaProperties = new HashSet<>(Arrays.asList(new RyaURI("urn:123"), new RyaURI("urn:456")));
Properties props = new Properties();
props.load(new FileInputStream("src/test/resources/accumulo_rya_indexing.properties"));
AccumuloIndexingConfiguration conf = AccumuloIndexingConfiguration.fromProperties(props);
assertEquals(conf.getTablePrefix(), prefix);
assertEquals(conf.getCv(), visibility);
assertEquals(conf.getAuthorizations(), new Authorizations(auth));
assertEquals(conf.isInfer(), useInference);
assertEquals(conf.isUseCompositeCardinality(), useComposite);
assertEquals(conf.isDisplayQueryPlan(), displayPlan);
assertEquals(conf.getAccumuloInstance(), instance);
assertEquals(conf.getAccumuloPassword(), password);
assertEquals(conf.getAccumuloUser(), user);
assertEquals(conf.getAccumuloZookeepers(), zookeeper);
assertEquals(conf.getUseMockAccumulo(), useMock);
assertEquals(conf.isPrefixRowsWithHash(), usePrefixHash);
assertTrue(Arrays.equals(conf.getAccumuloFreeTextPredicates(), new String[] { "http://pred1", "http://pred2" }));
assertTrue(Arrays.equals(conf.getAccumuloTemporalPredicates(), new String[] { "http://pred3", "http://pred4" }));
assertEquals(conf.getPcjTables(), Arrays.asList("table1", "table2"));
assertEquals(conf.getUsePCJ(), false);
assertEquals(conf.getUseOptimalPCJ(), true);
assertEquals(conf.getUseEntity(), true);
assertEquals(conf.getUseFreetext(), true);
assertEquals(conf.getUseTemporal(), true);
assertEquals(conf.getUsePCJUpdater(), true);
assertEquals(conf.getFluoAppUpdaterName(), "fluo");
assertEquals(conf.getUseStatementMetadata(), useMetadata);
assertEquals(conf.getStatementMetadataProperties(), metaProperties);
}
use of org.apache.rya.api.domain.RyaURI in project incubator-rya by apache.
the class AccumuloDocIndexerTest method testContextCommonVarBs1.
@Test
public void testContextCommonVarBs1() throws Exception {
BatchWriter bw = null;
RyaTableMutationsFactory rtm = new RyaTableMutationsFactory(RyaTripleContext.getInstance(conf));
bw = accCon.createBatchWriter(tableName, 500L * 1024L * 1024L, Long.MAX_VALUE, 30);
for (int i = 0; i < 30; i++) {
RyaStatement rs1 = new RyaStatement(new RyaURI("uri:" + i), new RyaURI("uri:cf1"), new RyaURI("uri:cq1"), new RyaURI("uri:joe"));
RyaStatement rs2 = new RyaStatement(new RyaURI("uri:" + i), new RyaURI("uri:cf2"), new RyaType(XMLSchema.STRING, "cq2"), new RyaURI("uri:joe"));
RyaStatement rs3 = null;
RyaStatement rs4 = new RyaStatement(new RyaURI("uri:" + i), new RyaURI("uri:cf1"), new RyaURI("uri:cq1"), new RyaURI("uri:hank"));
RyaStatement rs5 = new RyaStatement(new RyaURI("uri:" + i), new RyaURI("uri:cf2"), new RyaType(XMLSchema.STRING, "cq2"), new RyaURI("uri:hank"));
RyaStatement rs6 = null;
if (i == 5 || i == 10 || i == 15 || i == 20 || i == 25) {
rs3 = new RyaStatement(new RyaURI("uri:" + i), new RyaURI("uri:cf3"), new RyaType(XMLSchema.INTEGER, Integer.toString(i)), new RyaURI("uri:joe"));
rs6 = new RyaStatement(new RyaURI("uri:" + i), new RyaURI("uri:cf3"), new RyaType(XMLSchema.INTEGER, Integer.toString(i)), new RyaURI("uri:hank"));
}
Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Collection<Mutation>> serialize1 = rtm.serialize(rs1);
Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Collection<Mutation>> serialize2 = rtm.serialize(rs2);
Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Collection<Mutation>> serialize3 = null;
Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Collection<Mutation>> serialize4 = rtm.serialize(rs4);
Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Collection<Mutation>> serialize5 = rtm.serialize(rs5);
Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Collection<Mutation>> serialize6 = null;
if (rs3 != null) {
serialize3 = rtm.serialize(rs3);
}
if (rs6 != null) {
serialize6 = rtm.serialize(rs6);
}
Collection<Mutation> m1 = EntityCentricIndex.createMutations(rs1);
for (Mutation m : m1) {
bw.addMutation(m);
}
Collection<Mutation> m2 = EntityCentricIndex.createMutations(rs2);
for (Mutation m : m2) {
bw.addMutation(m);
}
if (serialize3 != null) {
Collection<Mutation> m3 = EntityCentricIndex.createMutations(rs3);
for (Mutation m : m3) {
bw.addMutation(m);
}
}
Collection<Mutation> m4 = EntityCentricIndex.createMutations(rs4);
for (Mutation m : m4) {
bw.addMutation(m);
}
Collection<Mutation> m5 = EntityCentricIndex.createMutations(rs5);
for (Mutation m : m5) {
bw.addMutation(m);
}
if (serialize6 != null) {
Collection<Mutation> m6 = EntityCentricIndex.createMutations(rs6);
for (Mutation m : m6) {
bw.addMutation(m);
}
}
}
String q1 = //
"" + //
"SELECT ?X ?Y1 ?Y2 ?Y3 " + //
"{" + //
"?X <uri:cf1> ?Y1 ." + //
"?X <uri:cf2> ?Y2 ." + //
"?X <uri:cf3> ?Y3 ." + "}";
String q2 = //
"" + //
"SELECT ?X ?Y1 ?Y2 ?Y3 " + //
"{" + //
" GRAPH <uri:hank> { " + //
"?X <uri:cf1> ?Y1 ." + //
"?X <uri:cf2> ?Y2 ." + //
"?X <uri:cf3> ?Y3 ." + //
" } " + "}";
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq1 = parser.parseQuery(q1, null);
TupleExpr te1 = pq1.getTupleExpr();
List<StatementPattern> spList1 = StatementPatternCollector.process(te1);
Assert.assertTrue(StarQuery.isValidStarQuery(spList1));
StarQuery sq1 = new StarQuery(spList1);
AccumuloDocIdIndexer adi = new AccumuloDocIdIndexer(conf);
Value v1 = RyaToRdfConversions.convertValue(new RyaType(XMLSchema.INTEGER, Integer.toString(5)));
Value v2 = RyaToRdfConversions.convertValue(new RyaType(XMLSchema.INTEGER, Integer.toString(25)));
List<BindingSet> bsList = Lists.newArrayList();
QueryBindingSet b1 = (new QueryBindingSet());
b1.addBinding("X", vf.createURI("uri:5"));
QueryBindingSet b2 = (new QueryBindingSet());
b2.addBinding("X", vf.createURI("uri:15"));
QueryBindingSet b3 = (new QueryBindingSet());
b3.addBinding("X", vf.createURI("uri:25"));
bsList.add(b1);
bsList.add(b2);
bsList.add(b3);
CloseableIteration<BindingSet, QueryEvaluationException> sol1 = adi.queryDocIndex(sq1, bsList);
System.out.println("**********************TEST 12***********************");
int results = 0;
while (sol1.hasNext()) {
System.out.println(sol1.next());
results++;
}
Assert.assertEquals(6, results);
ParsedQuery pq2 = parser.parseQuery(q2, null);
TupleExpr te2 = pq2.getTupleExpr();
List<StatementPattern> spList2 = StatementPatternCollector.process(te2);
Assert.assertTrue(StarQuery.isValidStarQuery(spList2));
StarQuery sq2 = new StarQuery(spList2);
CloseableIteration<BindingSet, QueryEvaluationException> sol2 = adi.queryDocIndex(sq2, bsList);
System.out.println("**********************TEST 12***********************");
results = 0;
while (sol2.hasNext()) {
System.out.println(sol2.next());
results++;
}
Assert.assertEquals(3, results);
adi.close();
}
Aggregations