Search in sources :

Example 41 with NewTableConfiguration

use of org.apache.accumulo.core.client.admin.NewTableConfiguration in project accumulo by apache.

the class NewTableConfigurationIT method testPreconfigureIteratorWithDefaultIterator1.

/**
 * Test pre-configuring iterator along with default iterator. Configure IteratorSetting values within method call.
 */
@Test
public void testPreconfigureIteratorWithDefaultIterator1() throws AccumuloException, TableNotFoundException, AccumuloSecurityException, TableExistsException {
    Connector conn = getConnector();
    String tableName = getUniqueNames(2)[0];
    NewTableConfiguration ntc = new NewTableConfiguration();
    ntc.attachIterator(new IteratorSetting(10, "anIterator", "it.class", Collections.emptyMap()), EnumSet.of(IteratorScope.scan));
    conn.tableOperations().create(tableName, ntc);
    Map<String, EnumSet<IteratorScope>> iteratorList = conn.tableOperations().listIterators(tableName);
    // should count the created iterator plus the default iterator
    assertEquals(2, iteratorList.size());
    verifyIterators(conn, tableName, new String[] { "table.iterator.scan.anIterator=10,it.class" }, true);
    conn.tableOperations().removeIterator(tableName, "anIterator", EnumSet.of(IteratorScope.scan));
    verifyIterators(conn, tableName, new String[] {}, true);
    iteratorList = conn.tableOperations().listIterators(tableName);
    assertEquals(1, iteratorList.size());
}
Also used : Connector(org.apache.accumulo.core.client.Connector) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) EnumSet(java.util.EnumSet) Test(org.junit.Test)

Example 42 with NewTableConfiguration

use of org.apache.accumulo.core.client.admin.NewTableConfiguration in project accumulo by apache.

the class NewTableConfigurationIT method testOverlappingGroupsFail.

/**
 * Verify that you cannot have overlapping locality groups.
 *
 * Attempt to set a locality group with overlapping groups. This test should throw an IllegalArgumentException indicating that groups overlap.
 */
@Test(expected = IllegalArgumentException.class)
public void testOverlappingGroupsFail() throws AccumuloSecurityException, AccumuloException, TableExistsException {
    NewTableConfiguration ntc = new NewTableConfiguration();
    Map<String, Set<Text>> lgroups = new HashMap<>();
    lgroups.put("lg1", ImmutableSet.of(new Text("colFamA"), new Text("colFamB")));
    lgroups.put("lg2", ImmutableSet.of(new Text("colFamC"), new Text("colFamB")));
    ntc.setLocalityGroups(lgroups);
}
Also used : EnumSet(java.util.EnumSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) HashMap(java.util.HashMap) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) Text(org.apache.hadoop.io.Text) Test(org.junit.Test)

Example 43 with NewTableConfiguration

use of org.apache.accumulo.core.client.admin.NewTableConfiguration in project accumulo by apache.

the class NewTableConfigurationIT method testGroupsIteratorAndPropsTogether.

/**
 * Verify use of all three ntc methods - setProperties, setLocalityGroups and attachIterator
 */
@Test
public void testGroupsIteratorAndPropsTogether() throws AccumuloException, TableNotFoundException, AccumuloSecurityException, TableExistsException {
    Connector conn = getConnector();
    String tableName = getUniqueNames(2)[0];
    NewTableConfiguration ntc = new NewTableConfiguration();
    IteratorSetting setting = new IteratorSetting(10, "someName", "foo.bar");
    ntc.attachIterator(setting, EnumSet.of(IteratorScope.scan));
    Map<String, String> props = new HashMap<>();
    props.put(Property.TABLE_ARBITRARY_PROP_PREFIX.getKey() + "prop1", "val1");
    ntc.setProperties(props);
    Map<String, Set<Text>> lgroups = new HashMap<>();
    lgroups.put("lg1", ImmutableSet.of(new Text("colF")));
    ntc.setLocalityGroups(lgroups);
    conn.tableOperations().create(tableName, ntc);
    // verify user table properties
    int count = 0;
    for (Entry<String, String> property : conn.tableOperations().getProperties(tableName)) {
        if (property.getKey().equals(Property.TABLE_ARBITRARY_PROP_PREFIX.getKey() + "prop1")) {
            assertEquals(property.getValue(), "val1");
            count++;
        }
    }
    assertEquals(1, count);
    // verify locality groups
    Map<String, Set<Text>> createdLocalityGroups = conn.tableOperations().getLocalityGroups(tableName);
    assertEquals(1, createdLocalityGroups.size());
    assertEquals(createdLocalityGroups.get("lg1"), ImmutableSet.of(new Text("colF")));
    // verify iterators
    verifyIterators(conn, tableName, new String[] { "table.iterator.scan.someName=10,foo.bar" }, true);
    conn.tableOperations().removeIterator(tableName, "someName", EnumSet.of(IteratorScope.scan));
    verifyIterators(conn, tableName, new String[] {}, true);
}
Also used : Connector(org.apache.accumulo.core.client.Connector) EnumSet(java.util.EnumSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) HashMap(java.util.HashMap) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) Text(org.apache.hadoop.io.Text) Test(org.junit.Test)

