All Products
Search
Document Center

Object Storage Service:select-object

Last Updated:Sep 26, 2024

The select-object command is used to execute SQL statements on objects and query the results of execution.

Usage notes

By default, an Alibaba Cloud account has the permissions to perform operations on objects. Performing operations as a RAM user or by using Security Token Service (STS) requires oss:GetObject permission. For more information, see Attach a custom policy to a RAM user.

Command syntax

ossutil api select-object --bucket value --key value --select-request value [flags]

Parameter

Type

Description

--bucket

string

Name of the bucket.

--key

string

Full path of the object.

--select-request

string

Container that stores SelectObject requests.

Note

The select-object command corresponds to the SelectObject operation. For more information about the parameters in the SelectObject operation, see SelectObject.

--select-request

The --select-request configuration option supports both XML and JSON formats. If the value of the option contains the 'file://' prefix, configuration parameters are read from the specified file.

  • XML format:

    <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 format:

    {
      "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
      }
    }
Note

For supported global command line options, see Supported global command line options.

Examples

  • Execute SQL statements on exampleobject in examplebucket. This operation supports the request syntax for CSV objects.

    • Create a configuration file named select-request.xml and add the following code:

      <?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>

      Sample command:

      ossutil api select-object --bucket examplebucket --key exampleobject --select-request file://select-request.xml
    • Create a configuration file named select-request.json and add the following code:

      {
        "Expression": "c2VsZWN0IFllYXIsU3RhdGVBYmJyLCBDaXR5TmFtZSwgU2hvcnRfUXVlc3Rpb25fVGV4dCBmcm9tIG9zc29iamVjdA==",
        "InputSerialization": {
          "CSV": {
            "FileHeaderInfo": "Use",
            "Range": "line-range=0-100"
          }
        },
        "OutputSerialization": {
          "JSON": {
            "RecordDelimiter": ","
          }
        }
      }

      Sample command:

      ossutil api select-object --bucket examplebucket --key exampleobject --select-request file://select-request.json
    • Configure parameters in the following command in the JSON format:

      ossutil api select-object --bucket examplebucket --key exampleobject --select-request "{\"Expression\":\"c2VsZWN0IFllYXIsU3RhdGVBYmJyLCBDaXR5TmFtZSwgU2hvcnRfUXVlc3Rpb25fVGV4dCBmcm9tIG9zc29iamVjdA==\",\"InputSerialization\":{\"CSV\":{\"FileHeaderInfo\":\"Use\",\"Range\":\"line-range=0-100\"}},\"OutputSerialization\":{\"JSON\":{\"RecordDelimiter\":\",\"}}}"
  • Execute SQL statements on exampleobject in examplebucket. This operation supports the request syntax for JSON objects.

    • Create a configuration file named select-request.xml and add the following code:

      <?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>

      Sample command:

      ossutil api select-object --bucket examplebucket --key exampleobject --select-request file://select-request.xml
    • Create a configuration file named select-request.json and add the following code:

      {
        "Expression": "c2VsZWN0ICogZnJvbSBvc3NvYmplY3Qub2JqZWN0c1sqXSB3aGVyZSBwYXJ0eSA9ICdEZW1vY3JhdCc=",
        "InputSerialization": {
          "CSV": {},
          "JSON": {
            "Type": "DOCUMENT"
          }
        },
        "OutputSerialization": {
          "JSON": {
            "RecordDelimiter": "LA=="
          }
        }
      }

      Sample command:

      ossutil api select-object --bucket examplebucket --key exampleobject --select-request file://select-request.xml
    • Configure parameters in the following command in the JSON format:

      ossutil api select-object --bucket examplebucket --key exampleobject --select-request "{\"Expression\":\"c2VsZWN0IFllYXIsU3RhdGVBYmJyLCBDaXR5TmFtZSwgU2hvcnRfUXVlc3Rpb25fVGV4dCBmcm9tIG9zc29iamVjdA==\",\"InputSerialization\":{\"CSV\":{\"FileHeaderInfo\":\"Use\",\"Range\":\"line-range=0-100\"}},\"OutputSerialization\":{\"JSON\":{\"RecordDelimiter\":\",\"}}}"