/** * Private constructor to prevent instantiation */ public CsvWriter(Table table, CsvWriteOptions options) { this.table = table; this.header = options.header(); this.writer = options.writer(); this.settings = new CsvWriterSettings(); // Sets the character sequence to write for the values that are null. settings.setNullValue(nullValue); settings.getFormat().setDelimiter(options.separator()); settings.getFormat().setQuote(options.quoteChar()); settings.getFormat().setQuoteEscape(options.escapeChar()); settings.getFormat().setLineSeparator(options.lineEnd()); // writes empty lines as well. settings.setSkipEmptyLines(false); }
/** * {@inheritDoc} */ @Override protected void configureFormat(CsvFormat format) { super.configureFormat(format); if (quote != null) { format.setQuote(quote); } if (quoteEscape != null) { format.setQuoteEscape(quoteEscape); } if (delimiter != null) { format.setDelimiter(delimiter); } }
public static CsvParserSettings extractCsvParserSettings(Configuration job) { CsvParserSettings parserSettings = new CsvParserSettings(); parserSettings.getFormat().setDelimiter(job.get(DELIMITER, DELIMITER_DEFAULT).charAt(0)); parserSettings.getFormat().setComment(job.get(COMMENT, COMMENT_DEFAULT).charAt(0)); parserSettings.setLineSeparatorDetectionEnabled(true); parserSettings.setNullValue(""); parserSettings.setEmptyValue(""); parserSettings.setIgnoreLeadingWhitespaces(false); parserSettings.setIgnoreTrailingWhitespaces(false); parserSettings.setSkipEmptyLines( Boolean.valueOf(job.get(SKIP_EMPTY_LINE, CarbonCommonConstants.CARBON_SKIP_EMPTY_LINE_DEFAULT))); // todo: will verify whether there is a performance degrade using -1 here // parserSettings.setMaxCharsPerColumn(CarbonCommonConstants.MAX_CHARS_PER_COLUMN_DEFAULT); parserSettings.setMaxCharsPerColumn(CarbonCommonConstants.MAX_CHARS_PER_COLUMN_INFINITY); String maxColumns = job.get(MAX_COLUMNS, "" + DEFAULT_MAX_NUMBER_OF_COLUMNS_FOR_PARSING); parserSettings.setMaxColumns(Integer.parseInt(maxColumns)); parserSettings.getFormat().setQuote(job.get(QUOTE, QUOTE_DEFAULT).charAt(0)); parserSettings.getFormat().setQuoteEscape(job.get(ESCAPE, ESCAPE_DEFAULT).charAt(0)); // setting the content length to to limit the length of displayed contents being parsed/written // in the exception message when an error occurs. parserSettings.setErrorContentLength(CarbonCommonConstants.CARBON_ERROR_CONTENT_LENGTH); return parserSettings; }
settings.getFormat().setQuoteEscape(loadData.getEscape().charAt(0));
/** * Returns the CSV format detected when one of the following settings is enabled: * <ul> * <li>{@link CommonParserSettings#isLineSeparatorDetectionEnabled()}</li> * <li>{@link CsvParserSettings#isDelimiterDetectionEnabled()}</li> * <li>{@link CsvParserSettings#isQuoteDetectionEnabled()}</li> * </ul> * * The detected format will be available once the parsing process is initialized (i.e. when {@link AbstractParser#beginParsing(Reader) runs}. * * @return the detected CSV format, or {@code null} if no detection has been enabled or if the parsing process has not been started yet. */ public final CsvFormat getDetectedFormat() { CsvFormat out = null; if (settings.isDelimiterDetectionEnabled()) { out = settings.getFormat().clone(); out.setDelimiter(this.delimiter); } if (settings.isQuoteDetectionEnabled()) { out = out == null ? settings.getFormat().clone() : out; out.setQuote(quote); out.setQuoteEscape(quoteEscape); } if (settings.isLineSeparatorDetectionEnabled()) { out = out == null ? settings.getFormat().clone() : out; out.setLineSeparator(input.getLineSeparator()); } return out; }
/** * Private constructor to prevent instantiation */ public CsvWriter(Table table, CsvWriteOptions options) { this.table = table; this.header = options.header(); this.writer = options.writer(); this.settings = new CsvWriterSettings(); // Sets the character sequence to write for the values that are null. settings.setNullValue(nullValue); settings.getFormat().setDelimiter(options.separator()); settings.getFormat().setQuote(options.quoteChar()); settings.getFormat().setQuoteEscape(options.escapeChar()); settings.getFormat().setLineSeparator(options.lineEnd()); // writes empty lines as well. settings.setSkipEmptyLines(false); }