Java Code Examples for org.apache.accumulo.core.client.BatchWriter#addMutation()

The following examples show how to use org.apache.accumulo.core.client.BatchWriter#addMutation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CountIT.java    From accumulo-examples with Apache License 2.0 6 votes vote down vote up
@Before
public void setupInstance() throws Exception {
  tableName = getUniqueNames(1)[0];
  client = Accumulo.newClient().from(getClientProperties()).build();
  client.tableOperations().create(tableName);
  BatchWriter bw = client.createBatchWriter(tableName, new BatchWriterConfig());
  ColumnVisibility cv = new ColumnVisibility();
  // / has 1 dir
  // /local has 2 dirs 1 file
  // /local/user1 has 2 files
  bw.addMutation(Ingest.buildMutation(cv, "/local", true, false, true, 272, 12345, null));
  bw.addMutation(Ingest.buildMutation(cv, "/local/user1", true, false, true, 272, 12345, null));
  bw.addMutation(Ingest.buildMutation(cv, "/local/user2", true, false, true, 272, 12345, null));
  bw.addMutation(Ingest.buildMutation(cv, "/local/file", false, false, false, 1024, 12345, null));
  bw.addMutation(Ingest.buildMutation(cv, "/local/file", false, false, false, 1024, 23456, null));
  bw.addMutation(
      Ingest.buildMutation(cv, "/local/user1/file1", false, false, false, 2024, 12345, null));
  bw.addMutation(
      Ingest.buildMutation(cv, "/local/user1/file2", false, false, false, 1028, 23456, null));
  bw.close();
}
 
Example 2
Source File: AccumuloStorageTest.java    From rya with Apache License 2.0 6 votes vote down vote up
public void testColumns() throws Exception {
    BatchWriter batchWriter = connector.createBatchWriter(table, 10l, 10l, 2);
    Mutation row = new Mutation("a");
    row.put("cf1", "cq", new Value(new byte[0]));
    row.put("cf2", "cq", new Value(new byte[0]));
    row.put("cf3", "cq1", new Value(new byte[0]));
    row.put("cf3", "cq2", new Value(new byte[0]));
    batchWriter.addMutation(row);
    batchWriter.flush();
    batchWriter.close();

    String location = "accumulo://" + table + "?instance=" + instance + "&user=" + user + "&password=" + pwd + "&range=a|c&columns=cf1,cf3|cq1&mock=true";
    AccumuloStorage storage = createAccumuloStorage(location);
    int count = 0;
    while (true) {
        Tuple next = storage.getNext();
        if (next == null)
            break;
        assertEquals(6, next.size());
        count++;
    }
    assertEquals(2, count);
}
 
Example 3
Source File: ChunkInputFormatIT.java    From accumulo-examples with Apache License 2.0 6 votes vote down vote up
@Test
public void testErrorOnNextWithoutClose() throws Exception {
  client.tableOperations().create(tableName);
  BatchWriter bw = client.createBatchWriter(tableName, new BatchWriterConfig());

  for (Entry<Key,Value> e : data) {
    Key k = e.getKey();
    Mutation m = new Mutation(k.getRow());
    m.put(k.getColumnFamily(), k.getColumnQualifier(),
        new ColumnVisibility(k.getColumnVisibility()), k.getTimestamp(), e.getValue());
    bw.addMutation(m);
  }
  bw.close();

  assertEquals(1, CIFTester.main(tableName, CIFTester.TestNoClose.class.getName()));
  assertEquals(1, assertionErrors.get(tableName).size());
  // this should actually exist, in addition to the dummy entry
  assertEquals(2, assertionErrors.get(tableName + "_map_ioexception").size());
}
 
Example 4
Source File: DiscoveryIteratorTest.java    From datawave with Apache License 2.0 5 votes vote down vote up
void writeSample(BatchWriter writer, String term) throws MutationsRejectedException {
    int nShards = 10;
    String date = "20130101";
    String[] types = new String[] {"t1", "t2", "t3"};
    Value value = new Value(makeUidList(24).toByteArray());
    Mutation m = new Mutation(term);
    for (String type : types) {
        for (int i = 0; i < nShards; i++) {
            m.put("field", date + "_" + i + "\u0000" + type, new ColumnVisibility("FOO"), value);
        }
    }
    writer.addMutation(m);
}
 
Example 5
Source File: ProspectorUtils.java    From rya with Apache License 2.0 5 votes vote down vote up
public static void writeMutations(final Connector connector, final String tableName, final Collection<Mutation> mutations) throws TableNotFoundException, MutationsRejectedException {
    final BatchWriter bw = connector.createBatchWriter(tableName, 10000l, 10000l, 4);
    for(final Mutation mutation : mutations) {
        bw.addMutation(mutation);
    }
    bw.flush();
    bw.close();
}
 
