Search in sources :

Example 86 with BatchWriter

use of org.apache.accumulo.core.client.BatchWriter in project accumulo by apache.

the class ScanRangeIT method insertData.

private void insertData(Connector c, String table) throws Exception {
    BatchWriter bw = c.createBatchWriter(table, new BatchWriterConfig());
    for (int i = 0; i < ROW_LIMIT; i++) {
        Mutation m = new Mutation(createRow(i));
        for (int j = 0; j < CF_LIMIT; j++) {
            for (int k = 0; k < CQ_LIMIT; k++) {
                for (int t = 0; t < TS_LIMIT; t++) {
                    m.put(createCF(j), createCQ(k), t, new Value(String.format("%06d_%03d_%03d_%03d", i, j, k, t).getBytes(UTF_8)));
                }
            }
        }
        bw.addMutation(m);
    }
    bw.close();
}
Also used : 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)

Example 87 with BatchWriter

use of org.apache.accumulo.core.client.BatchWriter in project accumulo by apache.

the class ScannerContextIT method testClearContext.

@Test
public void testClearContext() throws Exception {
    Path dstPath = copyTestIteratorsJarToTmp();
    try {
        Connector c = getConnector();
        // Set the classloader context property on the table to point to the test iterators jar file.
        c.instanceOperations().setProperty(CONTEXT_PROPERTY, CONTEXT_CLASSPATH);
        // Insert rows with the word "Test" in the value.
        String tableName = getUniqueNames(1)[0];
        c.tableOperations().create(tableName);
        BatchWriter bw = c.createBatchWriter(tableName, new BatchWriterConfig());
        for (int i = 0; i < ITERATIONS; i++) {
            Mutation m = new Mutation("row" + i);
            m.put("cf", "col1", "Test");
            bw.addMutation(m);
        }
        bw.close();
        try (Scanner one = c.createScanner(tableName, Authorizations.EMPTY)) {
            IteratorSetting cfg = new IteratorSetting(21, "reverse", "org.apache.accumulo.test.functional.ValueReversingIterator");
            one.addScanIterator(cfg);
            one.setClassLoaderContext(CONTEXT);
            Iterator<Entry<Key, Value>> iterator = one.iterator();
            for (int i = 0; i < ITERATIONS; i++) {
                assertTrue(iterator.hasNext());
                Entry<Key, Value> next = iterator.next();
                assertEquals("tseT", next.getValue().toString());
            }
            one.removeScanIterator("reverse");
            one.clearClassLoaderContext();
            iterator = one.iterator();
            for (int i = 0; i < ITERATIONS; i++) {
                assertTrue(iterator.hasNext());
                Entry<Key, Value> next = iterator.next();
                assertEquals("Test", next.getValue().toString());
            }
        }
    } finally {
        // Delete file in tmp
        fs.delete(dstPath, true);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Connector(org.apache.accumulo.core.client.Connector) BatchScanner(org.apache.accumulo.core.client.BatchScanner) Scanner(org.apache.accumulo.core.client.Scanner) Entry(java.util.Map.Entry) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) 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) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 88 with BatchWriter

use of org.apache.accumulo.core.client.BatchWriter in project accumulo by apache.

the class ScannerContextIT method testOneScannerDoesntInterfereWithAnother.

@Test
public void testOneScannerDoesntInterfereWithAnother() throws Exception {
    Path dstPath = copyTestIteratorsJarToTmp();
    try {
        Connector c = getConnector();
        // Set the classloader context property on the table to point to the test iterators jar file.
        c.instanceOperations().setProperty(CONTEXT_PROPERTY, CONTEXT_CLASSPATH);
        // Insert rows with the word "Test" in the value.
        String tableName = getUniqueNames(1)[0];
        c.tableOperations().create(tableName);
        BatchWriter bw = c.createBatchWriter(tableName, new BatchWriterConfig());
        for (int i = 0; i < ITERATIONS; i++) {
            Mutation m = new Mutation("row" + i);
            m.put("cf", "col1", "Test");
            bw.addMutation(m);
        }
        bw.close();
        try (Scanner one = c.createScanner(tableName, Authorizations.EMPTY);
            Scanner two = c.createScanner(tableName, Authorizations.EMPTY)) {
            IteratorSetting cfg = new IteratorSetting(21, "reverse", "org.apache.accumulo.test.functional.ValueReversingIterator");
            one.addScanIterator(cfg);
            one.setClassLoaderContext(CONTEXT);
            Iterator<Entry<Key, Value>> iterator = one.iterator();
            for (int i = 0; i < ITERATIONS; i++) {
                assertTrue(iterator.hasNext());
                Entry<Key, Value> next = iterator.next();
                assertEquals("tseT", next.getValue().toString());
            }
            Iterator<Entry<Key, Value>> iterator2 = two.iterator();
            for (int i = 0; i < ITERATIONS; i++) {
                assertTrue(iterator2.hasNext());
                Entry<Key, Value> next = iterator2.next();
                assertEquals("Test", next.getValue().toString());
            }
        }
    } finally {
        // Delete file in tmp
        fs.delete(dstPath, true);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Connector(org.apache.accumulo.core.client.Connector) BatchScanner(org.apache.accumulo.core.client.BatchScanner) Scanner(org.apache.accumulo.core.client.Scanner) Entry(java.util.Map.Entry) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) 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) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 89 with BatchWriter

