Search in sources :

Example 1 with TimeType

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

the class NewTableConfigurationIT method tableNameLimitVersionAndTimeType.

@SuppressWarnings("deprecation")
@Test
public void tableNameLimitVersionAndTimeType() throws Exception {
    log.info("Starting tableNameLimitVersionAndTimeType");
    // Create a table with the initial properties
    Connector connector = getConnector();
    String tableName = getUniqueNames(2)[0];
    boolean limitVersion = false;
    TimeType tt = TimeType.LOGICAL;
    connector.tableOperations().create(tableName, new NewTableConfiguration().withoutDefaultIterators().setTimeType(tt));
    String tableNameOrig = "originalWithLimitVersionAndTimeType";
    connector.tableOperations().create(tableNameOrig, limitVersion, tt);
    int countNew = numProperties(connector, tableName);
    int countOrig = compareProperties(connector, tableNameOrig, tableName, null);
    Assert.assertEquals("Extra properties using the new create method", countOrig, countNew);
    Assert.assertTrue("Wrong TimeType", checkTimeType(connector, tableName, tt));
}
Also used : Connector(org.apache.accumulo.core.client.Connector) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) TimeType(org.apache.accumulo.core.client.admin.TimeType) Test(org.junit.Test)

Example 2 with TimeType

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

the class CreateTableCommand method execute.

@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException, IOException, ClassNotFoundException {
    final String testTableName = cl.getArgs()[0];
    final HashMap<String, String> props = new HashMap<>();
    NewTableConfiguration ntc = new NewTableConfiguration();
    if (!testTableName.matches(Tables.VALID_NAME_REGEX)) {
        shellState.getReader().println("Only letters, numbers and underscores are allowed for use in table names.");
        throw new IllegalArgumentException();
    }
    final String tableName = cl.getArgs()[0];
    if (shellState.getConnector().tableOperations().exists(tableName)) {
        throw new TableExistsException(null, tableName, null);
    }
    final SortedSet<Text> partitions = new TreeSet<>();
    final boolean decode = cl.hasOption(base64Opt.getOpt());
    if (cl.hasOption(createTableOptSplit.getOpt())) {
        partitions.addAll(ShellUtil.scanFile(cl.getOptionValue(createTableOptSplit.getOpt()), decode));
    } else if (cl.hasOption(createTableOptCopySplits.getOpt())) {
        final String oldTable = cl.getOptionValue(createTableOptCopySplits.getOpt());
        if (!shellState.getConnector().tableOperations().exists(oldTable)) {
            throw new TableNotFoundException(null, oldTable, null);
        }
        partitions.addAll(shellState.getConnector().tableOperations().listSplits(oldTable));
    }
    if (cl.hasOption(createTableOptCopyConfig.getOpt())) {
        final String oldTable = cl.getOptionValue(createTableOptCopyConfig.getOpt());
        if (!shellState.getConnector().tableOperations().exists(oldTable)) {
            throw new TableNotFoundException(null, oldTable, null);
        }
    }
    TimeType timeType = TimeType.MILLIS;
    if (cl.hasOption(createTableOptTimeLogical.getOpt())) {
        timeType = TimeType.LOGICAL;
    }
    if (cl.hasOption(createTableOptInitProp.getOpt())) {
        String[] keyVals = StringUtils.split(cl.getOptionValue(createTableOptInitProp.getOpt()), ',');
        for (String keyVal : keyVals) {
            String[] sa = StringUtils.split(keyVal, '=');
            props.put(sa[0], sa[1]);
        }
    }
    // Set iterator if supplied
    if (cl.hasOption(createTableOptIteratorProps.getOpt())) {
        ntc = attachIteratorToNewTable(cl, shellState, ntc);
    }
    // Set up locality groups, if supplied
    if (cl.hasOption(createTableOptLocalityProps.getOpt())) {
        ntc = setLocalityForNewTable(cl, ntc);
    }
    // create table
    shellState.getConnector().tableOperations().create(tableName, ntc.setTimeType(timeType).setProperties(props));
    if (partitions.size() > 0) {
        shellState.getConnector().tableOperations().addSplits(tableName, partitions);
    }
    // switch shell to new table context
    shellState.setTableName(tableName);
    if (cl.hasOption(createTableNoDefaultIters.getOpt())) {
        for (String key : IteratorUtil.generateInitialTableProperties(true).keySet()) {
            shellState.getConnector().tableOperations().removeProperty(tableName, key);
        }
    }
    // Copy options if flag was set
    if (cl.hasOption(createTableOptCopyConfig.getOpt())) {
        if (shellState.getConnector().tableOperations().exists(tableName)) {
            final Iterable<Entry<String, String>> configuration = shellState.getConnector().tableOperations().getProperties(cl.getOptionValue(createTableOptCopyConfig.getOpt()));
            for (Entry<String, String> entry : configuration) {
                if (Property.isValidTablePropertyKey(entry.getKey())) {
                    shellState.getConnector().tableOperations().setProperty(tableName, entry.getKey(), entry.getValue());
                }
            }
        }
    }
    if (cl.hasOption(createTableOptEVC.getOpt())) {
        try {
            shellState.getConnector().tableOperations().addConstraint(tableName, VisibilityConstraint.class.getName());
        } catch (AccumuloException e) {
            Shell.log.warn(e.getMessage() + " while setting visibility constraint, but table was created");
        }
    }
    // Load custom formatter if set
    if (cl.hasOption(createTableOptFormatter.getOpt())) {
        final String formatterClass = cl.getOptionValue(createTableOptFormatter.getOpt());
        shellState.getConnector().tableOperations().setProperty(tableName, Property.TABLE_FORMATTER_CLASS.toString(), formatterClass);
    }
    return 0;
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) HashMap(java.util.HashMap) VisibilityConstraint(org.apache.accumulo.core.constraints.VisibilityConstraint) Text(org.apache.hadoop.io.Text) TimeType(org.apache.accumulo.core.client.admin.TimeType) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) Entry(java.util.Map.Entry) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) TreeSet(java.util.TreeSet) TableExistsException(org.apache.accumulo.core.client.TableExistsException)

Aggregations

NewTableConfiguration (org.apache.accumulo.core.client.admin.NewTableConfiguration)2 TimeType (org.apache.accumulo.core.client.admin.TimeType)2 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 TreeSet (java.util.TreeSet)1 AccumuloException (org.apache.accumulo.core.client.AccumuloException)1 Connector (org.apache.accumulo.core.client.Connector)1 TableExistsException (org.apache.accumulo.core.client.TableExistsException)1 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)1 VisibilityConstraint (org.apache.accumulo.core.constraints.VisibilityConstraint)1 Text (org.apache.hadoop.io.Text)1 Test (org.junit.Test)1