Example 6
Source File: WiseGuysIngest.java    From datawave with Apache License 2.0 5 votes vote down vote up
private static void addFiTokens(BatchWriter bw, WhatKindaRange range, String field, String phrase, String uid) throws MutationsRejectedException {
    Mutation fi = new Mutation(shard);
    fi.put("fi\u0000" + field.toUpperCase(), lcNoDiacriticsType.normalize(phrase) + "\u0000" + datatype + "\u0000" + uid, columnVisibility, timeStamp,
                    emptyValue);
    
    String[] tokens = phrase.split(" ");
    for (String token : tokens) {
        fi.put("fi\u0000" + field.toUpperCase(), lcNoDiacriticsType.normalize(token) + "\u0000" + datatype + "\u0000" + uid, columnVisibility, timeStamp,
                        emptyValue);
    }
    bw.addMutation(fi);
}
 
Example 7
Source File: WholeColumnFamilyIteratorTest.java    From accumulo-recipes with Apache License 2.0 5 votes vote down vote up
private void persistTestMutations(int numRows, int entriesPerRow) throws TableNotFoundException, MutationsRejectedException {

        BatchWriter writer = connector.createBatchWriter("test", 1000, 1000, 1);

        for (int j = 0; j < numRows; j++) {
            Mutation m = new Mutation(Integer.toString(j));
            for (int i = 0; i < entriesPerRow; i++)
                m.put(new Text(Integer.toString(j)), new Text(String.valueOf(i)), new Value("".getBytes()));

            writer.addMutation(m);
        }
        writer.flush();
    }
 
Example 8
Source File: MutationBuilderIT.java    From fluo with Apache License 2.0 4 votes vote down vote up
@Test
public void testBatchWrite() throws Exception {
  // test initializing a Fluo table by batch writing to it

  // use a batch writer to test this because its easier than using AccumuloOutputFormat
  BatchWriter bw = aClient.createBatchWriter(table, new BatchWriterConfig());
  try {

    FluoMutationGenerator mb1 = new FluoMutationGenerator(Bytes.of("row1"));
    mb1.put(new Column("cf1", "cq1"), Bytes.of("v1"));
    mb1.put(new Column("cf1", "cq2"), Bytes.of("v2"));
    mb1.put(new Column("cf1", "cq3"), Bytes.of("v3"));

    bw.addMutation(mb1.build());

    FluoMutationGenerator mb2 = new FluoMutationGenerator(Bytes.of("row2"));
    mb2.put(new Column("cf1", "cq1"), Bytes.of("v4"));
    mb2.put(new Column("cf1", "cq2"), Bytes.of("v5"));

    bw.addMutation(mb2.build());

  } finally {
    bw.close();
  }

  TestTransaction tx1 = new TestTransaction(env);
  TestTransaction tx2 = new TestTransaction(env);

  Assert.assertEquals("v1", tx1.gets("row1", new Column("cf1", "cq1")));
  Assert.assertEquals("v2", tx1.gets("row1", new Column("cf1", "cq2")));
  Assert.assertEquals("v3", tx1.gets("row1", new Column("cf1", "cq3")));
  Assert.assertEquals("v4", tx1.gets("row2", new Column("cf1", "cq1")));
  Assert.assertEquals("v5", tx1.gets("row2", new Column("cf1", "cq2")));

  tx1.set("row1", new Column("cf1", "cq2"), "v6");
  tx1.delete("row1", new Column("cf1", "cq3"));
  tx1.set("row2", new Column("cf1", "cq2"), "v7");

  tx1.done();

  // tx2 should see not changes from tx1
  Assert.assertEquals("v1", tx2.gets("row1", new Column("cf1", "cq1")));
  Assert.assertEquals("v2", tx2.gets("row1", new Column("cf1", "cq2")));
  Assert.assertEquals("v3", tx2.gets("row1", new Column("cf1", "cq3")));
  Assert.assertEquals("v4", tx2.gets("row2", new Column("cf1", "cq1")));
  Assert.assertEquals("v5", tx2.gets("row2", new Column("cf1", "cq2")));

  TestTransaction tx3 = new TestTransaction(env);

  // should see changes from tx1
  Assert.assertEquals("v1", tx3.gets("row1", new Column("cf1", "cq1")));
  Assert.assertEquals("v6", tx3.gets("row1", new Column("cf1", "cq2")));
  Assert.assertNull(tx3.gets("row1", new Column("cf1", "cq3")));
  Assert.assertEquals("v4", tx3.gets("row2", new Column("cf1", "cq1")));
  Assert.assertEquals("v7", tx3.gets("row2", new Column("cf1", "cq2")));
}
 
