select-object用于对目标文件执行SQL语句,返回执行结果。
注意事项
阿里云账号默认拥有对目标对象操作的权限。如果您需要通过RAM用户或者STS的方式进行操作,您必须拥有oss:GetObject
权限。具体操作,请参见为RAM用户授权自定义的权限策略。
命令格式
ossutil api select-object --bucket value --key value --select-request value [flags]
参数 | 类型 | 说明 |
--bucket | string | Bucket名称。 |
--key | string | Object的完整路径。 |
--select-request | string | 保存SelectObject请求的容器。 |
说明
select-object命令对应API接口SelectObject。关于API中的具体参数含义,请参见SelectObject。
--select-request
--select-request配置选项既支持XML语法也支持JSON语法,当选项值包含file://前缀时,表示从文件中读取配置。
XML语法:
<SelectRequest> <Expression>string</Expression> <InputSerialization> <CompressionType>string</CompressionType> <CSV> <Range>string</Range> <AllowQuotedRecordDelimiter>boolean</AllowQuotedRecordDelimiter> <FileHeaderInfo>string</FileHeaderInfo> <RecordDelimiter>string</RecordDelimiter> <FieldDelimiter>string</FieldDelimiter> <QuoteCharacter>string</QuoteCharacter> <CommentCharacter>string</CommentCharacter> </CSV> <JSON> <Range>string</Range> <ParseJsonNumberAsString>boolean</ParseJsonNumberAsString> <Type>string</Type> </JSON> </InputSerialization> <OutputSerialization> <CSV> <RecordDelimiter>string</RecordDelimiter> <FieldDelimiter>string</FieldDelimiter> </CSV> <JSON> <RecordDelimiter>string</RecordDelimiter> </JSON> <KeepAllColumns>boolean</KeepAllColumns> <OutputHeader>boolean</OutputHeader> <OutputRawData>boolean</OutputRawData> <EnablePayloadCrc>boolean</EnablePayloadCrc> </OutputSerialization> <Options> <MaxSkippedRecordsAllowed>integer</MaxSkippedRecordsAllowed> <SkipPartialDataRecord>boolean</SkipPartialDataRecord> </Options> </SelectRequest>
JSON语法:
{ "Options": { "SkipPartialDataRecord": boolean, "MaxSkippedRecordsAllowed": integer }, "Expression": "string", "InputSerialization": { "CompressionType": "string", "CSV": { "FileHeaderInfo": "string", "RecordDelimiter": "string", "FieldDelimiter": "string", "QuoteCharacter": "string", "CommentCharacter": "string", "Range": "string", "AllowQuotedRecordDelimiter": boolean }, "JSON": { "Range": "string", "ParseJsonNumberAsString": boolean, "Type": "string" } }, "OutputSerialization": { "CSV": { "RecordDelimiter": "string", "FieldDelimiter": "string" }, "JSON": { "RecordDelimiter": "string" }, "KeepAllColumns": boolean, "OutputHeader": boolean, "OutputRawData": boolean, "EnablePayloadCrc": boolean } }
说明
关于支持的全局命令行选项,请参见支持的全局命令行选项。
使用示例
为存储空间
examplebucket
中的exampleobject执行SQL语句,请求语法 CSV。使用XML配置文件,select-request.xml内容如下:
<?xml version="1.0" encoding="UTF-8"?> <SelectRequest> <Expression>c2VsZWN0IFllYXIsU3RhdGVBYmJyLCBDaXR5TmFtZSwgU2hvcnRfUXVlc3Rpb25fVGV4dCBmcm9tIG9zc29iamVjdA==</Expression> <InputSerialization> <CSV> <FileHeaderInfo>Use</FileHeaderInfo> <Range>line-range=0-100</Range> </CSV> </InputSerialization> <OutputSerialization> <JSON> <RecordDelimiter>,</RecordDelimiter> </JSON> </OutputSerialization> </SelectRequest>
命令示例如下:
ossutil api select-object --bucket examplebucket --key exampleobject --select-request file://select-request.xml
使用JSON配置文件,select-request.json 内容如下:
{ "Expression": "c2VsZWN0IFllYXIsU3RhdGVBYmJyLCBDaXR5TmFtZSwgU2hvcnRfUXVlc3Rpb25fVGV4dCBmcm9tIG9zc29iamVjdA==", "InputSerialization": { "CSV": { "FileHeaderInfo": "Use", "Range": "line-range=0-100" } }, "OutputSerialization": { "JSON": { "RecordDelimiter": "," } } }
命令示例如下:
ossutil api select-object --bucket examplebucket --key exampleobject --select-request file://select-request.json
使用JSON配置参数,命令示例如下:
ossutil api select-object --bucket examplebucket --key exampleobject --select-request "{\"Expression\":\"c2VsZWN0IFllYXIsU3RhdGVBYmJyLCBDaXR5TmFtZSwgU2hvcnRfUXVlc3Rpb25fVGV4dCBmcm9tIG9zc29iamVjdA==\",\"InputSerialization\":{\"CSV\":{\"FileHeaderInfo\":\"Use\",\"Range\":\"line-range=0-100\"}},\"OutputSerialization\":{\"JSON\":{\"RecordDelimiter\":\",\"}}}"
为存储空间
examplebucket
中的exampleobject执行SQL语句,请求语法 JSON。使用XML配置文件,select-request.xml内容如下:
<?xml version="1.0" encoding="UTF-8"?> <SelectRequest> <Expression>c2VsZWN0ICogZnJvbSBvc3NvYmplY3Qub2JqZWN0c1sqXSB3aGVyZSBwYXJ0eSA9ICdEZW1vY3JhdCc=</Expression> <InputSerialization> <CSV> <SplitRange></SplitRange> </CSV> <JSON> <Type>DOCUMENT</Type> <SplitRange></SplitRange> </JSON> </InputSerialization> <OutputSerialization> <CSV></CSV> <JSON> <RecordDelimiter>LA==</RecordDelimiter> </JSON> </OutputSerialization> <Options></Options> </SelectRequest>
命令示例如下:
ossutil api select-object --bucket examplebucket --key exampleobject --select-request file://select-request.xml
使用JSON配置文件,select-request.json 内容如下:
{ "Expression": "c2VsZWN0ICogZnJvbSBvc3NvYmplY3Qub2JqZWN0c1sqXSB3aGVyZSBwYXJ0eSA9ICdEZW1vY3JhdCc=", "InputSerialization": { "CSV": {}, "JSON": { "Type": "DOCUMENT" } }, "OutputSerialization": { "JSON": { "RecordDelimiter": "LA==" } } }
命令示例如下:
ossutil api select-object --bucket examplebucket --key exampleobject --select-request file://select-request.xml
使用JSON配置参数,命令示例如下:
ossutil api select-object --bucket examplebucket --key exampleobject --select-request "{\"Expression\":\"c2VsZWN0IFllYXIsU3RhdGVBYmJyLCBDaXR5TmFtZSwgU2hvcnRfUXVlc3Rpb25fVGV4dCBmcm9tIG9zc29iamVjdA==\",\"InputSerialization\":{\"CSV\":{\"FileHeaderInfo\":\"Use\",\"Range\":\"line-range=0-100\"}},\"OutputSerialization\":{\"JSON\":{\"RecordDelimiter\":\",\"}}}"
文档内容是否对您有帮助?