@Test public void testBasic() throws Exception { command.partitions = Lists.newArrayList( "username:hash[16]", "username:copy"); command.run(); PartitionStrategy strategy = new PartitionStrategy.Builder() .hash("username", 16) .identity("username") .build(); verify(console).info(strategy.toString(true)); verifyNoMoreInteractions(console); }
@Override public int run() throws IOException { PartitionStrategy.Builder strategyBuilder = new PartitionStrategy.Builder(); for (String partition : partitions) { Matcher m = PARTITION_FIELD.matcher(partition); if (m.matches()) { String fieldName = m.group(1); ValidationException.check(fieldName != null && !fieldName.isEmpty(), "Invalid field name: %s", String.valueOf(fieldName)); String partitionerType = m.group(2); if ("hash".equals(partitionerType)) { String width = m.group(3); ValidationException.check(width != null, "Missing number of hash partitions: %s:hash[?]", fieldName); strategyBuilder.hash(fieldName, Integer.parseInt(width)); } else if ("copy".equals(partitionerType)) { strategyBuilder.identity(fieldName); } else if ("year".equals(partitionerType)) { strategyBuilder.year(fieldName); } else if ("month".equals(partitionerType)) { strategyBuilder.month(fieldName); } else if ("day".equals(partitionerType)) { strategyBuilder.day(fieldName); } else if ("hour".equals(partitionerType)) { strategyBuilder.hour(fieldName); } else if ("minute".equals(partitionerType)) { strategyBuilder.minute(fieldName); } else if ("provided".equals(partitionerType)) { strategyBuilder.provided(fieldName); } else { throw new ValidationException( "Unknown partitioner type: " + partitionerType); } } else { throw new ValidationException( "Invalid partition <field:type>: " + partition); } } DatasetDescriptor descriptor = new DatasetDescriptor.Builder() .partitionStrategy(strategyBuilder.build()) .schema(open(avroSchemaFile)) .build(); String strategy = descriptor.getPartitionStrategy().toString(!minimize); output(strategy, console, outputPath); return 0; }
CreatePartitionStrategyCommand extends BaseCommand { @Override public int run() throws IOException { PartitionStrategy.Builder strategyBuilder = new PartitionStrategy.Builder(); for (String partition : partitions) { Matcher m = PARTITION_FIELD.matcher(partition); if (m.matches()) { String fieldName = m.group(1); ValidationException.check(fieldName != null && !fieldName.isEmpty(), "Invalid field name: %s", String.valueOf(fieldName)); String partitionerType = m.group(2); if ("hash".equals(partitionerType)) { String width = m.group(3); ValidationException.check(width != null, "Missing number of hash partitions: %s:hash[?]", fieldName); strategyBuilder.hash(fieldName, Integer.parseInt(width)); } else if ("copy".equals(partitionerType)) { strategyBuilder.identity(fieldName); } else if ("year".equals(partitionerType)) { strategyBuilder.year(fieldName); } else if ("month".equals(partitionerType)) { strategyBuilder.month(fieldName); } else if ("day".equals(partitionerType)) { strategyBuilder.day(fieldName); } else if ("hour".equals(partitionerType)) { strategyBuilder.hour(fieldName); } else if ("minute".equals(partitionerType)) { strategyBuilder.minute(fieldName); } else if ("provided".equals(partitionerType)) { strategyBuilder.provided(fieldName); } else { throw new ValidationException( "Unknown partitioner type: " + partitionerType); } } else { throw new ValidationException( "Invalid partition <field:type>: " + partition); } } DatasetDescriptor descriptor = new DatasetDescriptor.Builder() .partitionStrategy(strategyBuilder.build()) .schema(open(avroSchemaFile)) .build(); String strategy = descriptor.getPartitionStrategy().toString(!minimize); output(strategy, console, outputPath); return 0; } }
CreatePartitionStrategyCommand extends BaseCommand { @Override public int run() throws IOException { PartitionStrategy.Builder strategyBuilder = new PartitionStrategy.Builder(); for (String partition : partitions) { Matcher m = PARTITION_FIELD.matcher(partition); if (m.matches()) { String fieldName = m.group(1); ValidationException.check(fieldName != null && !fieldName.isEmpty(), "Invalid field name: %s", String.valueOf(fieldName)); String partitionerType = m.group(2); if ("hash".equals(partitionerType)) { String width = m.group(3); ValidationException.check(width != null, "Missing number of hash partitions: %s:hash[?]", fieldName); strategyBuilder.hash(fieldName, Integer.parseInt(width)); } else if ("copy".equals(partitionerType)) { strategyBuilder.identity(fieldName); } else if ("year".equals(partitionerType)) { strategyBuilder.year(fieldName); } else if ("month".equals(partitionerType)) { strategyBuilder.month(fieldName); } else if ("day".equals(partitionerType)) { strategyBuilder.day(fieldName); } else if ("hour".equals(partitionerType)) { strategyBuilder.hour(fieldName); } else if ("minute".equals(partitionerType)) { strategyBuilder.minute(fieldName); } else if ("provided".equals(partitionerType)) { strategyBuilder.provided(fieldName); } else { throw new ValidationException( "Unknown partitioner type: " + partitionerType); } } else { throw new ValidationException( "Invalid partition <field:type>: " + partition); } } DatasetDescriptor descriptor = new DatasetDescriptor.Builder() .partitionStrategy(strategyBuilder.build()) .schema(open(avroSchemaFile)) .build(); String strategy = descriptor.getPartitionStrategy().toString(!minimize); output(strategy, console, outputPath); return 0; } CreatePartitionStrategyCommand(Logger console); }
CreatePartitionStrategyCommand extends BaseCommand { @Override public int run() throws IOException { PartitionStrategy.Builder strategyBuilder = new PartitionStrategy.Builder(); for (String partition : partitions) { Matcher m = PARTITION_FIELD.matcher(partition); if (m.matches()) { String fieldName = m.group(1); ValidationException.check(fieldName != null && !fieldName.isEmpty(), "Invalid field name: %s", String.valueOf(fieldName)); String partitionerType = m.group(2); if ("hash".equals(partitionerType)) { String width = m.group(3); ValidationException.check(width != null, "Missing number of hash partitions: %s:hash[?]", fieldName); strategyBuilder.hash(fieldName, Integer.parseInt(width)); } else if ("copy".equals(partitionerType)) { strategyBuilder.identity(fieldName); } else if ("year".equals(partitionerType)) { strategyBuilder.year(fieldName); } else if ("month".equals(partitionerType)) { strategyBuilder.month(fieldName); } else if ("day".equals(partitionerType)) { strategyBuilder.day(fieldName); } else if ("hour".equals(partitionerType)) { strategyBuilder.hour(fieldName); } else if ("minute".equals(partitionerType)) { strategyBuilder.minute(fieldName); } else if ("provided".equals(partitionerType)) { strategyBuilder.provided(fieldName); } else { throw new ValidationException( "Unknown partitioner type: " + partitionerType); } } else { throw new ValidationException( "Invalid partition <field:type>: " + partition); } } DatasetDescriptor descriptor = new DatasetDescriptor.Builder() .partitionStrategy(strategyBuilder.build()) .schema(open(avroSchemaFile)) .build(); String strategy = descriptor.getPartitionStrategy().toString(!minimize); output(strategy, console, outputPath); return 0; } CreatePartitionStrategyCommand(Logger console); @Override int run(); @Override List<String> getExamples(); }
CreatePartitionStrategyCommand extends BaseCommand { @Override public int run() throws IOException { PartitionStrategy.Builder strategyBuilder = new PartitionStrategy.Builder(); for (String partition : partitions) { Matcher m = PARTITION_FIELD.matcher(partition); if (m.matches()) { String fieldName = m.group(1); ValidationException.check(fieldName != null && !fieldName.isEmpty(), "Invalid field name: %s", String.valueOf(fieldName)); String partitionerType = m.group(2); if ("hash".equals(partitionerType)) { String width = m.group(3); ValidationException.check(width != null, "Missing number of hash partitions: %s:hash[?]", fieldName); strategyBuilder.hash(fieldName, Integer.parseInt(width)); } else if ("copy".equals(partitionerType)) { strategyBuilder.identity(fieldName); } else if ("year".equals(partitionerType)) { strategyBuilder.year(fieldName); } else if ("month".equals(partitionerType)) { strategyBuilder.month(fieldName); } else if ("day".equals(partitionerType)) { strategyBuilder.day(fieldName); } else if ("hour".equals(partitionerType)) { strategyBuilder.hour(fieldName); } else if ("minute".equals(partitionerType)) { strategyBuilder.minute(fieldName); } else if ("provided".equals(partitionerType)) { strategyBuilder.provided(fieldName); } else { throw new ValidationException( "Unknown partitioner type: " + partitionerType); } } else { throw new ValidationException( "Invalid partition <field:type>: " + partition); } } DatasetDescriptor descriptor = new DatasetDescriptor.Builder() .partitionStrategy(strategyBuilder.build()) .schema(open(avroSchemaFile)) .build(); String strategy = descriptor.getPartitionStrategy().toString(!minimize); output(strategy, console, outputPath); return 0; } CreatePartitionStrategyCommand(Logger console); @Override int run(); @Override List<String> getExamples();  }