Example 9
Source File: WebSocketClientIT.java    From qonduit with Apache License 2.0 4 votes vote down vote up
private void doScan(WebSocketClient client) throws Exception {
    long now = System.currentTimeMillis();
    String tableName = "qonduit.scanTest";
    Connector con = mac.getConnector(MAC_ROOT_USER, MAC_ROOT_PASSWORD);
    con.namespaceOperations().create("qonduit");
    con.tableOperations().create(tableName);
    BatchWriterConfig bwc = new BatchWriterConfig();
    bwc.setMaxLatency(2, TimeUnit.SECONDS);
    BatchWriter writer = con.createBatchWriter(tableName, bwc);

    ColumnVisibility cv = new ColumnVisibility();
    for (int i = 0; i < 10; i++) {
        Mutation m = new Mutation("m" + i);
        m.put("cf" + i, "cq" + i, cv, now + i, Integer.toString(i));
        writer.addMutation(m);
    }
    writer.flush();
    writer.close();
    sleepUninterruptibly(2, TimeUnit.SECONDS);
    List<byte[]> responses = new ArrayList<>();
    String id = UUID.randomUUID().toString();
    ScanRequest request = new ScanRequest();
    request.setRequestId(id);
    request.setTableName(tableName);
    request.setResultBatchSize(5);
    doIt(client, request, responses, 3);
    Assert.assertEquals(11, responses.size());
    for (byte[] b : responses) {
        KVPair kv = JsonSerializer.getObjectMapper().readValue(b, KVPair.class);
        Value val = kv.getValue();
        if (null != val) {
            int num = Integer.parseInt(new String(val.getValue()));
            Key key = kv.getKey().toKey();
            Assert.assertEquals("m" + num, key.getRow().toString());
            Assert.assertEquals("cf" + num, key.getColumnFamily().toString());
            Assert.assertEquals("cq" + num, key.getColumnQualifier().toString());
            Assert.assertEquals(now + num, key.getTimestamp());
            Assert.assertEquals(id, kv.getRequestId());
        } else {
            Assert.assertTrue(kv.isEndOfResults());
        }
    }
}
 
Example 10
Source File: FileCount.java    From accumulo-examples with Apache License 2.0 4 votes vote down vote up
private void calculateCounts(Scanner scanner, int depth, BatchWriter batchWriter)
    throws Exception {

  scanner.setRange(
      new Range(String.format("%03d", depth), true, String.format("%03d", depth + 1), false));

  CountValue countVal = new CountValue();

  Iterator<Entry<Key,Value>> iterator = scanner.iterator();

  String currentDir = null;

  Entry<Key,Value> entry = null;
  if (iterator.hasNext()) {
    entry = iterator.next();
    entriesScanned++;
  }

  while (entry != null) {
    Key key = entry.getKey();

    String dir = extractDir(key);

    if (currentDir == null) {
      currentDir = dir;
    } else if (!currentDir.equals(dir)) {
      batchWriter.addMutation(createMutation(depth - 1, currentDir, countVal));
      inserts++;
      currentDir = dir;
      countVal.clear();
    }

    // process a whole row
    if (key.compareColumnFamily(QueryUtil.DIR_COLF) == 0) {
      CountValue tmpCount = new CountValue();
      entry = findCount(entry, iterator, tmpCount);

      if (tmpCount.dirCount == 0 && tmpCount.fileCount == 0) {
        // in this case the higher depth will not insert anything if the
        // dir has no children, so insert something here
        Mutation m = new Mutation(key.getRow());
        m.put(QueryUtil.DIR_COLF, QueryUtil.COUNTS_COLQ, visibility, tmpCount.toValue());
        batchWriter.addMutation(m);
        inserts++;
      }

      countVal.incrementRecursive(tmpCount);
      countVal.incrementDirs();
    } else {
      entry = consumeRow(entry, iterator);
      countVal.incrementFiles();
    }
  }

  if (currentDir != null) {
    batchWriter.addMutation(createMutation(depth - 1, currentDir, countVal));
    inserts++;
  }
}
 
