use of org.apache.rya.api.resolver.triple.TripleRow in project incubator-rya by apache.
the class RyaStatementWritable method write.
/**
* Serializes this RyaStatementWritable.
* @param dataOutput An output stream for serialized statement data.
* @throws IOException if the RyaStatement is null or otherwise can't be
* serialized.
*/
@Override
public void write(DataOutput dataOutput) throws IOException {
if (ryaStatement == null) {
throw new IOException("Rya Statement is null");
}
try {
Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> map = ryaContext.serializeTriple(ryaStatement);
TripleRow tripleRow = map.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO);
byte[] row = tripleRow.getRow();
byte[] columnFamily = tripleRow.getColumnFamily();
byte[] columnQualifier = tripleRow.getColumnQualifier();
write(dataOutput, row);
write(dataOutput, columnFamily);
write(dataOutput, columnQualifier);
write(dataOutput, ryaStatement.getColumnVisibility());
write(dataOutput, ryaStatement.getValue());
Long timestamp = ryaStatement.getTimestamp();
boolean b = timestamp != null;
dataOutput.writeBoolean(b);
if (b) {
dataOutput.writeLong(timestamp);
}
} catch (TripleRowResolverException e) {
throw new IOException(e);
}
}
use of org.apache.rya.api.resolver.triple.TripleRow in project incubator-rya by apache.
the class JoinSelectStatisticsTest method testMap1.
@Test
public void testMap1() throws Exception {
init();
System.out.println("*****************************Test1**************************** ");
BatchWriter bw_table1 = c.createBatchWriter("rya_spo", new BatchWriterConfig());
for (int i = 1; i < 3; i++) {
RyaStatement rs = new RyaStatement(new RyaURI(uri + i), new RyaURI(uri + 5), new RyaType(uri + (i + 2)));
Map<TABLE_LAYOUT, TripleRow> tripleRowMap = ryaContext.serializeTriple(rs);
TripleRow tripleRow = tripleRowMap.get(TABLE_LAYOUT.SPO);
Mutation m = JoinSelectStatsUtil.createMutation(tripleRow);
bw_table1.addMutation(m);
}
bw_table1.close();
BatchWriter bw_table2 = c.createBatchWriter("rya_prospects", new BatchWriterConfig());
for (int i = 1; i < 6; i++) {
int j = 1;
for (String s : cardList) {
Mutation m = new Mutation(new Text(s + DELIM + uri + i + DELIM + i));
m.put(new Text(), new Text(), new Value(new IntWritable(i + j).toString().getBytes()));
bw_table2.addMutation(m);
j++;
}
}
bw_table2.close();
Assert.assertEquals(0, ToolRunner.run(new JoinSelectTestDriver(), new String[] { "" }));
Scanner scan = c.createScanner("rya_selectivity", new Authorizations());
scan.setRange(new Range());
for (Map.Entry<Key, Value> entry : scan) {
System.out.println("Key row string is " + entry.getKey().getRow().toString());
System.out.println("Join type is " + entry.getKey().getColumnFamily().toString());
System.out.println("Value is " + entry.getKey().getColumnQualifier().toString());
}
Scanner scan1 = c.createScanner("rya_selectivity", new Authorizations());
scan1.setRange(Range.prefix("predicate" + DELIM + uri + 5));
int i = 5;
for (Map.Entry<Key, Value> entry : scan1) {
int val1 = 5 + 2 * i;
int val2 = 5 + 2 * (i - 1);
int val = Integer.parseInt(entry.getKey().getColumnQualifier().toString());
if (i < 3) {
Assert.assertTrue(val == val1);
}
if (i >= 3 && i < 6) {
Assert.assertTrue(val == val2);
}
i--;
}
Assert.assertTrue(i == -1);
Scanner scan2 = c.createScanner("rya_selectivity", new Authorizations());
scan2.setRange(Range.prefix("object" + DELIM + uri + 3));
int j = 5;
for (Map.Entry<Key, Value> entry : scan2) {
int val1 = 5 + (j - 2);
int val2 = 2 + j;
int val = Integer.parseInt(entry.getKey().getColumnQualifier().toString());
if (j < 3) {
Assert.assertTrue(val == val2);
}
if (j >= 3 && j < 6) {
Assert.assertTrue(val == val1);
}
j--;
}
Assert.assertTrue(j == -1);
Scanner scan3 = c.createScanner("rya_selectivity", new Authorizations());
scan3.setRange(Range.prefix("objectsubject" + DELIM + uri + 3 + DELIM + uri + 1));
int k = 8;
for (Map.Entry<Key, Value> entry : scan3) {
int val = Integer.parseInt(entry.getKey().getColumnQualifier().toString());
Assert.assertTrue(val == k);
k--;
}
Assert.assertTrue(k == 5);
}
use of org.apache.rya.api.resolver.triple.TripleRow in project incubator-rya by apache.
the class JoinSelectStatisticsTest method testMap2.
@Test
public void testMap2() throws Exception {
System.out.println("*********************Test2******************* ");
init();
BatchWriter bw_table1 = c.createBatchWriter("rya_spo", new BatchWriterConfig());
for (int i = 1; i < 4; i++) {
RyaStatement rs = new RyaStatement(new RyaURI(uri + 1), new RyaURI(uri + 2), new RyaType(uri + i));
Map<TABLE_LAYOUT, TripleRow> tripleRowMap = ryaContext.serializeTriple(rs);
TripleRow tripleRow = tripleRowMap.get(TABLE_LAYOUT.SPO);
Mutation m = JoinSelectStatsUtil.createMutation(tripleRow);
bw_table1.addMutation(m);
}
bw_table1.close();
BatchWriter bw_table2 = c.createBatchWriter("rya_prospects", new BatchWriterConfig());
for (int i = 1; i < 4; i++) {
for (String s : cardList) {
Mutation m = new Mutation(new Text(s + DELIM + uri + i + DELIM + i));
m.put(new Text(), new Text(), new Value(new IntWritable(i + 2).toString().getBytes()));
bw_table2.addMutation(m);
}
}
bw_table2.close();
Assert.assertEquals(0, ToolRunner.run(new JoinSelectTestDriver(), new String[] { "" }));
Scanner scan1 = c.createScanner("rya_selectivity", new Authorizations());
scan1.setRange(Range.prefix("subject" + DELIM + uri + 1));
int i = 0;
for (Map.Entry<Key, Value> entry : scan1) {
Assert.assertTrue(entry.getKey().getColumnQualifier().toString().equals("12"));
i++;
}
Assert.assertTrue(i == 6);
Scanner scan2 = c.createScanner("rya_selectivity", new Authorizations());
scan2.setRange(Range.prefix("predicate" + DELIM + uri + 2));
int j = 0;
for (Map.Entry<Key, Value> entry : scan2) {
if (j < 3) {
Assert.assertTrue(entry.getKey().getColumnQualifier().toString().equals("12"));
}
if (j > 3 && j < 6) {
Assert.assertTrue(entry.getKey().getColumnQualifier().toString().equals("9"));
}
j++;
}
Assert.assertTrue(j == 6);
Scanner scan3 = c.createScanner("rya_selectivity", new Authorizations());
scan3.setRange(Range.prefix("predicateobject" + DELIM + uri + 2 + DELIM + uri + 2));
int k = 0;
for (Map.Entry<Key, Value> entry : scan3) {
Assert.assertTrue(entry.getKey().getColumnQualifier().toString().equals("3"));
k++;
}
Assert.assertTrue(k == 3);
}
use of org.apache.rya.api.resolver.triple.TripleRow in project incubator-rya by apache.
the class JoinSelectStatisticsTest method testMap4.
@Test
public void testMap4() throws Exception {
init();
System.out.println("*************************Test4**************************** ");
System.out.println("*************************Test4**************************** ");
BatchWriter bw_table1 = c.createBatchWriter("rya_spo", new BatchWriterConfig());
for (int i = 1; i < 3; i++) {
for (int j = 1; j < 3; j++) {
for (int k = 1; k < 3; k++) {
if (j == 1 && k == 2) {
break;
}
RyaStatement rs = new RyaStatement(new RyaURI(uri + i), new RyaURI(uri + (j)), new RyaType(uri + k));
Map<TABLE_LAYOUT, TripleRow> tripleRowMap = ryaContext.serializeTriple(rs);
TripleRow tripleRow = tripleRowMap.get(TABLE_LAYOUT.SPO);
Mutation m = JoinSelectStatsUtil.createMutation(tripleRow);
bw_table1.addMutation(m);
}
}
}
bw_table1.close();
BatchWriter bw_table2 = c.createBatchWriter("rya_prospects", new BatchWriterConfig());
for (int i = 1; i < 3; i++) {
int k = 1;
for (String s : cardList) {
Mutation m = new Mutation(new Text(s + DELIM + uri + i + DELIM + i));
m.put(new Text(), new Text(), new Value(new IntWritable(i + k).toString().getBytes()));
bw_table2.addMutation(m);
k++;
}
for (int j = 1; j < 3; j++) {
k = 1;
for (String s : aggCardList) {
Mutation m = new Mutation(new Text(s + DELIM + uri + i + DELIM + uri + j + DELIM + i));
m.put(new Text(), new Text(), new Value(new IntWritable(i + k + 2 * j).toString().getBytes()));
bw_table2.addMutation(m);
k++;
}
}
}
bw_table2.close();
Assert.assertEquals(0, ToolRunner.run(new JoinSelectTestDriver(), new String[] { "" }));
Scanner scan = c.createScanner("rya_selectivity", new Authorizations());
scan.setRange(new Range());
for (Map.Entry<Key, Value> entry : scan) {
System.out.println("Key row string is " + entry.getKey().getRow().toString());
System.out.println("Join type is " + entry.getKey().getColumnFamily().toString());
System.out.println("Value is " + entry.getKey().getColumnQualifier().toString());
}
Scanner scan1 = c.createScanner("rya_selectivity", new Authorizations());
scan1.setRange(Range.prefix("subject" + DELIM + uri + 1));
int i = 0;
for (Map.Entry<Key, Value> entry : scan1) {
Key key = entry.getKey();
String s = key.getColumnFamily().toString();
int val = Integer.parseInt(key.getColumnQualifier().toString());
if (s.equals("predicatepredicate")) {
Assert.assertTrue(val == 11);
}
if (s.equals("objectobject")) {
Assert.assertTrue(val == 13);
}
if (s.equals("predicateobjectobjectpredicate")) {
Assert.assertTrue(val == 26);
}
if (s.equals("predicateobjectpredicateobject")) {
Assert.assertTrue(val == 25);
}
if (s.equals("predicateobjectsubjectpredicate")) {
Assert.assertTrue(val == 19);
}
if (s.equals("predicateobjectpredicatesubject")) {
Assert.assertTrue(val == 20);
}
i++;
}
Assert.assertTrue(i == 12);
Scanner scan2 = c.createScanner("rya_selectivity", new Authorizations());
scan2.setRange(Range.prefix("predicate" + DELIM + uri + 1));
int j = 0;
for (Map.Entry<Key, Value> entry : scan2) {
Key key = entry.getKey();
String s = key.getColumnFamily().toString();
int val = Integer.parseInt(key.getColumnQualifier().toString());
if (s.equals("subjectsubject")) {
Assert.assertTrue(val == 5);
}
if (s.equals("objectobject")) {
Assert.assertTrue(val == 8);
}
if (s.equals("objectsubjectsubjectpredicate")) {
Assert.assertTrue(val == 11);
}
if (s.equals("objectsubjectpredicateobject")) {
Assert.assertTrue(val == 15);
}
if (s.equals("objectsubjectobjectsubject")) {
Assert.assertTrue(val == 9);
}
if (s.equals("objectsubjectsubjectobject")) {
Assert.assertTrue(val == 10);
}
j++;
}
Assert.assertTrue(j == 12);
}
use of org.apache.rya.api.resolver.triple.TripleRow in project incubator-rya by apache.
the class HashedSpoWholeRowTriplePatternStrategyTest method testS.
public void testS() throws Exception {
Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaTripleContext.serializeTriple(new RyaStatement(uri, uri, uri, null));
TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO);
Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(uri, null, null, null, null);
assertContains(entry.getValue(), tripleRow.getRow());
entry = strategy.defineRange(uri2, null, null, null, null);
assertContainsFalse(entry.getValue(), tripleRow.getRow());
}
Aggregations