use of org.apache.accumulo.core.client.BatchWriter in project accumulo by apache.

the class AccumuloFileOutputFormatIT method testRealWrite.

@Test
public void testRealWrite() throws Exception {
    Connector c = getConnector();
    c.tableOperations().create(TEST_TABLE);
    BatchWriter bw = c.createBatchWriter(TEST_TABLE, new BatchWriterConfig());
    Mutation m = new Mutation("Key");
    m.put("", "", "");
    bw.addMutation(m);
    bw.close();
    handleWriteTests(true);
}
Also used : Connector(org.apache.accumulo.core.client.Connector) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Test(org.junit.Test)

Example 90 with BatchWriter

use of org.apache.accumulo.core.client.BatchWriter in project accumulo by apache.

the class TokenFileIT method testMR.

@Test
public void testMR() throws Exception {
    String[] tableNames = getUniqueNames(2);
    String table1 = tableNames[0];
    String table2 = tableNames[1];
    Connector c = getConnector();
    c.tableOperations().create(table1);
    c.tableOperations().create(table2);
    BatchWriter bw = c.createBatchWriter(table1, new BatchWriterConfig());
    for (int i = 0; i < 100; i++) {
        Mutation m = new Mutation(new Text(String.format("%09x", i + 1)));
        m.put(new Text(), new Text(), new Value(String.format("%09x", i).getBytes()));
        bw.addMutation(m);
    }
    bw.close();
    File tf = folder.newFile("root_test.pw");
    PrintStream out = new PrintStream(tf);
    String outString = new Credentials(getAdminPrincipal(), getAdminToken()).serialize();
    out.println(outString);
    out.close();
    MRTokenFileTester.main(new String[] { tf.getAbsolutePath(), table1, table2 });
    assertNull(e1);
    try (Scanner scanner = c.createScanner(table2, new Authorizations())) {
        Iterator<Entry<Key, Value>> iter = scanner.iterator();
        assertTrue(iter.hasNext());
        Entry<Key, Value> entry = iter.next();
        assertEquals(Integer.parseInt(new String(entry.getValue().get())), 100);
        assertFalse(iter.hasNext());
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) PrintStream(java.io.PrintStream) Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) Text(org.apache.hadoop.io.Text) Entry(java.util.Map.Entry) 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) File(java.io.File) Credentials(org.apache.accumulo.core.client.impl.Credentials) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Aggregations

BatchWriter (org.apache.accumulo.core.client.BatchWriter)402 Mutation (org.apache.accumulo.core.data.Mutation)360 Test (org.junit.Test)264 Value (org.apache.accumulo.core.data.Value)250 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)246 Text (org.apache.hadoop.io.Text)194 Key (org.apache.accumulo.core.data.Key)179 Scanner (org.apache.accumulo.core.client.Scanner)174 Connector (org.apache.accumulo.core.client.Connector)169 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)81 Authorizations (org.apache.accumulo.core.security.Authorizations)68 Range (org.apache.accumulo.core.data.Range)61 Entry (java.util.Map.Entry)51 Map (java.util.Map)50 BatchScanner (org.apache.accumulo.core.client.BatchScanner)46 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)44 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)40 HashMap (java.util.HashMap)38 ArrayList (java.util.ArrayList)36 Status (org.apache.accumulo.server.replication.proto.Replication.Status)32