Matches s3 invalid compression format error for 'mc sql' (#9067)

master
ebozduman 5 years ago committed by GitHub
parent 7f19a9a617
commit a1c7c9ea73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      pkg/s3select/errors.go
  2. 5
      pkg/s3select/progress.go
  3. 7
      pkg/s3select/select.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",

@ -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:

@ -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)

Loading…
Cancel
Save