S3 Select具有FileHeaderInfo.Use
选项以在查询中使用标题。但是,如果使用该选项,则会从结果内容中删除标题。
在使用FileHeaderInfo.Use选项时,是否还有一种方法可以在结果中获取标头?或者,我需要提出2个请求
FileHeaderInfo.None
(Select * from S3Object s LIMIT 1
)的标题FileHeaderInfo.Use
(Select * from S3Object s Where created_date = '12152019' LIMIT 100
)
using (IAmazonS3 client = new AmazonS3Client(awsAccessKey, awsSecretKey, RegionEndpoint.USEast1))
{
var response = await client.SelectObjectContentAsync(new SelectObjectContentRequest()
{
Bucket = "s3-bucket",
Key = "s3-select-test/test1.txt.gz",
ExpressionType = Amazon.S3.ExpressionType.SQL,
Expression = "Select * from S3Object s Where created_date = '12152019' LIMIT 100",
InputSerialization = new InputSerialization()
{
CompressionType = CompressionType.Gzip,
CSV = new CSVInput()
{
FileHeaderInfo = FileHeaderInfo.Use,
}
},
OutputSerialization = new OutputSerialization()
{
CSV = new CSVOutput()
{
QuoteFields = QuoteFields.Always
}
}
});
foreach (var line in response.Payload)
{
if (line is RecordsEvent records)
{
using (var reader = new StreamReader(records.Payload, Encoding.UTF8))
{
Console.WriteLine(reader.ReadToEnd());
}
}
}
}