public Builder addArrayColumn(String name) { int index = _columns.size(); return addColumn(new Column(index, name, ColumnType.ARRAY, "")); }
public Builder renameColumn(int index, String newName) { _checkIndex(index); _columns.set(index, _columns.get(index).withName(newName)); return this; }
name = _reader.nextString(); if (name == null) { _reportError(String.format("Missing header %s", column.getName())); } else if (!column.getName().equals(name)) { _reportError(String.format("Expected header %s, actual header %s", column.getName(), name)); builder.addColumn(name, prev.getType()); } else { builder.addColumn(name);
name = _reader.nextString(); if (name == null) { _reportError(String.format("Missing header %s", column.getName())); } else if (!column.getName().equals(name)) { _reportError(String.format("Expected header %s, actual header %s", column.getName(), name)); builder.addColumn(name, prev.getType()); } else { builder.addColumn(name);
if (_nextColumnByName >= 0) { CsvSchema.Column col = _schema.column(_nextColumnByName); sep = col.isArray() ? col.getArrayElementSeparator() : CsvSchema.NO_ARRAY_ELEMENT_SEPARATOR; } else { sep = CsvSchema.NO_ARRAY_ELEMENT_SEPARATOR;
if (_nextColumnByName >= 0) { CsvSchema.Column col = _schema.column(_nextColumnByName); sep = col.isArray() ? col.getArrayElementSeparator() : CsvSchema.NO_ARRAY_ELEMENT_SEPARATOR; } else { sep = CsvSchema.NO_ARRAY_ELEMENT_SEPARATOR;
builder.addColumn(name, prev.getType()); } else { builder.addColumn(name); int size = newSchema.size(); if (size < 2) { // 1 just because we may get 'empty' header name String first = (size == 0) ? "" : newSchema.column(0).getName().trim(); if (first.length() == 0) { _reportError("Empty header line: can not bind data");
if (column.getType() == CsvSchema.ColumnType.STRING) { _startArray(column); return true;
_currentName = _schema.column(_columnIndex).getName(); return JsonToken.FIELD_NAME;
if (column.getType() == CsvSchema.ColumnType.STRING) { _startArray(column); return true;
_columnsByName = new HashMap<String,Column>(4 + _columns.length); for (Column c : _columns) { _columnsByName.put(c.getName(), c);
_columnsByName = new HashMap<String,Column>(4 + _columns.length); for (Column c : _columns) { _columnsByName.put(c.getName(), c);
/** * Mutant factory method that will construct a new instance in which columns * are sorted based on names given as argument. Columns not listed in argument * will be sorted after those within list, using existing ordering. *<p> * For example, schema that has columns: *<pre>"a", "d", "c", "b" *</pre> * ordered with <code>schema.sortedBy("a", "b");</code> * would result instance that columns in order: *<pre>"a", "b", "d", "c" *</pre> * * @since 2.4 */ public CsvSchema sortedBy(String... columnNames) { LinkedHashMap<String,Column> map = new LinkedHashMap<String,Column>(); for (String colName : columnNames) { Column col = _columnsByName.get(colName); if (col != null) { map.put(col.getName(), col); } } for (Column col : _columns) { map.put(col.getName(), col); } return new CsvSchema(this, map.values().toArray(new Column[map.size()])); }
/** * Mutant factory method that will construct a new instance in which columns * are sorted based on names given as argument. Columns not listed in argument * will be sorted after those within list, using existing ordering. *<p> * For example, schema that has columns: *<pre>"a", "d", "c", "b" *</pre> * ordered with <code>schema.sortedBy("a", "b");</code> * would result instance that columns in order: *<pre>"a", "b", "d", "c" *</pre> * * @since 2.4 */ public CsvSchema sortedBy(String... columnNames) { LinkedHashMap<String,Column> map = new LinkedHashMap<String,Column>(); for (String colName : columnNames) { Column col = _columnsByName.get(colName); if (col != null) { map.put(col.getName(), col); } } for (Column col : _columns) { map.put(col.getName(), col); } return new CsvSchema(this, map.values().toArray(new Column[map.size()])); }
private final void _writeFieldName(String name) throws IOException { // just find the matching index -- must have schema for that if (_schema == null) { // not a low-level error, so: _reportMappingError("Unrecognized column '"+name+"', can not resolve without CsvSchema"); } if (_skipWithin != null) { // new in 2.7 _skipValue = true; _nextColumnByName = -1; return; } // note: we are likely to get next column name, so pass it as hint CsvSchema.Column col = _schema.column(name, _nextColumnByName+1); if (col == null) { if (isEnabled(StreamWriteFeature.IGNORE_UNKNOWN)) { _skipValue = true; _nextColumnByName = -1; return; } // not a low-level error, so: _reportMappingError("Unrecognized column '"+name+"': known columns: "+_schema.getColumnDesc()); } _skipValue = false; // and all we do is just note index to use for following value write _nextColumnByName = col.getIndex(); }
columnNames.add( column.getName() );
/** * Mutant factory method that will try to combine columns of this schema with those * from `toAppend`, starting with columns of this instance, and ignoring * duplicates (if any) from argument `toAppend`. * All settings aside from column sets are copied from `this` instance. *<p> * As with all `withXxx()` methods this method never modifies `this` but either * returns it unmodified (if no new columns found from `toAppend`), or constructs * a new instance and returns that. * * @since 2.9 */ public CsvSchema withColumnsFrom(CsvSchema toAppend) { int addCount = toAppend.size(); if (addCount == 0) { return this; } Builder b = rebuild(); for (int i = 0; i < addCount; ++i) { Column col = toAppend.column(i); if (column(col.getName()) == null) { b.addColumn(col); } } return b.build(); }
/** * Mutant factory method that will try to combine columns of this schema with those * from `toAppend`, starting with columns of this instance, and ignoring * duplicates (if any) from argument `toAppend`. * All settings aside from column sets are copied from `this` instance. *<p> * As with all `withXxx()` methods this method never modifies `this` but either * returns it unmodified (if no new columns found from `toAppend`), or constructs * a new instance and returns that. * * @since 2.9 */ public CsvSchema withColumnsFrom(CsvSchema toAppend) { int addCount = toAppend.size(); if (addCount == 0) { return this; } Builder b = rebuild(); for (int i = 0; i < addCount; ++i) { Column col = toAppend.column(i); if (column(col.getName()) == null) { b.addColumn(col); } } return b.build(); }