Search in sources :

Example 26 with TripleRow

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);
    }
}
Also used : TripleRowResolverException(org.apache.rya.api.resolver.triple.TripleRowResolverException) TripleRow(org.apache.rya.api.resolver.triple.TripleRow) IOException(java.io.IOException)

Example 27 with TripleRow

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);
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) RyaStatement(org.apache.rya.api.domain.RyaStatement) Text(org.apache.hadoop.io.Text) RyaType(org.apache.rya.api.domain.RyaType) Range(org.apache.accumulo.core.data.Range) RyaURI(org.apache.rya.api.domain.RyaURI) TABLE_LAYOUT(org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT) TripleRow(org.apache.rya.api.resolver.triple.TripleRow) Value(org.apache.accumulo.core.data.Value) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Map(java.util.Map) IntWritable(org.apache.hadoop.io.IntWritable) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 28 with TripleRow

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);
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) RyaStatement(org.apache.rya.api.domain.RyaStatement) Text(org.apache.hadoop.io.Text) RyaType(org.apache.rya.api.domain.RyaType) RyaURI(org.apache.rya.api.domain.RyaURI) TABLE_LAYOUT(org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT) TripleRow(org.apache.rya.api.resolver.triple.TripleRow) Value(org.apache.accumulo.core.data.Value) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Map(java.util.Map) IntWritable(org.apache.hadoop.io.IntWritable) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 29 with TripleRow

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);
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) RyaStatement(org.apache.rya.api.domain.RyaStatement) Text(org.apache.hadoop.io.Text) RyaType(org.apache.rya.api.domain.RyaType) Range(org.apache.accumulo.core.data.Range) RyaURI(org.apache.rya.api.domain.RyaURI) TABLE_LAYOUT(org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT) TripleRow(org.apache.rya.api.resolver.triple.TripleRow) Value(org.apache.accumulo.core.data.Value) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Map(java.util.Map) IntWritable(org.apache.hadoop.io.IntWritable) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 30 with TripleRow

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());
}
Also used : TripleRow(org.apache.rya.api.resolver.triple.TripleRow) ByteRange(org.apache.rya.api.query.strategy.ByteRange) RyaStatement(org.apache.rya.api.domain.RyaStatement) Map(java.util.Map)

Aggregations

TripleRow (org.apache.rya.api.resolver.triple.TripleRow)55 RyaStatement (org.apache.rya.api.domain.RyaStatement)42 RyaURI (org.apache.rya.api.domain.RyaURI)21 Map (java.util.Map)19 TABLE_LAYOUT (org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT)17 Key (org.apache.accumulo.core.data.Key)14 Value (org.apache.accumulo.core.data.Value)13 ByteRange (org.apache.rya.api.query.strategy.ByteRange)13 TripleRowResolverException (org.apache.rya.api.resolver.triple.TripleRowResolverException)13 RyaType (org.apache.rya.api.domain.RyaType)11 RdfCloudTripleStoreConstants (org.apache.rya.api.RdfCloudTripleStoreConstants)8 Test (org.junit.Test)8 IOException (java.io.IOException)7 Text (org.apache.hadoop.io.Text)7 Mutation (org.apache.accumulo.core.data.Mutation)6 Scanner (org.apache.accumulo.core.client.Scanner)5 Authorizations (org.apache.accumulo.core.security.Authorizations)5 IntWritable (org.apache.hadoop.io.IntWritable)5 HashMap (java.util.HashMap)4 BatchWriter (org.apache.accumulo.core.client.BatchWriter)4