Scan Records

ScanResult scan(ScanRequest request)

Function

Scanning operation, where each scanned record consumes 1 read quota (even if the filter conditions are not met), each Lazy secondary index requires 1 additional read quota

Method parameters

request : ScanRequest : required

ScanRequest includes the following sections

1.tableName : String : required

Specifies a scanned table name

2.indexName :String : optional

Specifies the secondary index name for the scan. If not specified, the master record is scanned

3.startKey : Map< String, Datum > :optional

The start of the query scope contains a startKey. If the startKey is not a complete key but the prefix part of the key, the startKey of the actual query is the {startKey, the smallest possible suffix} complementary form

4.stopKey : Map< String, Datum > :optional

The start of the query scope contains a stopKey. If the stopKey is not a complete key but the prefix part of the key, the stopKey of the actual query is the {stopKey, the biggest possible suffix} complementary form

5.attributes : List< String > :optional

The list of attributes that need to be returned, without specifying that all attributes are returned

6.condition : String : optional

SQL WHERE statement query condition. Note: Unlike SQL, this condition is only used as a filter condition and does not affect the specific query plan (index, startKey, endKey). To perform a range query, you need to display the setting index, startKey, and endKey. Each scanned record counts towards the read quota even if the query conditions are not met. Try to avoid the use of conditional filtering, especially when the filtered records account for more than half of the time, it is strongly not recommended for use.

7.limit :int : optinal

Returns the maximum number of records, the number of returns may be less than this value (such as when the table's read quota is exceeded), the default is 10, range is (0, 1000]

8.reverse : boolean : optional

If the reverse scan is performed, the startKey should be greater than endKey

Note: The reverse order query has low efficiency and is used with caution. It is recommended to set the corresponding Key to reverse storage

9.inGlobalOrder :boolean :optional

Whether a globally ordered scan or not, for a table with entity group keys and hash enabled, you need to set the value to true to ensure that the results are in order

10.action :ScanAction : optional

Associated operation during scan, including COUNT, DELETE and UPDATE, SQL-like select count(*) / update XXX / delete XXX from table where XXX is the semantics

Method return value

scanResult : ScanResult

scanResult includes the following

1.records : List< Map< String,Datum > >

Scanned records

2.nextStartKey : Map< String,Datum >

The next record primary key that needs to be scanned, NULL indicates that the final position is reached

Exception error code

INTERNAL_ERROR(1): Server exception

ACCESS_DENIED(4): User does not have read permission for this table

VALIDATION_FAILED(5): Parameter setting error

THROUGHPUT_EXCEED(8): The current read/write speed has exceeded the read/write quota for this table

RESOURCE_NOT_FOUND(9): Specified table does not exist

Limitation

The range of limit values is (0, 1000]

Warning

You can choose to use the primary key (indexName does not specify expressing query through the primary key) and the secondary index query. The scan can specify the query range. When not specified, it indicates a full table scan. The range defined by the query scope is [startKey, stopKey), That is, if both attributes are specified and the same, the scope of the query is null. Among them, startKey and stopKey can only specify the primary key or partial attribute of the corresponding index (must be the prefix). When specifying the prefix, the query range is [startKey prefix + suffix's possible minimum value, stopKey prefix + suffix's possible maximum value + 1). For example, startKey = {userId = "user1"}, stopKey = {userId = "user1"} means query all notes under user1

The scan operation can also specify filter conditions. Note that the records filtered by the conditions also compute the read quota (1 or 2 read quotas based on the index type). The syntax of the filter condition is similar to the SQL Where statement. It should be noted that the absence of the attribute indicates that the value is null, All other expressions and function invocation results except for the isnull and notnull operators are null. If the final value of the expression is null, the expression evaluates to false.

If a hash distribution is defined, scanning across entity groups needs to first determine the range distribution in each hash bucket, perform local scan for each hash bucket, and finally merge and sort all the in-bucket scan results. Therefore, it will introduce a large performance overhead and it is recommended to use it with caution. Note: This scenario suggests that users use the Structured Database Storage MapReduce API MapReduce distributed computing framework to distribute the above steps Perform parallel execution on multiple machines to greatly improve scan performance.

Example

With the Example table, the sample code for scanning record is provided below

$scan = new ScanRequest(array(
  "tableName" => $tableName,
  "indexName" => "mtime",
  "startKey" => array(
    "userId" => DatumUtil::datum("user1"),
  ),
  "stopKey" => array(
    "userId" => DatumUtil::datum("user1"),
  ),
  "condition" => "title REGEXP '.*[0-5]' AND noteId > 5",
  "attributes" => array("noteId", "title", "mtime"),
  "limit" => 50 // the maximum record count every time rpc returns
));

$scanner = new TableScanner($tableClient, $scan);

foreach ($scanner->iterator() as $k => $v) {
  echo "$k: " . DatumUtil::value($v['noteId'])
    . " [" . DatumUtil::value($v['title']) . "] "
    . DatumUtil::value($v['mtime']) . "\n";
}

results matching ""

    No results matching ""