Example 11
Source File: DocumentIndexIntersectingIteratorTest.java    From rya with Apache License 2.0 2 votes vote down vote up
@Test
public void testBasicColumnSubjObjPrefix() throws Exception {

    BatchWriter bw = null;

    bw = accCon.createBatchWriter(tablename, 500L * 1024L * 1024L, Long.MAX_VALUE, 30);

    for (int i = 0; i < 100; i++) {

        Mutation m = new Mutation(new Text("" + i));
        m.put(new Text("cf"), new Text(null + "\u0000" +"obj" + "\u0000" + "cq"), new Value(new byte[0]));
        m.put(new Text("cF"), new Text(null + "\u0000" +"obj" + "\u0000" + "cQ"), new Value(new byte[0]));

        if (i == 30 ) {
            m.put(new Text("CF"), new Text(null + "\u0000" +"obj" + "\u0000" + "CQ"), new Value(new byte[0]));
        }

        if  (i == 60) {
            m.put(new Text("CF"), new Text(null + "\u0000" +"subj" + "\u0000" + "CQ"), new Value(new byte[0]));
        }




        bw.addMutation(m);

    }

    DocumentIndexIntersectingIterator dii = new DocumentIndexIntersectingIterator();
    TextColumn tc1 = new TextColumn(new Text("cf"), new Text("obj" + "\u0000" + "cq" ));
    TextColumn tc2 = new TextColumn(new Text("cF"), new Text("obj" + "\u0000" + "cQ"));
    TextColumn tc3 = new TextColumn(new Text("CF"), new Text("subj"));

    TextColumn[] tc = new TextColumn[3];
    tc[0] = tc1;
    tc[1] = tc2;
    tc[2] = tc3;

    tc3.setIsPrefix(true);

    IteratorSetting is = new IteratorSetting(30, "fii", DocumentIndexIntersectingIterator.class);

    dii.setColumnFamilies(is, tc);

    Scanner scan = accCon.createScanner(tablename, new Authorizations("auths"));
    scan.addScanIterator(is);

    int results = 0;
    System.out.println("************************Test 3****************************");
    for (Map.Entry<Key, Value> e : scan) {
        System.out.println(e);
        results++;
    }


    Assert.assertEquals(1, results);




}
 
Example 12
Source File: DocumentIndexIntersectingIteratorTest.java    From rya with Apache License 2.0 2 votes vote down vote up
@Test
public void testContext3() throws Exception {

    BatchWriter bw = null;

    bw = accCon.createBatchWriter(tablename, 500L * 1024L * 1024L, Long.MAX_VALUE, 30);



    for (int i = 0; i < 100; i++) {

        Mutation m = new Mutation(new Text("" + i));

        m.put(new Text("cf" + 1), new Text("context1" + "\u0000" +"obj" + "\u0000" + "cq" + 1 + "\u0000" + "context1"), new Value(new byte[0]));
        m.put(new Text("cf" + 2), new Text("context1" + "\u0000" +"obj" + "\u0000" + "cq" + 2 + "\u0000" + "context1"), new Value(new byte[0]));
        m.put(new Text("cf" + 1), new Text("context2" + "\u0000" +"obj" + "\u0000" + "cq" + 1 + "\u0000" + "context2"), new Value(new byte[0]));
        m.put(new Text("cf" + 2), new Text("context2" + "\u0000" +"obj" + "\u0000" + "cq" + 2 + "\u0000" + "context2"), new Value(new byte[0]));


        if(i == 30 || i == 60 || i == 90 || i == 99) {
            m.put(new Text("cf" + 3), new Text("context1" + "\u0000" +"obj" + "\u0000" + "cq" + 3 ), new Value(new byte[0]));
            m.put(new Text("cf" + 3), new Text("context2" + "\u0000" +"obj" + "\u0000" + "cq" + 4 ), new Value(new byte[0]));
            m.put(new Text("cf" + 3), new Text("context3" + "\u0000" +"obj" + "\u0000" + "cq" + 5 ), new Value(new byte[0]));

        }

        bw.addMutation(m);

    }



    TextColumn tc1 = new TextColumn(new Text("cf" + 1 ), new Text("obj" + "\u0000" + "cq" + 1));
    TextColumn tc2 = new TextColumn(new Text("cf" + 2), new Text("obj" + "\u0000" + "cq" + 2));
    TextColumn tc3 = new TextColumn(new Text("cf" + 3), new Text("obj"));

    tc3.setIsPrefix(true);

    TextColumn[] tc = new TextColumn[3];
    tc[0] = tc1;
    tc[1] = tc2;
    tc[2] = tc3;


    IteratorSetting is = new IteratorSetting(30, "fii", DocumentIndexIntersectingIterator.class);

    DocumentIndexIntersectingIterator.setColumnFamilies(is, tc);
    DocumentIndexIntersectingIterator.setContext(is, "context2");

    Scanner scan = accCon.createScanner(tablename, new Authorizations("auths"));

    scan.addScanIterator(is);

    int results = 0;
    System.out.println("************************Test 16****************************");
    for (Map.Entry<Key, Value> e : scan) {
        System.out.println(e);
        results++;
    }


    Assert.assertEquals(4, results);




}
 
