@Test public void testSchemaToFile() throws Exception { command.samplePaths = Lists.newArrayList("target/users.csv"); command.recordName = "User"; command.outputPath = "target/user.avsc"; int rc = command.run(); Assert.assertEquals("Should return success code", 0, rc); String fileContent = Files.toString( new File("target/user.avsc"), BaseCommand.UTF8); Assert.assertTrue("File should contain pretty printed schema", TestUtil.matchesSchema(schema).matches(fileContent)); verifyNoMoreInteractions(console); }
@Override public int run() throws IOException { Preconditions.checkArgument(samplePaths != null && !samplePaths.isEmpty(), "Sample CSV path is required"); Preconditions.checkArgument(samplePaths.size() == 1, "Only one CSV sample can be given"); if (header != null) { noHeader = true; } CSVProperties props = new CSVProperties.Builder() .delimiter(delimiter) .escape(escape) .quote(quote) .header(header) .hasHeader(!noHeader) .linesToSkip(linesToSkip) .charset(charsetName) .build(); Set<String> required = ImmutableSet.of(); if (requiredFields != null) { required = ImmutableSet.copyOf(requiredFields); } String sampleSchema = CSVUtil .inferNullableSchema( recordName, open(samplePaths.get(0)), props, required) .toString(!minimize); output(sampleSchema, console, outputPath); return 0; }
CSVSchemaCommand extends BaseCommand { @Override public int run() throws IOException { Preconditions.checkArgument(samplePaths != null && !samplePaths.isEmpty(), "Sample CSV path is required"); Preconditions.checkArgument(samplePaths.size() == 1, "Only one CSV sample can be given"); if (header != null) { noHeader = true; } CSVProperties props = new CSVProperties.Builder() .delimiter(delimiter) .escape(escape) .quote(quote) .header(header) .hasHeader(!noHeader) .linesToSkip(linesToSkip) .charset(charsetName) .build(); Set<String> required = ImmutableSet.of(); if (requiredFields != null) { required = ImmutableSet.copyOf(requiredFields); } String sampleSchema = CSVUtil .inferNullableSchema( recordName, open(samplePaths.get(0)), props, required) .toString(!minimize); output(sampleSchema, console, outputPath); return 0; } }
CSVSchemaCommand extends BaseCommand { @Override public int run() throws IOException { Preconditions.checkArgument(samplePaths != null && !samplePaths.isEmpty(), "Sample CSV path is required"); Preconditions.checkArgument(samplePaths.size() == 1, "Only one CSV sample can be given"); if (header != null) { noHeader = true; } CSVProperties props = new CSVProperties.Builder() .delimiter(delimiter) .escape(escape) .quote(quote) .header(header) .hasHeader(!noHeader) .linesToSkip(linesToSkip) .charset(charsetName) .build(); Set<String> required = ImmutableSet.of(); if (requiredFields != null) { required = ImmutableSet.copyOf(requiredFields); } String sampleSchema = CSVUtil .inferNullableSchema( recordName, open(samplePaths.get(0)), props, required) .toString(!minimize); output(sampleSchema, console, outputPath); return 0; } CSVSchemaCommand(Logger console); }
CSVSchemaCommand extends BaseCommand { @Override public int run() throws IOException { Preconditions.checkArgument(samplePaths != null && !samplePaths.isEmpty(), "Sample CSV path is required"); Preconditions.checkArgument(samplePaths.size() == 1, "Only one CSV sample can be given"); if (header != null) { noHeader = true; } CSVProperties props = new CSVProperties.Builder() .delimiter(delimiter) .escape(escape) .quote(quote) .header(header) .hasHeader(!noHeader) .linesToSkip(linesToSkip) .charset(charsetName) .build(); Set<String> required = ImmutableSet.of(); if (requiredFields != null) { required = ImmutableSet.copyOf(requiredFields); } String sampleSchema = CSVUtil .inferNullableSchema( recordName, open(samplePaths.get(0)), props, required) .toString(!minimize); output(sampleSchema, console, outputPath); return 0; } CSVSchemaCommand(Logger console); @Override int run(); @Override List<String> getExamples(); @Override void setConf(Configuration conf); @Override Configuration getConf(); }
CSVSchemaCommand extends BaseCommand { @Override public int run() throws IOException { Preconditions.checkArgument(samplePaths != null && !samplePaths.isEmpty(), "Sample CSV path is required"); Preconditions.checkArgument(samplePaths.size() == 1, "Only one CSV sample can be given"); if (header != null) { noHeader = true; } CSVProperties props = new CSVProperties.Builder() .delimiter(delimiter) .escape(escape) .quote(quote) .header(header) .hasHeader(!noHeader) .linesToSkip(linesToSkip) .charset(charsetName) .build(); Set<String> required = ImmutableSet.of(); if (requiredFields != null) { required = ImmutableSet.copyOf(requiredFields); } String sampleSchema = CSVUtil .inferNullableSchema( recordName, open(samplePaths.get(0)), props, required) .toString(!minimize); output(sampleSchema, console, outputPath); return 0; } CSVSchemaCommand(Logger console); @Override int run(); @Override List<String> getExamples(); @Override void setConf(Configuration conf); @Override Configuration getConf();  }