百度智能云

All Product Document

          Object Storage

          Execute Sql Statements of Object

          Interface Description

          This interface is used to execute the SQL statement of the specified object in the bucket, and select and return the specified content. The requester must have the read permission of the selected object. Before SelectObject, you need to ensure that the corresponding bucket and object already exist. For more information, see SelectObject Developer Documentation.

          Detailed description of the message format:

          select-msg.png

          1. There are 8 bytes in the prelude section. The first 4 bytes represent the total length of messages. The last 4 bytes represent the total length of headers, Total chunk length (prelude the value stored in the first 4bytes) - total header length - 8 bytes of prelude part - 4 bytes of crc32 = Total data length of the payload part. CRC32 represents the erasure code of the whole message.
          2. Headers contain the following custom <key,value>: “message-type”: {"Records", "Cont", "End"}, "error-code": specific error code and "error-message": "detailed error information".
          3. Payload represents the real data returned, which can be in any format. The payload of the Continuation message contains the Select progress information represented by BytesScanned and BytesReturned fields.

          Request URI

          POST /v1/{bucketName}/{objectKey}?select

          Parameter Name Parameter Type Required Description Example Value Parameter Position
          bucketName String Yes Bucket name "bucketName_example" Path
          objectKey String Yes Object name "objectKey_example" Path
          type String Yes Destination object type selected, which can be JSON/CSV currently. "type_example" Query

          Request Body Parameters

          Description of Data Structure for Request Body Field

          Parameter Name Parameter Type Required Description Example Value
          selectRequest SelectRequest Yes JSON body root node

          Description of Data Structure for SelectRequest Field

          Parameter Name Parameter Type Required Description Example Value
          expression String Yes Base64 encoded SQL statement c2VsZWN0IGNvdW50KCopIGZyb20gbxkl2JqZWN0IHdoZXJlIF80ID4gNDU=
          expressionType String Yes Query statement syntax type, which can be SQL only. SQL
          inputSerialization InputSerialization Yes Input stream node, whose child node describes the queried object format information.
          outputSerialization OutputSerialization Yes Output stream node, whose child node describes the return format information of query result.
          requestProgress RequestProgress No + requestProgress No - Select the progress information node, whose child node describes the execution progress of Select operation and returns it to the user within 3s regularly.

          Data Structure Description of InputSerialization Field

          Parameter Name Parameter Type Required Description Example Value
          compressionType String No Specify whether the queried object is compressed, whose optional value is "NONE" or "GZIP". NONE
          csv Csv No CSV node, whose child node describes the CSV file related information.

          Description of Data Structure for Csv Field

          Parameter Name Parameter Type Required Description Example Value
          fileHeaderInfo String No The optional value is NONE/IGNORE/USE, which specifies the first-line header information of the CSV file. The default NONE represents that there is no header information, and IGNORE represents that there is the header information, but it is ignored. NONE and IGNORE mean that a column can be taken out with the column serial number only. USE represents that the header information is used, and a column can be taken out with the header name only. NONE
          recordDelimiter String No Specify the newline character of the CSV file. which is Base64 encoded. The default value is \n (optional). It includes up to 2 characters, e.g., \r\n. \r\n
          fieldDelimiter String No Specify the column separator of the CSV file, which is Base64 encoded. The default value is “,” (optional). It includes up to 1 character, e.g., “;”. ;
          quoteCharacter String No Specify the quotation marks character of the CSV file, which is Base64 encoded. The newline character and column separator in quotation marks in CSV are regarded as the ordinary character. The default value is double quotation marks (") (optional). It includes up to 1 character, such as single quotation marks ('). '
          commentCharacter String No Specify the comment character of the CSV file, which is Base64 encoded. If a line starts with the comment character, it indicates that this line can be ignored. The default value is # (optional). It includes up to 2 characters, e.g., //. //

          Description of Data Structure for OutputSerialization Field

          Parameter Name Parameter Type Required? Description Example Value
          outputHeader Boolean No Output the CSV header information at the beginning of return results, which is false by default. The fileHeaderInfo field value must be “USE”. If this value is true, the corresponding CSV header name is added to the first line of each Records message in return results. The optional value is false/true. false
          csv Csv No CSV node, whose child node describes the returned CSV data related information.

          Data Structure Description of RequestProgress Field

          Parameter Name Parameter Type Required? Description Example Value
          enabled Boolean No Describe whether the progress information needs to be returned regularly, whose optional value is false/true. If the data filtration takes a long time, it may cause the timeout error 504. You can set it to “True” to maintain the HTTP connection. false

          Response Body Parameters

          Description of Data Structure for Response Body Field

          Request Example

          POST /v1/bucketName_example/objectKey_example?select&type=type_example
          Common Request Header
          
          
          {
            "selectRequest" : {
              "outputSerialization" : {
                "outputHeader" : false,
                "csv" : {
                  "quoteFields" : "ALWAYS",
                  "recordDelimiter" : "Cg==",
                  "quoteCharacter" : "Ig==",
                  "fieldDelimiter" : "LA=="
                }
              },
              "expression" : "c2VsZWN0IGNvdW50KCopIGZyb20gbxkl2JqZWN0IHdoZXJlIF80ID4gNDU=",
              "expressionType" : "SQL",
              "requestProgress" : {
                "enabled" : false
              },
              "inputSerialization" : {
                "csv" : {
                  "fileHeaderInfo" : "NONE",
                  "recordDelimiter" : "\\r\\n",
                  "quoteCharacter" : "'",
                  "fieldDelimiter" : ";",
                  "commentCharacter" : "//"
                },
                "compressionType" : "NONE"
              }
            }
          }

          Response Example

          HTTP/1.1 200 OK
          <Common response header>
          
          { }

          Error Code

          Refer to the universal error code.

          Previous
          Access Control
          Next
          Soft Link