From 4aa9ee153b788f1f561a07d9a62c3b0ab050242f Mon Sep 17 00:00:00 2001 From: Aditya Manthramurthy Date: Wed, 6 Feb 2019 13:25:52 -0800 Subject: [PATCH] Fix S3 Select request XML parsing (#7202) --- pkg/s3select/csv/args.go | 2 ++ pkg/s3select/select.go | 21 +++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/pkg/s3select/csv/args.go b/pkg/s3select/csv/args.go index f935b998c..33df09b28 100644 --- a/pkg/s3select/csv/args.go +++ b/pkg/s3select/csv/args.go @@ -65,6 +65,8 @@ func (args *ReaderArgs) UnmarshalXML(d *xml.Decoder, start xml.StartElement) err parsedArgs.FileHeaderInfo = strings.ToLower(parsedArgs.FileHeaderInfo) switch parsedArgs.FileHeaderInfo { + case "": + parsedArgs.FileHeaderInfo = none case none, use, ignore: default: return errInvalidFileHeaderInfo(fmt.Errorf("invalid FileHeaderInfo '%v'", parsedArgs.FileHeaderInfo)) diff --git a/pkg/s3select/select.go b/pkg/s3select/select.go index 8f6b46c04..88ad400cb 100644 --- a/pkg/s3select/select.go +++ b/pkg/s3select/select.go @@ -99,6 +99,11 @@ func (input *InputSerialization) UnmarshalXML(d *xml.Decoder, start xml.StartEle return errMalformedXML(err) } + // If no compression is specified, set to noneType + if parsedInput.CompressionType == CompressionType("") { + parsedInput.CompressionType = noneType + } + found := 0 if !parsedInput.CSVArgs.IsEmpty() { parsedInput.format = csvFormat @@ -172,10 +177,10 @@ type RequestProgress struct { } // S3Select - filters the contents on a simple structured query language (SQL) statement. It -// represents elements inside in request XML specified in detail at +// represents elements inside in request XML specified in detail at // https://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectSELECTContent.html. type S3Select struct { - XMLName xml.Name `xml:"SelectObjectContentRequest"` + XMLName xml.Name `xml:"SelectRequest"` Expression string `xml:"Expression"` ExpressionType string `xml:"ExpressionType"` Input InputSerialization `xml:"InputSerialization"` @@ -187,8 +192,20 @@ type S3Select struct { recordReader recordReader } +var ( + legacyXMLName = "SelectObjectContentRequest" +) + // UnmarshalXML - decodes XML data. func (s3Select *S3Select) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { + // S3 also supports the older SelectObjectContentRequest tag, + // though it is no longer found in documentation. This is + // checked and renamed below to allow older clients to also + // work. + if start.Name.Local == legacyXMLName { + start.Name = xml.Name{Space: "", Local: "SelectRequest"} + } + // Make subtype to avoid recursive UnmarshalXML(). type subS3Select S3Select parsedS3Select := subS3Select{}