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 { func errInvalidDataSource(err error) *s3Error {
return &s3Error{ return &s3Error{
code: "InvalidDataSource", code: "InvalidDataSource",

@ -101,8 +101,11 @@ func newProgressReader(rc io.ReadCloser, compType CompressionType) (*progressRea
r = scannedReader r = scannedReader
case gzipType: case gzipType:
if r, err = gzip.NewReader(scannedReader); err != nil { 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: case bzip2Type:
r = bzip2.NewReader(scannedReader) r = bzip2.NewReader(scannedReader)
default: default:

@ -19,7 +19,9 @@ package s3select
import ( import (
"bufio" "bufio"
"bytes" "bytes"
"compress/bzip2"
"encoding/xml" "encoding/xml"
"errors"
"fmt" "fmt"
"io" "io"
"io/ioutil" "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) s3Select.recordReader, err = csv.NewReader(s3Select.progressReader, &s3Select.Input.CSVArgs)
if err != nil { if err != nil {
rc.Close() rc.Close()
var stErr bzip2.StructuralError
if errors.As(err, &stErr) {
return errInvalidBZIP2CompressionFormat(err)
}
return err return err
} }
return nil return nil
case jsonFormat: case jsonFormat:
rc, err := getReader(0, -1) rc, err := getReader(0, -1)

Loading…
Cancel
Save