Example 13
Source File: DocumentIndexIntersectingIteratorTest.java    From rya with Apache License 2.0 2 votes vote down vote up
@Test
public void testLubmLikeTest() throws Exception {

    BatchWriter bw = null;

    bw = accCon.createBatchWriter(tablename, 500L * 1024L * 1024L, Long.MAX_VALUE, 30);



    for (int i = 0; i < 100; i++) {

        Mutation m1 = new Mutation(new Text("ProfessorA" + i));
        Mutation m2= new Mutation(new Text("ProfessorB" + i));

        m1.put(new Text("http://swat.cse.lehigh.edu/onto/univ-bench.owl#doctoralDegreeFrom"),
                new Text(null + "\u0000" +"object" + "\u0000" + "http://www.University" + i + ".edu"), new Value(new byte[0]));
        m2.put(new Text("http://swat.cse.lehigh.edu/onto/univ-bench.owl#doctoralDegreeFrom"),
                new Text(null + "\u0000" +"object" + "\u0000" + "http://www.University" + i + ".edu"), new Value(new byte[0]));
        m1.put(new Text("http://swat.cse.lehigh.edu/onto/univ-bench.owl#teacherOf"),
                new Text(null + "\u0000" +"object" + "\u0000" + "http://Course" + i), new Value(new byte[0]));
        m2.put(new Text("http://swat.cse.lehigh.edu/onto/univ-bench.owl#teacherOf"),
                new Text(null + "\u0000" +"object" + "\u0000" + "http://Course" + i), new Value(new byte[0]));


        bw.addMutation(m1);
        bw.addMutation(m2);

    }



    TextColumn tc1 = new TextColumn(new Text("http://swat.cse.lehigh.edu/onto/univ-bench.owl#doctoralDegreeFrom" ),
            new Text("object" + "\u0000" + "http://www.University" + 30 + ".edu"));
    TextColumn tc2 = new TextColumn(new Text("http://swat.cse.lehigh.edu/onto/univ-bench.owl#teacherOf"),
            new Text("object" + "\u0000" + "http://Course" + 30));




    TextColumn[] tc = new TextColumn[2];
    tc[0] = tc1;
    tc[1] = tc2;


    IteratorSetting is = new IteratorSetting(30, "fii", DocumentIndexIntersectingIterator.class);

    DocumentIndexIntersectingIterator.setColumnFamilies(is, tc);

    Scanner scan = accCon.createScanner(tablename, new Authorizations("auths"));
    scan.addScanIterator(is);

    int results = 0;
    System.out.println("************************Test 15****************************");
    for (Map.Entry<Key, Value> e : scan) {
        System.out.println(e);
        results++;
    }


    Assert.assertEquals(2, results);




}
 
Example 14
Source File: DocumentIndexIntersectingIteratorTest.java    From rya with Apache License 2.0 2 votes vote down vote up
@Test
public void testContext5() throws Exception {

    BatchWriter bw = null;

    bw = accCon.createBatchWriter(tablename, 500L * 1024L * 1024L, Long.MAX_VALUE, 30);



    for (int i = 0; i < 100; i++) {

        Mutation m = new Mutation(new Text("" + i));

        m.put(new Text("cf" + 1), new Text("context1" + "\u0000"  + "obj" + "\u0000" + "cq" + 1), new Value(new byte[0]));
        m.put(new Text("cf" + 2), new Text("context1" + "\u0000"  + "obj" + "\u0000" + "cq" + 2), new Value(new byte[0]));
        m.put(new Text("cf" + 1), new Text("context2" + "\u0000"  + "obj" + "\u0000" + "cq" + 1), new Value(new byte[0]));
        m.put(new Text("cf" + 2), new Text("context2" + "\u0000"  + "obj" + "\u0000" + "cq" + 2), new Value(new byte[0]));
        m.put(new Text("cf" + 1), new Text(null + "\u0000" + "obj" + "\u0000" + "cq" + 1 ), new Value(new byte[0]));
        m.put(new Text("cf" + 2), new Text(null + "\u0000" + "obj" + "\u0000" + "cq" + 2 ), new Value(new byte[0]));


        if(i == 30 || i == 60 || i == 90 || i == 99) {
            m.put(new Text("cf" + 3), new Text("context1" + "\u0000"  + "obj" + "\u0000" + "cq" + 3), new Value(new byte[0]));
            m.put(new Text("cf" + 3), new Text("context2" + "\u0000"  + "obj" + "\u0000" + "cq" + 3 ), new Value(new byte[0]));
            m.put(new Text("cf" + 3), new Text(null + "\u0000"  + "obj" + "\u0000" + "cq" + 3 ), new Value(new byte[0]));


        }

        bw.addMutation(m);

    }



    TextColumn tc1 = new TextColumn(new Text("cf" + 1 ), new Text("obj" + "\u0000" + "cq" + 1));
    TextColumn tc2 = new TextColumn(new Text("cf" + 2), new Text("obj" + "\u0000" + "cq" + 2));
    TextColumn tc3 = new TextColumn(new Text("cf" + 3), new Text("obj"));

    tc3.setIsPrefix(true);

    TextColumn[] tc = new TextColumn[3];
    tc[0] = tc1;
    tc[1] = tc2;
    tc[2] = tc3;


    IteratorSetting is = new IteratorSetting(30, "fii", DocumentIndexIntersectingIterator.class);

    DocumentIndexIntersectingIterator.setColumnFamilies(is, tc);


    Scanner scan = accCon.createScanner(tablename, new Authorizations("auths"));

    scan.addScanIterator(is);

    int results = 0;
    System.out.println("************************Test 18****************************");
    for (Map.Entry<Key, Value> e : scan) {
        System.out.println(e);
        results++;
    }


    Assert.assertEquals(12, results);




}
 
