@Test public void testBasic() throws Exception { command.partitions = Lists.newArrayList( "email:key", "username:u", "created_at:u"); command.run(); ColumnMapping mapping = new ColumnMapping.Builder() .key("email") .column("username", "u", "username") .counter("created_at", "u", "created_at") .build(); verify(console).info(mapping.toString(true)); verifyNoMoreInteractions(console); }
@Override public int run() throws IOException { Schema schema = new Schema.Parser().parse(open(avroSchemaFile)); boolean hasVersion = false; ColumnMapping.Builder mappingBuilder = new ColumnMapping.Builder(); for (String mapping : partitions) { Matcher matcher = VERSION_MAPPING.matcher(mapping); if (matcher.matches()) { String source = matcher.group(1); ValidationException.check(schema.getField(source) != null, "Not a schema field: %s", source); mappingBuilder.occ(source); hasVersion = true; } } for (String mapping : partitions) { Matcher matcher = KEY_MAPPING.matcher(mapping); if (matcher.matches()) { String source = matcher.group(1); ValidationException.check(schema.getField(source) != null, "Not a schema field: %s", source); mappingBuilder.key(source); continue; } matcher = VERSION_MAPPING.matcher(mapping); if (matcher.matches()) { continue; } matcher = FIELD_MAPPING.matcher(mapping); if (matcher.matches()) { String source = matcher.group(1); String family = matcher.group(2); String qualOrPrefix = matcher.group(3); Schema.Field field = schema.getField(source); ValidationException.check(field != null, "Not a schema field: %s", source); ValidationException.check(family != null && !family.isEmpty(), "Missing column family: %s:?", source); Schema.Type type = schema.getField(source).schema().getType(); if (!hasVersion && counterTypes.contains(type)) { if (qualOrPrefix == null) { mappingBuilder.counter(source, family, source); } else { mappingBuilder.counter(source, family, qualOrPrefix); } } else if (kacTypes.contains(type)) { mappingBuilder.keyAsColumn(source, family, qualOrPrefix); } else { if (qualOrPrefix == null) { mappingBuilder.column(source, family, source); } else { mappingBuilder.column(source, family, qualOrPrefix); } } } else { throw new ValidationException("Unknown mapping: " + mapping); } } DatasetDescriptor descriptor = new DatasetDescriptor.Builder() .columnMapping(mappingBuilder.build()) .schema(open(avroSchemaFile)) .partitionStrategy(open(partitionStrategyFile)) .build(); String mapping = descriptor.getColumnMapping().toString(!minimize); output(mapping, console, outputPath); return 0; }
CreateColumnMappingCommand extends BaseCommand { @Override public int run() throws IOException { Schema schema = new Schema.Parser().parse(open(avroSchemaFile)); boolean hasVersion = false; ColumnMapping.Builder mappingBuilder = new ColumnMapping.Builder(); for (String mapping : partitions) { Matcher matcher = VERSION_MAPPING.matcher(mapping); if (matcher.matches()) { String source = matcher.group(1); ValidationException.check(schema.getField(source) != null, "Not a schema field: %s", source); mappingBuilder.occ(source); hasVersion = true; } } for (String mapping : partitions) { Matcher matcher = KEY_MAPPING.matcher(mapping); if (matcher.matches()) { String source = matcher.group(1); ValidationException.check(schema.getField(source) != null, "Not a schema field: %s", source); mappingBuilder.key(source); continue; } matcher = VERSION_MAPPING.matcher(mapping); if (matcher.matches()) { continue; } matcher = FIELD_MAPPING.matcher(mapping); if (matcher.matches()) { String source = matcher.group(1); String family = matcher.group(2); String qualOrPrefix = matcher.group(3); Schema.Field field = schema.getField(source); ValidationException.check(field != null, "Not a schema field: %s", source); ValidationException.check(family != null && !family.isEmpty(), "Missing column family: %s:?", source); Schema.Type type = schema.getField(source).schema().getType(); if (!hasVersion && counterTypes.contains(type)) { if (qualOrPrefix == null) { mappingBuilder.counter(source, family, source); } else { mappingBuilder.counter(source, family, qualOrPrefix); } } else if (kacTypes.contains(type)) { mappingBuilder.keyAsColumn(source, family, qualOrPrefix); } else { if (qualOrPrefix == null) { mappingBuilder.column(source, family, source); } else { mappingBuilder.column(source, family, qualOrPrefix); } } } else { throw new ValidationException("Unknown mapping: " + mapping); } } DatasetDescriptor descriptor = new DatasetDescriptor.Builder() .columnMapping(mappingBuilder.build()) .schema(open(avroSchemaFile)) .partitionStrategy(open(partitionStrategyFile)) .build(); String mapping = descriptor.getColumnMapping().toString(!minimize); output(mapping, console, outputPath); return 0; } }
CreateColumnMappingCommand extends BaseCommand { @Override public int run() throws IOException { Schema schema = new Schema.Parser().parse(open(avroSchemaFile)); boolean hasVersion = false; ColumnMapping.Builder mappingBuilder = new ColumnMapping.Builder(); for (String mapping : partitions) { Matcher matcher = VERSION_MAPPING.matcher(mapping); if (matcher.matches()) { String source = matcher.group(1); ValidationException.check(schema.getField(source) != null, "Not a schema field: %s", source); mappingBuilder.occ(source); hasVersion = true; } } for (String mapping : partitions) { Matcher matcher = KEY_MAPPING.matcher(mapping); if (matcher.matches()) { String source = matcher.group(1); ValidationException.check(schema.getField(source) != null, "Not a schema field: %s", source); mappingBuilder.key(source); continue; } matcher = VERSION_MAPPING.matcher(mapping); if (matcher.matches()) { continue; } matcher = FIELD_MAPPING.matcher(mapping); if (matcher.matches()) { String source = matcher.group(1); String family = matcher.group(2); String qualOrPrefix = matcher.group(3); Schema.Field field = schema.getField(source); ValidationException.check(field != null, "Not a schema field: %s", source); ValidationException.check(family != null && !family.isEmpty(), "Missing column family: %s:?", source); Schema.Type type = schema.getField(source).schema().getType(); if (!hasVersion && counterTypes.contains(type)) { if (qualOrPrefix == null) { mappingBuilder.counter(source, family, source); } else { mappingBuilder.counter(source, family, qualOrPrefix); } } else if (kacTypes.contains(type)) { mappingBuilder.keyAsColumn(source, family, qualOrPrefix); } else { if (qualOrPrefix == null) { mappingBuilder.column(source, family, source); } else { mappingBuilder.column(source, family, qualOrPrefix); } } } else { throw new ValidationException("Unknown mapping: " + mapping); } } DatasetDescriptor descriptor = new DatasetDescriptor.Builder() .columnMapping(mappingBuilder.build()) .schema(open(avroSchemaFile)) .partitionStrategy(open(partitionStrategyFile)) .build(); String mapping = descriptor.getColumnMapping().toString(!minimize); output(mapping, console, outputPath); return 0; } CreateColumnMappingCommand(Logger console); }
CreateColumnMappingCommand extends BaseCommand { @Override public int run() throws IOException { Schema schema = new Schema.Parser().parse(open(avroSchemaFile)); boolean hasVersion = false; ColumnMapping.Builder mappingBuilder = new ColumnMapping.Builder(); for (String mapping : partitions) { Matcher matcher = VERSION_MAPPING.matcher(mapping); if (matcher.matches()) { String source = matcher.group(1); ValidationException.check(schema.getField(source) != null, "Not a schema field: %s", source); mappingBuilder.occ(source); hasVersion = true; } } for (String mapping : partitions) { Matcher matcher = KEY_MAPPING.matcher(mapping); if (matcher.matches()) { String source = matcher.group(1); ValidationException.check(schema.getField(source) != null, "Not a schema field: %s", source); mappingBuilder.key(source); continue; } matcher = VERSION_MAPPING.matcher(mapping); if (matcher.matches()) { continue; } matcher = FIELD_MAPPING.matcher(mapping); if (matcher.matches()) { String source = matcher.group(1); String family = matcher.group(2); String qualOrPrefix = matcher.group(3); Schema.Field field = schema.getField(source); ValidationException.check(field != null, "Not a schema field: %s", source); ValidationException.check(family != null && !family.isEmpty(), "Missing column family: %s:?", source); Schema.Type type = schema.getField(source).schema().getType(); if (!hasVersion && counterTypes.contains(type)) { if (qualOrPrefix == null) { mappingBuilder.counter(source, family, source); } else { mappingBuilder.counter(source, family, qualOrPrefix); } } else if (kacTypes.contains(type)) { mappingBuilder.keyAsColumn(source, family, qualOrPrefix); } else { if (qualOrPrefix == null) { mappingBuilder.column(source, family, source); } else { mappingBuilder.column(source, family, qualOrPrefix); } } } else { throw new ValidationException("Unknown mapping: " + mapping); } } DatasetDescriptor descriptor = new DatasetDescriptor.Builder() .columnMapping(mappingBuilder.build()) .schema(open(avroSchemaFile)) .partitionStrategy(open(partitionStrategyFile)) .build(); String mapping = descriptor.getColumnMapping().toString(!minimize); output(mapping, console, outputPath); return 0; } CreateColumnMappingCommand(Logger console); @Override int run(); @Override List<String> getExamples(); }
CreateColumnMappingCommand extends BaseCommand { @Override public int run() throws IOException { Schema schema = new Schema.Parser().parse(open(avroSchemaFile)); boolean hasVersion = false; ColumnMapping.Builder mappingBuilder = new ColumnMapping.Builder(); for (String mapping : partitions) { Matcher matcher = VERSION_MAPPING.matcher(mapping); if (matcher.matches()) { String source = matcher.group(1); ValidationException.check(schema.getField(source) != null, "Not a schema field: %s", source); mappingBuilder.occ(source); hasVersion = true; } } for (String mapping : partitions) { Matcher matcher = KEY_MAPPING.matcher(mapping); if (matcher.matches()) { String source = matcher.group(1); ValidationException.check(schema.getField(source) != null, "Not a schema field: %s", source); mappingBuilder.key(source); continue; } matcher = VERSION_MAPPING.matcher(mapping); if (matcher.matches()) { continue; } matcher = FIELD_MAPPING.matcher(mapping); if (matcher.matches()) { String source = matcher.group(1); String family = matcher.group(2); String qualOrPrefix = matcher.group(3); Schema.Field field = schema.getField(source); ValidationException.check(field != null, "Not a schema field: %s", source); ValidationException.check(family != null && !family.isEmpty(), "Missing column family: %s:?", source); Schema.Type type = schema.getField(source).schema().getType(); if (!hasVersion && counterTypes.contains(type)) { if (qualOrPrefix == null) { mappingBuilder.counter(source, family, source); } else { mappingBuilder.counter(source, family, qualOrPrefix); } } else if (kacTypes.contains(type)) { mappingBuilder.keyAsColumn(source, family, qualOrPrefix); } else { if (qualOrPrefix == null) { mappingBuilder.column(source, family, source); } else { mappingBuilder.column(source, family, qualOrPrefix); } } } else { throw new ValidationException("Unknown mapping: " + mapping); } } DatasetDescriptor descriptor = new DatasetDescriptor.Builder() .columnMapping(mappingBuilder.build()) .schema(open(avroSchemaFile)) .partitionStrategy(open(partitionStrategyFile)) .build(); String mapping = descriptor.getColumnMapping().toString(!minimize); output(mapping, console, outputPath); return 0; } CreateColumnMappingCommand(Logger console); @Override int run(); @Override List<String> getExamples();  }