drill icon indicating copy to clipboard operation
drill copied to clipboard

SAS format plugin. Select fails if the first row contains null values

Open pseudomo opened this issue 4 years ago • 7 comments

Select from dfs.path_to_sas_file fails with error "Cannot invoke "Object.getClass()" because "this.firstRow[counter]" is null" if the first row of sas file contains null values.

Can be reproduced with any sas file that contain null values in the first row. Apparently, the problem is here: drill\contrib\format-sas\src\main\java\org\apache\drill\exec\store\sas\SasBatchReader.java

private TupleMetadata buildSchema() {
    SchemaBuilder builder = new SchemaBuilder();
    List<Column> columns = sasFileReader.getColumns();
    int counter = 0;
    for (Column column : columns) {
      String fieldName = column.getName();
      try {
        MinorType type = getType(**firstRow[counter].getClass()**.getSimpleName());
        if (type == MinorType.BIGINT && !column.getFormat().isEmpty()) {
          logger.debug("Found possible time");
          type = MinorType.TIME;
        }
        builder.addNullable(fieldName, type);
      } catch (Exception e) {
        throw UserException.dataReadError()
          .message("Error with column type: " + firstRow[counter].getClass().getSimpleName())
          .addContext(errorContext)
          .build(logger);
      }
      counter++;
    }

    return builder.buildSchema();
  }

image

pseudomo avatar Feb 17 '22 21:02 pseudomo

@pseudomo Thanks for posting. Could you share a file with null values in the first row so that we can test a fix?

cgivre avatar Feb 17 '22 21:02 cgivre

@pseudomo Thanks for posting. Could you share a file with null values in the first row so that we can test a fix?

Unfortunately, I can't share the file here since it contains sensitive information and I don't know how to create one for testing.

pseudomo avatar Feb 17 '22 21:02 pseudomo

@pseudomo I'm going to fix this, but we're in the middle of a release cycle right now and I'm not sure if we can get it into the next release. If we can't get it into Drill 1.20, we'll do a 1.20.1 in the next few months with a bunch of other bug fixes. However there may be a slightly ugly workaround which would at least let you read the data. If you provide the schema, Drill should be able to read the file. You can do this either with a CREATE SCHEMA query, or by providing the schema inline. 1 That can be done as follows:

SELECT * 
FROM table(dfs.tmp.`somefile.sas7dat`(
schema => 'inline=(col1 int, col2 varchar, col3 float8)
))

cgivre avatar Feb 18 '22 02:02 cgivre

@cgivre, Many thanks! It will work for me since I build Drill from source.

pseudomo avatar Feb 18 '22 07:02 pseudomo

@pseudomo I submitted a fix. Could you please try this out with your data?

cgivre avatar Feb 18 '22 14:02 cgivre

@pseudomo I submitted a fix. Could you please try this out with your data?

Thanks for fixing the issue ! I can now query my file with Drill. I got some more real world SAS files to work with and faced new issues. I will report those issues as soon as I get a chance.

pseudomo avatar Feb 20 '22 22:02 pseudomo

@pseudomo I submitted a fix. Could you please try this out with your data?

Thanks for fixing the issue ! I can now query my file with Drill. I got some more real world SAS files to work with and faced new issues. I will report those issues as soon as I get a chance.

Oh no! Well, I'm glad we got that one working at least. I don't have a way to generate test data, so it was very hard to test this plugin. Please send that privately, and I'll work up fixes.

cgivre avatar Feb 20 '22 23:02 cgivre