Example 15
Source File: DocumentIndexIntersectingIteratorTest.java    From rya with Apache License 2.0 2 votes vote down vote up
@Test
public void testGeneralStarQuerySubjPrefix() throws Exception {

    BatchWriter bw = null;

    bw = accCon.createBatchWriter(tablename, 500L * 1024L * 1024L, Long.MAX_VALUE, 30);



    for (int i = 0; i < 100; i++) {

        Mutation m = new Mutation(new Text("" + i));

        m.put(new Text("cf" + 1), new Text(null + "\u0000" +"obj" + "\u0000" + "cq" + 1), new Value(new byte[0]));
        m.put(new Text("cf" + 2), new Text(null + "\u0000" +"obj" + "\u0000" + "cq" + 2 ), new Value(new byte[0]));
        m.put(new Text("cf" + 1), new Text(null + "\u0000" +"subj" + "\u0000" + "cq" + 1), new Value(new byte[0]));
        m.put(new Text("cf" + 2), new Text(null + "\u0000" +"subj" + "\u0000" + "cq" + 2), new Value(new byte[0]));



        if(i == 30 || i == 60 || i == 90 || i == 99) {
            m.put(new Text("cf" + 3), new Text(null + "\u0000" +"obj" + "\u0000" + "cq" + 3), new Value(new byte[0]));
            m.put(new Text("cf" + 3), new Text(null + "\u0000" +"subj" + "\u0000" + "cq" + 3), new Value(new byte[0]));
        }

        bw.addMutation(m);

    }


    DocumentIndexIntersectingIterator dii = new DocumentIndexIntersectingIterator();
    TextColumn tc1 = new TextColumn(new Text("cf" + 1 ), new Text("obj" + "\u0000" + "cq" + 1));
    TextColumn tc2 = new TextColumn(new Text("cf" + 2), new Text("obj" + "\u0000" + "cq" + 2));
    TextColumn tc3 = new TextColumn(new Text("cf" + 3), new Text("subj"));

    tc3.setIsPrefix(true);

    TextColumn[] tc = new TextColumn[3];
    tc[0] = tc1;
    tc[1] = tc2;
    tc[2] = tc3;


    IteratorSetting is = new IteratorSetting(30, "fii", DocumentIndexIntersectingIterator.class);

    dii.setColumnFamilies(is, tc);

    Scanner scan = accCon.createScanner(tablename, new Authorizations("auths"));
    scan.addScanIterator(is);

    int results = 0;
    System.out.println("************************Test 11****************************");
    for (Map.Entry<Key, Value> e : scan) {
        System.out.println(e);
        results++;
    }


    Assert.assertEquals(4, results);




}
 
Example 16
Source File: DocumentIndexIntersectingIteratorTest.java    From rya with Apache License 2.0 2 votes vote down vote up
@Test
public void testOneHundredColumnSubjObjPrefix() throws Exception {

    BatchWriter bw = null;

    bw = accCon.createBatchWriter(tablename, 500L * 1024L * 1024L, Long.MAX_VALUE, 30);

    for (int i = 0; i < 100; i++) {

        Mutation m = new Mutation(new Text("" + i));

        for(int j= 0; j < 100; j++) {
            m.put(new Text("cf" + j), new Text(null + "\u0000" +"obj" + "\u0000" + "cq" + j), new Value(new byte[0]));
        }

        if (i == 30 || i == 60 || i == 90 || i == 99) {
            m.put(new Text("cf" + 100), new Text(null + "\u0000" +"obj" + "\u0000" + "cq" + (100 + i)), new Value(new byte[0]));
            m.put(new Text("cf" + 100), new Text(null + "\u0000" +"subj" + "\u0000" + "cq" + (100 + i + 1)), new Value(new byte[0]));
        }






        bw.addMutation(m);

    }

    DocumentIndexIntersectingIterator dii = new DocumentIndexIntersectingIterator();
    TextColumn tc1 = new TextColumn(new Text("cf" + 20), new Text("obj" + "\u0000" + "cq" + 20));
    TextColumn tc2 = new TextColumn(new Text("cf" + 50), new Text("obj" + "\u0000" + "cq" + 50));
    TextColumn tc3 = new TextColumn(new Text("cf" + 100), new Text("subj"));

    tc3.setIsPrefix(true);

    TextColumn[] tc = new TextColumn[3];
    tc[0] = tc1;
    tc[1] = tc2;
    tc[2] = tc3;

    IteratorSetting is = new IteratorSetting(30, "fii", DocumentIndexIntersectingIterator.class);

    dii.setColumnFamilies(is, tc);

    Scanner scan = accCon.createScanner(tablename, new Authorizations("auths"));
    scan.addScanIterator(is);

    int results = 0;
    System.out.println("************************Test 7****************************");
    for (Map.Entry<Key, Value> e : scan) {
        System.out.println(e);
        results++;
    }


    Assert.assertEquals(4, results);




}
 