Example 44 with NewTableConfiguration

use of org.apache.accumulo.core.client.admin.NewTableConfiguration in project accumulo by apache.

the class ReadWriteIT method sunnyLGUsingNewTableConfiguration.

/**
 * Pretty much identical to sunnyLG, but verifies locality groups are created when configured in NewTableConfiguration prior to table creation.
 */
@Test
public void sunnyLGUsingNewTableConfiguration() throws Exception {
    // create a locality group, write to it and ensure it exists in the RFiles that result
    final Connector connector = getConnector();
    final String tableName = getUniqueNames(1)[0];
    NewTableConfiguration ntc = new NewTableConfiguration();
    Map<String, Set<Text>> groups = new HashMap<>();
    groups.put("g1", Collections.singleton(t("colf")));
    ntc.setLocalityGroups(groups);
    connector.tableOperations().create(tableName, ntc);
    verifyLocalityGroupsInRFile(connector, tableName);
}
Also used : Connector(org.apache.accumulo.core.client.Connector) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) Test(org.junit.Test)

Example 45 with NewTableConfiguration

use of org.apache.accumulo.core.client.admin.NewTableConfiguration in project accumulo by apache.

the class LogicalTimeIT method runMergeTest.

private void runMergeTest(Connector conn, String table, String[] splits, String[] inserts, String start, String end, String last, long expected) throws Exception {
    log.info("table {}", table);
    conn.tableOperations().create(table, new NewTableConfiguration().setTimeType(TimeType.LOGICAL));
    TreeSet<Text> splitSet = new TreeSet<>();
    for (String split : splits) {
        splitSet.add(new Text(split));
    }
    conn.tableOperations().addSplits(table, splitSet);
    BatchWriter bw = conn.createBatchWriter(table, new BatchWriterConfig());
    for (String row : inserts) {
        Mutation m = new Mutation(row);
        m.put("cf", "cq", "v");
        bw.addMutation(m);
    }
    bw.flush();
    conn.tableOperations().merge(table, start == null ? null : new Text(start), end == null ? null : new Text(end));
    Mutation m = new Mutation(last);
    m.put("cf", "cq", "v");
    bw.addMutation(m);
    bw.flush();
    try (Scanner scanner = conn.createScanner(table, Authorizations.EMPTY)) {
        scanner.setRange(new Range(last));
        bw.close();
        long time = scanner.iterator().next().getKey().getTimestamp();
        if (time != expected) {
            throw new RuntimeException("unexpected time " + time + " " + expected);
        }
    }
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) TreeSet(java.util.TreeSet) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) Text(org.apache.hadoop.io.Text) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Range(org.apache.accumulo.core.data.Range)

Aggregations

NewTableConfiguration (org.apache.accumulo.core.client.admin.NewTableConfiguration)54 Test (org.junit.Test)47 Connector (org.apache.accumulo.core.client.Connector)40 HashMap (java.util.HashMap)22 Text (org.apache.hadoop.io.Text)22 BatchWriter (org.apache.accumulo.core.client.BatchWriter)20 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)18 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)17 EnumSet (java.util.EnumSet)13 Mutation (org.apache.accumulo.core.data.Mutation)13 Value (org.apache.accumulo.core.data.Value)13 Set (java.util.Set)12 ImmutableSet (com.google.common.collect.ImmutableSet)11 Scanner (org.apache.accumulo.core.client.Scanner)10 Key (org.apache.accumulo.core.data.Key)10 SummarizerConfiguration (org.apache.accumulo.core.client.summary.SummarizerConfiguration)9 Summary (org.apache.accumulo.core.client.summary.Summary)8 TreeSet (java.util.TreeSet)7 CounterSummary (org.apache.accumulo.core.client.summary.CounterSummary)7 Range (org.apache.accumulo.core.data.Range)5