Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SOLR-14279: remove CSVStrategy's deprecated setters #480

Merged
merged 2 commits into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -166,45 +166,51 @@ protected CSVLoaderBase(SolrQueryRequest req, UpdateRequestProcessor processor)
templateAdd.overwrite=params.getBool(OVERWRITE,true);
templateAdd.commitWithin = params.getInt(UpdateParams.COMMIT_WITHIN, -1);

strategy = new CSVStrategy(',', '"', CSVStrategy.COMMENTS_DISABLED, CSVStrategy.ESCAPE_DISABLED, false, false, false, true, "\n");
char delimiter = ',';
String sep = params.get(SEPARATOR);
if (sep!=null) {
if (sep.length()!=1) throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Invalid separator:'"+sep+"'");
strategy.setDelimiter(sep.charAt(0));
delimiter = sep.charAt(0);
}

char encapsulatorChar = '"';
String encapsulator = params.get(ENCAPSULATOR);
if (encapsulator!=null) {
if (encapsulator.length()!=1) throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Invalid encapsulator:'"+encapsulator+"'");
}

char escapeChar = CSVStrategy.ESCAPE_DISABLED;
String escape = params.get(ESCAPE);
if (escape!=null) {
if (escape.length()!=1) throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Invalid escape:'"+escape+"'");
}
rowId = params.get(ROW_ID);
rowIdOffset = params.getInt(ROW_ID_OFFSET, 0);

boolean interpretUnicodeEscapes = false;
// if only encapsulator or escape is set, disable the other escaping mechanism
if (encapsulator == null && escape != null) {
strategy.setEncapsulator( CSVStrategy.ENCAPSULATOR_DISABLED);
strategy.setEscape(escape.charAt(0));
encapsulatorChar = CSVStrategy.ENCAPSULATOR_DISABLED;
escapeChar = escape.charAt(0);
} else {
if (encapsulator != null) {
strategy.setEncapsulator(encapsulator.charAt(0));
encapsulatorChar = encapsulator.charAt(0);
}
if (escape != null) {
char ch = escape.charAt(0);
strategy.setEscape(ch);
escapeChar = ch;
if (ch == '\\') {
// If the escape is the standard backslash, then also enable
// unicode escapes (it's harmless since 'u' would not otherwise
// be escaped.
strategy.setUnicodeEscapeInterpretation(true);
interpretUnicodeEscapes = true;
}
}
}

strategy = new CSVStrategy(delimiter, encapsulatorChar, CSVStrategy.COMMENTS_DISABLED, escapeChar, false, false, interpretUnicodeEscapes, true, "\n");

rowId = params.get(ROW_ID);
rowIdOffset = params.getInt(ROW_ID_OFFSET, 0);

String fn = params.get(FIELDNAMES);
fieldnames = fn != null ? commaSplit.split(fn,-1) : null;