Example 17
Source File: DocumentIndexIntersectingIteratorTest.java    From rya with Apache License 2.0 2 votes vote down vote up
public void testOneHundredColumnSameCf() throws Exception {

        BatchWriter bw = null;

        bw = accCon.createBatchWriter(tablename, 500L * 1024L * 1024L, Long.MAX_VALUE, 30);

        for (int i = 0; i < 100; i++) {

            Mutation m = new Mutation(new Text("" + i));

            for(int j= 0; j < 100; j++) {
                m.put(new Text("cf"), new Text(null + "\u0000" +"obj" + "\u0000" + "cq" + j), new Value(new byte[0]));
            }



            bw.addMutation(m);

        }

        DocumentIndexIntersectingIterator dii = new DocumentIndexIntersectingIterator();
        TextColumn tc1 = new TextColumn(new Text("cf" ), new Text("obj" + "\u0000" + "cq" + 20));
        TextColumn tc2 = new TextColumn(new Text("cf"), new Text("obj" + "\u0000" + "cq" + 50));
        TextColumn tc3 = new TextColumn(new Text("cf" ), new Text("obj" + "\u0000" + "cq" + 80));
        TextColumn tc4 = new TextColumn(new Text("cf"), new Text("obj"));

        tc4.setIsPrefix(true);

        TextColumn[] tc = new TextColumn[4];
        tc[0] = tc1;
        tc[1] = tc2;
        tc[2] = tc3;
        tc[3] = tc4;

        IteratorSetting is = new IteratorSetting(30, "fii", DocumentIndexIntersectingIterator.class);

        dii.setColumnFamilies(is, tc);

        Scanner scan = accCon.createScanner(tablename, new Authorizations("auths"));
        scan.addScanIterator(is);

        int results = 0;
        System.out.println("************************Test 9****************************");
        for (Map.Entry<Key, Value> e : scan) {
            //System.out.println(e);
            results++;
        }


        Assert.assertEquals(10000, results);




    }
 
Example 18
Source File: DocumentIndexIntersectingIteratorTest.java    From rya with Apache License 2.0 2 votes vote down vote up
@Test
public void testBasicColumnObj() throws Exception {

    BatchWriter bw = null;

    bw = accCon.createBatchWriter(tablename, 500L * 1024L * 1024L, Long.MAX_VALUE, 30);

    for (int i = 0; i < 100; i++) {

        Mutation m = new Mutation(new Text("" + i));
        m.put(new Text("cf"), new Text(null + "\u0000" + "obj" + "\u0000" + "cq"), new Value(new byte[0]));
        m.put(new Text("cF"), new Text(null + "\u0000" +"obj" + "\u0000" + "cQ"), new Value(new byte[0]));

        if (i == 30 || i == 60) {
            m.put(new Text("CF"), new Text(null + "\u0000" +"obj" + "\u0000" + "CQ"), new Value(new byte[0]));
        }

        bw.addMutation(m);

    }

    DocumentIndexIntersectingIterator dii = new DocumentIndexIntersectingIterator();
    TextColumn tc1 = new TextColumn(new Text("cf"), new Text("obj" + "\u0000" + "cq" ));
    TextColumn tc2 = new TextColumn(new Text("cF"), new Text("obj" + "\u0000" + "cQ" ));
    TextColumn tc3 = new TextColumn(new Text("CF"), new Text("obj" + "\u0000" + "CQ" ));

    TextColumn[] tc = new TextColumn[3];
    tc[0] = tc1;
    tc[1] = tc2;
    tc[2] = tc3;

    IteratorSetting is = new IteratorSetting(30, "fii", DocumentIndexIntersectingIterator.class);

    dii.setColumnFamilies(is, tc);

    Scanner scan = accCon.createScanner(tablename, new Authorizations("auths"));
    scan.addScanIterator(is);

    int results = 0;
    System.out.println("************************Test 1****************************");
    for (Map.Entry<Key, Value> e : scan) {
        System.out.println(e);
        results++;
    }


    Assert.assertEquals(2, results);




}
 
