Skip to content

Commit

Permalink
Matches s3 invalid compression format error for 'mc sql' (minio#9067)
Browse files Browse the repository at this point in the history
  • Loading branch information
ebozduman authored Mar 6, 2020
1 parent 7f19a9a commit a1c7c9e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
18 changes: 18 additions & 0 deletions pkg/s3select/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,24 @@ func errInvalidCompressionFormat(err error) *s3Error {
}
}

func errInvalidBZIP2CompressionFormat(err error) *s3Error {
return &s3Error{
code: "InvalidCompressionFormat",
message: "BZIP2 is not applicable to the queried object. Please correct the request and try again.",
statusCode: 400,
cause: err,
}
}

func errInvalidGZIPCompressionFormat(err error) *s3Error {
return &s3Error{
code: "InvalidCompressionFormat",
message: "GZIP is not applicable to the queried object. Please correct the request and try again.",
statusCode: 400,
cause: err,
}
}

func errInvalidDataSource(err error) *s3Error {
return &s3Error{
code: "InvalidDataSource",
Expand Down
5 changes: 4 additions & 1 deletion pkg/s3select/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,11 @@ func newProgressReader(rc io.ReadCloser, compType CompressionType) (*progressRea
r = scannedReader
case gzipType:
if r, err = gzip.NewReader(scannedReader); err != nil {
return nil, errTruncatedInput(err)
if errors.Is(err, gzip.ErrHeader) || errors.Is(err, gzip.ErrChecksum) {
return nil, errInvalidGZIPCompressionFormat(err)
}
}
return nil, errTruncatedInput(err)
case bzip2Type:
r = bzip2.NewReader(scannedReader)
default:
Expand Down
7 changes: 6 additions & 1 deletion pkg/s3select/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ package s3select
import (
"bufio"
"bytes"
"compress/bzip2"
"encoding/xml"
"errors"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -302,9 +304,12 @@ func (s3Select *S3Select) Open(getReader func(offset, length int64) (io.ReadClos
s3Select.recordReader, err = csv.NewReader(s3Select.progressReader, &s3Select.Input.CSVArgs)
if err != nil {
rc.Close()
var stErr bzip2.StructuralError
if errors.As(err, &stErr) {
return errInvalidBZIP2CompressionFormat(err)
}
return err
}

return nil
case jsonFormat:
rc, err := getReader(0, -1)
Expand Down

0 comments on commit a1c7c9e

Please sign in to comment.