Skip to content

Fix issue in setSchema() #481

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

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -498,14 +498,13 @@ public void setCodec(ObjectCodec c) {
}

@Override
public void setSchema(FormatSchema schema)
public void setSchema(final FormatSchema schema)
{
if (schema instanceof CsvSchema) {
_schema = (CsvSchema) schema;
String str = _schema.getNullValueString();
_nullValue = str;
_nullValue = _schema.getNullValueString();
} else if (schema == null) {
schema = EMPTY_SCHEMA;
_schema = EMPTY_SCHEMA;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like a bug to me - the old code was updating the input param (schema) instead of the _schema.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I concur this is a bug. I think I'll backport this in 2.17 as well.

} else {
super.setSchema(schema);
}
Expand Down Expand Up @@ -924,7 +923,7 @@ protected void _readHeaderLine() throws IOException {
int newColumnCount = newSchema.size();
if (newColumnCount < 2) { // 1 just because we may get 'empty' header name
String first = (newColumnCount == 0) ? "" : newSchema.columnName(0).trim();
if (first.length() == 0) {
if (first.isEmpty()) {
_reportCsvMappingError("Empty header line: can not bind data");
}
}
Expand Down Expand Up @@ -1468,9 +1467,6 @@ protected boolean _isNullValue(String value) {
if (_cfgEmptyStringAsNull && value.isEmpty()) {
return true;
}
if (_cfgEmptyUnquotedStringAsNull && value.isEmpty() && !_reader.isCurrentTokenQuoted()) {
return true;
}
return false;
return _cfgEmptyUnquotedStringAsNull && value.isEmpty() && !_reader.isCurrentTokenQuoted();
}
}