static async Task <ISelectObjectContentEventStream> GetSelectObjectContentEventStream(string fileName, string sqlStr) { //Select Object 設定 SelectObjectContentRequest selectObject = new SelectObjectContentRequest() { Bucket = bucketName, //儲存貯體名稱 Key = fileName, //讀取檔案名稱 ExpressionType = ExpressionType.SQL, //Tyep為SQL Expression = sqlStr, //SQL語法 InputSerialization = new InputSerialization() //讀取檔案的格式 { CSV = new CSVInput() { FileHeaderInfo = FileHeaderInfo.Use } }, OutputSerialization = new OutputSerialization() //輸出格式 { CSV = new CSVOutput() { QuoteFields = QuoteFields.Always, FieldDelimiter = "," } } }; //取得Select Object 結果 var response = await clientS3.SelectObjectContentAsync(selectObject); //回傳封包 return(response.Payload); }
private ISelectObjectContentEventStream GetSelectObjectContentEventStream( string bucketName, string key, string selectQuery, InputSerialization inputSerialization, OutputSerialization outputSerialization, ScanRange scanRange = null) { if (string.IsNullOrWhiteSpace(bucketName)) { throw new ArgumentNullException("bucketName"); } if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException("key"); } if (string.IsNullOrWhiteSpace(selectQuery)) { throw new ArgumentNullException("selectQuery"); } if (inputSerialization == null) { throw new ArgumentNullException("inputSerialization"); } if (outputSerialization == null) { throw new ArgumentNullException("outputSerialization"); } SelectObjectContentRequest selectObjectContentRequest = new SelectObjectContentRequest() { Bucket = bucketName, Key = key, ExpressionType = ExpressionType.SQL, Expression = selectQuery, InputSerialization = inputSerialization, OutputSerialization = outputSerialization }; if (scanRange != null) { selectObjectContentRequest.ScanRange = scanRange; } return(Client.SelectObjectContent(selectObjectContentRequest).Payload); }
private async Task <ISelectObjectContentEventStream> SelectAsync(Query query, string bucketName, string objectKey) { var request = new SelectObjectContentRequest { Bucket = bucketName, Key = objectKey, Expression = query.ToString(), ExpressionType = ExpressionType.SQL, InputSerialization = _inputSerialization, OutputSerialization = new OutputSerialization { JSON = new JSONOutput() }, }; var response = await _s3.SelectObjectContentAsync(request).ConfigureAwait(false); return(response.Payload); }
public void SelectObjectContentTest() { var accessPointArn = "arn:aws:s3:us-east-1:000011112222:accesspoint/testpoint"; var request = new SelectObjectContentRequest { Bucket = accessPointArn, Key = "foo.txt", Expression = "crazy expression", ExpressionType = ExpressionType.SQL, InputSerialization = new InputSerialization { }, OutputSerialization = new OutputSerialization { } }; var internalRequest = S3ArnTestUtils.RunMockRequest(request, SelectObjectContentRequestMarshaller.Instance); Assert.AreEqual(new Uri("https://testpoint-000011112222.s3-accesspoint.us-east-1.amazonaws.com"), internalRequest.Endpoint); Assert.AreEqual("/foo.txt", internalRequest.ResourcePath); }
public Task <SelectObjectContentResponse> SelectObjectContentAsync(SelectObjectContentRequest request, CancellationToken cancellationToken = default) { throw new NotImplementedException(); }
public IRequest Marshall(SelectObjectContentRequest selectObjectContentRequest) { // Required Parameters // Bucket if (string.IsNullOrEmpty(selectObjectContentRequest.Bucket)) { throw ConstructExceptionArgumentRequired(nameof(selectObjectContentRequest.Bucket)); } // Key if (string.IsNullOrEmpty(selectObjectContentRequest.Key)) { throw ConstructExceptionArgumentRequired(nameof(selectObjectContentRequest.Key)); } // Expression if (string.IsNullOrEmpty(selectObjectContentRequest.Expression)) { throw ConstructExceptionArgumentRequired(nameof(selectObjectContentRequest.Expression)); } // ExpressionType if (!selectObjectContentRequest.IsSetExpressionType()) { throw ConstructExceptionArgumentRequired(nameof(selectObjectContentRequest.ExpressionType)); } // InputSerialization if (!selectObjectContentRequest.IsSetInputSerialization()) { throw ConstructExceptionArgumentRequired(nameof(selectObjectContentRequest.InputSerialization)); } // OutputSerialization if (!selectObjectContentRequest.IsSetOutputSerialization()) { throw ConstructExceptionArgumentRequired(nameof(selectObjectContentRequest.OutputSerialization)); } var request = new DefaultRequest(selectObjectContentRequest, "AmazonS3") { HttpMethod = "POST", ResourcePath = string.Format(CultureInfo.InvariantCulture, "/{0}/{1}", S3Transforms.ToStringValue(selectObjectContentRequest.Bucket), S3Transforms.ToStringValue(selectObjectContentRequest.Key)), UseQueryString = true, }; // Headers if (selectObjectContentRequest.IsSetServerSideCustomerEncryptionMethod()) { request.Headers.Add(HeaderKeys.XAmzSSECustomerAlgorithmHeader, selectObjectContentRequest.ServerSideCustomerEncryptionMethod); } if (selectObjectContentRequest.IsSetServerSideEncryptionCustomerProvidedKey()) { request.Headers.Add(HeaderKeys.XAmzSSECustomerKeyHeader, selectObjectContentRequest.ServerSideEncryptionCustomerProvidedKey); if (selectObjectContentRequest.IsSetServerSideEncryptionCustomerProvidedKeyMD5()) { request.Headers.Add(HeaderKeys.XAmzSSECustomerKeyMD5Header, selectObjectContentRequest.ServerSideEncryptionCustomerProvidedKeyMD5); } else { request.Headers.Add(HeaderKeys.XAmzSSECustomerKeyMD5Header, AmazonS3Util.ComputeEncodedMD5FromEncodedString(selectObjectContentRequest .ServerSideEncryptionCustomerProvidedKey)); } } if (selectObjectContentRequest.IsSetExpectedBucketOwner()) { request.Headers.Add(S3Constants.AmzHeaderExpectedBucketOwner, S3Transforms.ToStringValue(selectObjectContentRequest.ExpectedBucketOwner)); } // Subresources request.AddSubResource("select"); request.AddSubResource("select-type", "2"); // Parameters using (var stringWriter = new StringWriter(CultureInfo.InvariantCulture)) { var xmlWriterSettings = new XmlWriterSettings() { Encoding = Encoding.UTF8, OmitXmlDeclaration = true, NewLineHandling = NewLineHandling.None }; using (var xmlWriter = XmlWriter.Create(stringWriter, xmlWriterSettings)) { xmlWriter.WriteStartElement("SelectRequest"); xmlWriter.WriteElementString("Expression", S3Transforms.ToXmlStringValue(selectObjectContentRequest.Expression)); xmlWriter.WriteElementString("ExpressionType", S3Transforms.ToXmlStringValue(selectObjectContentRequest.ExpressionType.Value)); selectObjectContentRequest.InputSerialization.Marshall("InputSerialization", xmlWriter); selectObjectContentRequest.OutputSerialization.Marshall("OutputSerialization", xmlWriter); xmlWriter.WriteStartElement("RequestProgress"); xmlWriter.WriteElementString("Enabled", selectObjectContentRequest.RequestProgress.GetValueOrDefault(false).ToString() .ToUpperInvariant()); if (selectObjectContentRequest.IsSetScanRange()) { selectObjectContentRequest.ScanRange.Marshall("ScanRange", xmlWriter); } xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); } try { var content = stringWriter.ToString(); request.Content = Encoding.UTF8.GetBytes(content); request.Headers[HeaderKeys.ContentTypeHeader] = "application/xml"; var checksum = AWSSDKUtils.GenerateChecksumForContent(content, true); request.Headers[HeaderKeys.ContentMD5Header] = checksum; } catch (EncoderFallbackException e) { throw new AmazonServiceException("Unable to marshall request to XML", e); } } return(request); }