From a1c7c9ea73d7cb563156f4a6278d4ac66b9fe34c Mon Sep 17 00:00:00 2001 From: ebozduman Date: Thu, 5 Mar 2020 19:34:04 -0800 Subject: [PATCH] Matches s3 invalid compression format error for 'mc sql' (#9067) --- pkg/s3select/errors.go | 18 ++++++++++++++++++ pkg/s3select/progress.go | 5 ++++- pkg/s3select/select.go | 7 ++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/pkg/s3select/errors.go b/pkg/s3select/errors.go index 3cd12d4f0..feb1d17cc 100644 --- a/pkg/s3select/errors.go +++ b/pkg/s3select/errors.go @@ -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", diff --git a/pkg/s3select/progress.go b/pkg/s3select/progress.go index 2e926063e..00d9afd4a 100644 --- a/pkg/s3select/progress.go +++ b/pkg/s3select/progress.go @@ -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: diff --git a/pkg/s3select/select.go b/pkg/s3select/select.go index a158394ae..4ddc47f1a 100644 --- a/pkg/s3select/select.go +++ b/pkg/s3select/select.go @@ -19,7 +19,9 @@ package s3select import ( "bufio" "bytes" + "compress/bzip2" "encoding/xml" + "errors" "fmt" "io" "io/ioutil" @@ -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)