Expand Down
157 changes: 12 additions & 145 deletions solr/core/src/java/org/apache/solr/internal/csv/CSVStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@
*/
public class CSVStrategy implements Cloneable, Serializable {

private char delimiter;
private char encapsulator;
private char commentStart;
private char escape;
private boolean ignoreLeadingWhitespaces;
private boolean ignoreTrailingWhitespaces;
private boolean interpretUnicodeEscapes;
private boolean ignoreEmptyLines;
final private char delimiter;
final private char encapsulator;
final private char commentStart;
final private char escape;
final private boolean ignoreLeadingWhitespaces;
final private boolean ignoreTrailingWhitespaces;
final private boolean interpretUnicodeEscapes;
final private boolean ignoreEmptyLines;

// controls for output
private String printerNewline;
final private String printerNewline;

// -2 is used to signal disabled, because it won't be confused with
// an EOF signal (-1), and because \ufffe in UTF-16 would be
Expand All @@ -46,11 +46,11 @@ public class CSVStrategy implements Cloneable, Serializable {
public static char ENCAPSULATOR_DISABLED = (char)-2;
public static String DEFAULT_PRINTER_NEWLINE = "\n";

public static final CSVStrategy DEFAULT_STRATEGY = new ImmutableCSVStrategy
public static final CSVStrategy DEFAULT_STRATEGY = new CSVStrategy
(',', '"', COMMENTS_DISABLED, ESCAPE_DISABLED, true, true, false, true, DEFAULT_PRINTER_NEWLINE);
public static final CSVStrategy EXCEL_STRATEGY = new ImmutableCSVStrategy
public static final CSVStrategy EXCEL_STRATEGY = new CSVStrategy
(',', '"', COMMENTS_DISABLED, ESCAPE_DISABLED, false, false, false, false, DEFAULT_PRINTER_NEWLINE);
public static final CSVStrategy TDF_STRATEGY = new ImmutableCSVStrategy
public static final CSVStrategy TDF_STRATEGY = new CSVStrategy
('\t', '"', COMMENTS_DISABLED, ESCAPE_DISABLED, true, true, false, true, DEFAULT_PRINTER_NEWLINE);

public CSVStrategy(char delimiter, char encapsulator, char commentStart) {
Expand Down Expand Up @@ -88,158 +88,25 @@ public CSVStrategy(char delimiter, char encapsulator, char commentStart, char es
this.printerNewline = printerNewline;
}

/**
* Customized CSV strategy setter.
*
* @param delimiter a Char used for value separation
* @param encapsulator a Char used as value encapsulation marker
* @param commentStart a Char used for comment identification
* @param escape a Char used for escaping
* @param ignoreTrailingWhitespaces TRUE when trailing whitespaces should be
* ignored
* @param ignoreLeadingWhitespaces TRUE when leading whitespaces should be
* ignored
* @param interpretUnicodeEscapes TRUE when unicode escapes should be
* interpreted
* @param ignoreEmptyLines TRUE when the parser should skip emtpy lines
* @deprecated Use the ctor that also takes printerNewline. This ctor will be removed in Solr 7.
*/
@Deprecated
public CSVStrategy(char delimiter, char encapsulator, char commentStart, char escape,
boolean ignoreLeadingWhitespaces, boolean ignoreTrailingWhitespaces,
boolean interpretUnicodeEscapes, boolean ignoreEmptyLines) {
this(delimiter, encapsulator, commentStart, escape,
ignoreLeadingWhitespaces, ignoreTrailingWhitespaces,
interpretUnicodeEscapes, ignoreEmptyLines,
DEFAULT_PRINTER_NEWLINE);
}

/** @deprecated will be removed in Solr 7 */
@Deprecated
public void setDelimiter(char delimiter) { this.delimiter = delimiter; }
public char getDelimiter() { return this.delimiter; }

/** @deprecated will be removed in Solr 7 */
@Deprecated
public void setEncapsulator(char encapsulator) { this.encapsulator = encapsulator; }
public char getEncapsulator() { return this.encapsulator; }

/** @deprecated will be removed in Solr 7 */
@Deprecated
public void setCommentStart(char commentStart) { this.commentStart = commentStart; }
public char getCommentStart() { return this.commentStart; }
public boolean isCommentingDisabled() { return this.commentStart == COMMENTS_DISABLED; }

/** @deprecated will be removed in Solr 7 */
@Deprecated
public void setEscape(char escape) { this.escape = escape; }
public char getEscape() { return this.escape; }

/** @deprecated will be removed in Solr 7 */
@Deprecated
public void setIgnoreLeadingWhitespaces(boolean ignoreLeadingWhitespaces) {
this.ignoreLeadingWhitespaces = ignoreLeadingWhitespaces;
}
public boolean getIgnoreLeadingWhitespaces() { return this.ignoreLeadingWhitespaces; }

/** @deprecated will be removed in Solr 7 */
@Deprecated
public void setIgnoreTrailingWhitespaces(boolean ignoreTrailingWhitespaces) {
this.ignoreTrailingWhitespaces = ignoreTrailingWhitespaces;
}
public boolean getIgnoreTrailingWhitespaces() { return this.ignoreTrailingWhitespaces; }

/** @deprecated will be removed in Solr 7 */
@Deprecated
public void setUnicodeEscapeInterpretation(boolean interpretUnicodeEscapes) {
this.interpretUnicodeEscapes = interpretUnicodeEscapes;
}
public boolean getUnicodeEscapeInterpretation() { return this.interpretUnicodeEscapes; }

/** @deprecated will be removed in Solr 7 */
@Deprecated
public void setIgnoreEmptyLines(boolean ignoreEmptyLines) { this.ignoreEmptyLines = ignoreEmptyLines; }
public boolean getIgnoreEmptyLines() { return this.ignoreEmptyLines; }

/** @deprecated will be removed in Solr 7 */
@Deprecated
public void setPrinterNewline(String newline) {
this.printerNewline = newline;
}
public String getPrinterNewline() {
return this.printerNewline;
}

/** @deprecated will be removed in Solr 7 */
@Deprecated
@Override
public Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException e) {
throw new RuntimeException(e); // impossible
}
}
}

/**
* @deprecated will be removed in Solr 7
* @lucene.internal
*/
@Deprecated
class ImmutableCSVStrategy extends CSVStrategy {
ImmutableCSVStrategy(char delimiter, char encapsulator, char commentStart, char escape,
boolean ignoreLeadingWhitespaces, boolean ignoreTrailingWhitespaces,
boolean interpretUnicodeEscapes, boolean ignoreEmptyLines,
String printerNewline) {
super(delimiter, encapsulator, commentStart, escape,
ignoreLeadingWhitespaces, ignoreTrailingWhitespaces,
interpretUnicodeEscapes, ignoreEmptyLines,
printerNewline);
}
@Override
public void setDelimiter(char delimiter) {
throw new UnsupportedOperationException();
}
@Override
public void setEncapsulator(char encapsulator) {
throw new UnsupportedOperationException();
}
@Override
public void setCommentStart(char commentStart) {
throw new UnsupportedOperationException();
}
@Override
public void setEscape(char escape) {
throw new UnsupportedOperationException();
}
@Override
public void setIgnoreLeadingWhitespaces(boolean ignoreLeadingWhitespaces) {
throw new UnsupportedOperationException();
}
@Override
public void setIgnoreTrailingWhitespaces(boolean ignoreTrailingWhitespaces) {
throw new UnsupportedOperationException();
}
@Override
public void setUnicodeEscapeInterpretation(boolean interpretUnicodeEscapes) {
throw new UnsupportedOperationException();
}
@Override
public void setIgnoreEmptyLines(boolean ignoreEmptyLines) {
throw new UnsupportedOperationException();
}
@Override
public void setPrinterNewline(String newline) {
throw new UnsupportedOperationException();
}

/** Returns a mutable clone */
@Override
public Object clone() {
return new CSVStrategy(getDelimiter(), getEncapsulator(), getCommentStart(), getEscape(),
getIgnoreLeadingWhitespaces(), getIgnoreTrailingWhitespaces(),
getUnicodeEscapeInterpretation(), getIgnoreEmptyLines(),
getPrinterNewline());
}
}