Example 19
Source File: DocumentIndexIntersectingIteratorTest.java    From rya with Apache License 2.0 2 votes vote down vote up
@Test
public void testGeneralStarQuery() throws Exception {

    BatchWriter bw = null;

    bw = accCon.createBatchWriter(tablename, 500L * 1024L * 1024L, Long.MAX_VALUE, 30);



    for (int i = 0; i < 100; i++) {

        Mutation m = new Mutation(new Text("" + i));

        m.put(new Text("cf" + 1), new Text(null + "\u0000" +"obj" + "\u0000" + "cq" + 1), new Value(new byte[0]));
        m.put(new Text("cf" + 2), new Text(null + "\u0000" +"obj" + "\u0000" + "cq" + 2 ), new Value(new byte[0]));
        m.put(new Text("cf" + 1), new Text(null + "\u0000" +"subj" + "\u0000" + "cq" + 1 ), new Value(new byte[0]));
        m.put(new Text("cf" + 2), new Text(null + "\u0000" +"subj" + "\u0000" + "cq" + 2 ), new Value(new byte[0]));



        if(i == 30 || i == 60 ) {
            m.put(new Text("cf" + 3), new Text(null + "\u0000" +"obj" + "\u0000" + "cq" + 3), new Value(new byte[0]));
            m.put(new Text("cf" + 3), new Text(null + "\u0000" +"subj" + "\u0000" + "cq" + 3), new Value(new byte[0]));
        }

        bw.addMutation(m);

    }


    DocumentIndexIntersectingIterator dii = new DocumentIndexIntersectingIterator();
    TextColumn tc1 = new TextColumn(new Text("cf" + 1 ), new Text("obj" + "\u0000" + "cq" + 1));
    TextColumn tc2 = new TextColumn(new Text("cf" + 2), new Text("obj" + "\u0000" + "cq" + 2));
    TextColumn tc3 = new TextColumn(new Text("cf" + 3), new Text("subj" + "\u0000" + "cq" + 3));


    TextColumn[] tc = new TextColumn[3];
    tc[0] = tc1;
    tc[1] = tc2;
    tc[2] = tc3;


    IteratorSetting is = new IteratorSetting(30, "fii", DocumentIndexIntersectingIterator.class);

    dii.setColumnFamilies(is, tc);

    Scanner scan = accCon.createScanner(tablename, new Authorizations("auths"));
    scan.addScanIterator(is);

    int results = 0;
    System.out.println("************************Test 10****************************");
    for (Map.Entry<Key, Value> e : scan) {
        System.out.println(e);
        results++;
    }


    Assert.assertEquals(2, results);




}
 
Example 20
Source File: DocumentIndexIntersectingIteratorTest.java    From rya with Apache License 2.0 2 votes vote down vote up
@Test
public void testContext6() throws Exception {

    BatchWriter bw = null;

    bw = accCon.createBatchWriter(tablename, 500L * 1024L * 1024L, Long.MAX_VALUE, 30);



    for (int i = 0; i < 100; i++) {

        Mutation m = new Mutation(new Text("row" + i));


        m.put(new Text("cf" + 1), new Text("context1" + "\u0000"  + "obj" + "\u0000" + "cq" + i), new Value(new byte[0]));
        m.put(new Text("cf" + 2), new Text("context1" + "\u0000"  + "subj" + "\u0000" + "cq" + i), new Value(new byte[0]));
        m.put(new Text("cf" + 1), new Text("context2" + "\u0000"  + "obj" + "\u0000" + "cq" + i), new Value(new byte[0]));
        m.put(new Text("cf" + 2), new Text("context2" + "\u0000"  + "subj" + "\u0000" + "cq" + i), new Value(new byte[0]));


        bw.addMutation(m);


    }



    TextColumn tc1 = new TextColumn(new Text("cf" + 1 ), new Text("obj" ));
    TextColumn tc2 = new TextColumn(new Text("cf" + 2), new Text("subj" ));


    tc1.setIsPrefix(true);
    tc2.setIsPrefix(true);

    TextColumn[] tc = new TextColumn[2];
    tc[0] = tc1;
    tc[1] = tc2;



    IteratorSetting is = new IteratorSetting(30, "fii", DocumentIndexIntersectingIterator.class);

    DocumentIndexIntersectingIterator.setColumnFamilies(is, tc);
    DocumentIndexIntersectingIterator.setContext(is, "context2");

    Scanner scan = accCon.createScanner(tablename, new Authorizations("auths"));

    scan.addScanIterator(is);

    int results = 0;
    System.out.println("************************Test 19****************************");
    for (Map.Entry<Key, Value> e : scan) {
        System.out.println(e);
        results++;
    }


    Assert.assertEquals(100, results);




}