Class Scan
To perform a scan it is neccesary to create an instance of this class with the required parameters to execute it.
The scan can be executed over the primary table or an index and it allows to read a range of rows of a table between two keys (primary key for the primary table or secondary key for an index). Also, it can perform filtering, aggregation, grouping and sorting.
The range of keys to read in the scan, the filter conditions, aggregation expressions and grouping definition are configured through an instance of ScanProperties. This is provided at the parameter "properties" of the constructor
Furthermore, you can pass a bit mask to either index and table scans to tell the server how to perform an scan. This is provided at the parameter "flags" of the constructor. Find below the possible flags to use. Note that these flags provide sorting, reverse sorting and other features:
.- KVHist Perform a histogram scan
- KVReverse Travel the table data in primary key descendant order. Otherwise, it is ascendant
- KVSort The server returns the data sorted.
- KVGetBlobs Include the blob pointer in the returned rows.
Once a scan is created, it can be executed by calling begin() and then iterate over the rows using next(). Close the scan when done with end(). To perform another scan it is neccesary to create a new instance of this class.
Find below some examples:
session = new Session();
table = new Table(session, "person");
Scan scan = table.scan();
scan.begin();
lxapi.Tuple tuple = scan.next();
int count = 0;
while (tuple != null)
{
count++;
tuple = scan.next();
}
scan.end();
session = new Session();
table = new Table(session, "person");
Scan scan = table.scan(null, (int)ScanPropFlags.KVSort|(int)ScanPropFlags.KVReverse);
lxapi.Index index = new lxapi.Index(table, idcardidx);
lxapi.Tuple min = index.tupleBuilder().add(0, 111111111Q).build(index);
ScanProperties properties = new ScanProperties(index).skRange(min, null, 0);
scan = new Scan(properties, 0);</code></pre>
Project #1, #2 and #4 fields and filter those rows whose field #9 is smaller than 70 and limit the result to the first 10 filtered rows visited:
Expression expr = Expression.fieldFloat(9).op(Expression.Op.KVLE, new Expression((double)70));
ScanProperties properties = new ScanProperties(table).addPredicate(expr).maxrows(10);
ushort[] projection = { 1, 2, 4 };
properties.project(projection)
Scan scan = new Scan(properties, 0);</code></pre>
Expression[] groupbyexprs = new Expression[2];
groupbyexprs[0] = Expression.fieldStr(3);
groupbyexprs[1] = Expression.aggr(Expression.Op.KVMAX, Expression.fieldFloat(9));
Scan scan = table.scan(new ScanProperties(table).groupBy(groupbyexprs), 0);</code></pre>
Inheritance
Implements
Inherited Members
Namespace: lxapi
Assembly: lxapi.dll
Syntax
public class Scan : IDisposable
Constructors
Scan(ScanProperties, Int32)
Create a scan that will iterate over the rows of a table according to the ScanProperties and the desired flags.
Expression expr = Expression.fieldFloat(9).op(Expression.Op.KVLE, new Expression((double)70));
ScanProperties properties = new ScanProperties(table).addPredicate(expr).maxrows(10);
Scan scan = new Scan(properties, 0);</code></pre>
Declaration
public Scan(ScanProperties properties_, int flags = 0)
Parameters
Type | Name | Description |
---|---|---|
ScanProperties | properties_ | |
System.Int32 | flags | bit mask to indicate how the server is going to iterate over the rows ScanPropFlags |
Fields
kvScan
Scan handle
Declaration
public readonly IntPtr kvScan
Field Value
Type | Description |
---|---|
System.IntPtr |
Methods
begin()
Start scan
Declaration
public int begin()
Returns
Type | Description |
---|---|
System.Int32 |
Dispose()
Dispose
Declaration
public void Dispose()
Dispose(Boolean)
End and Release Table Handle
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing |
end()
End scan
Declaration
public int end()
Returns
Type | Description |
---|---|
System.Int32 |
Finalize()
End and release scan
Declaration
protected void Finalize()
next()
Get next Tuple
Declaration
public Tuple next()
Returns
Type | Description |
---|---|
Tuple |