org.kitesdk.data.spi.filesystem.CSVProperties Java Examples

The following examples show how to use org.kitesdk.data.spi.filesystem.CSVProperties. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CSVSchemaCommand.java    From kite with Apache License 2.0 5 votes vote down vote up
@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) {
    // if a header is given on the command line, do assume one is in the file
    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);
  }

  // assume fields are nullable by default, users can easily change this
  String sampleSchema = CSVUtil
      .inferNullableSchema(
          recordName, open(samplePaths.get(0)), props, required)
      .toString(!minimize);

  output(sampleSchema, console, outputPath);

  return 0;
}