Class Table
Wrap a Table Handle.
A table object is mainly used to modify database's data massively. This class supports inserts, upserts, delta upserts, conditional upserts, updates and deletes.
A table object can be also used to retrieve data from the database directly from a row's key
Further, it allows perform a scan Scan over a primary table.
It also holds the Table Info in order to retrieve some valuable information from it TableInfo
To create an Table instance, it is neccesary to provide the session in which it will be used, at the paremeter "session", and its name at the parameter "tname". Note that the Table's Handle and other objects using it will belong to the specified session
Once having a Table Instance, it is possible to modify database's data by calling insert(Tuple), upsert(Tuple), update(Tuple) and delete(Tuple). Note that for deleting a tuple, a key Tuple is needed.
As mentioned before, delta and conditional upserts can be performed with a Table object. To upsert a delta, it is necessary to build a delta tuple first buildDelta(Table). Use addUpsertDefition(Expression[]) for conditionals upsert before invoking the upsert method.
A table instance allows also to create a Scan object by calling fullScan(Int32) in order to perform an scan. It is also possible to create a Scan by creating first an ScanPorperties object ScanProperties and then an Scan from it
In addition, it is possible to retrieve a row directly from its key by invoking get(Tuple), get(Tuple, ScanProperties), gets(Tuple[]) and gets(Tuple[], ScanProperties). Note that it is also possible to filter the Tuple on the before the server returns it
Inheritance
Implements
Inherited Members
Namespace: lxapi
Assembly: lxapi.dll
Syntax
public class Table : IDisposable
Examples
// tag::insert[] session = new Session(); Table table = new Table(session, tablename);
int jimbirthday = (int)(new DateTimeOffset(new DateTime(2010, 12, 12)).ToUnixTimeSeconds() / 86400); object[] jimrow = { 0, null, "Jim", "Doe", "No comments", "Mulholland Drive", null, null, jimbirthday, 50, 3.26, null }; table.insert(jimrow);
// With Builder
TupleBuilder builder = table.tupleBuilder();
int johnbirthday = (int)(new DateTimeOffset(new DateTime(1975, 1, 1)).ToUnixTimeSeconds() / 86400); object[] johnrow = { 1, "123456789A", "John", "Doe", "No comments", "Mulholland Drive", "555333695", "johndoe@nowhere.no", johnbirthday, 70, 1.79, null }; builder.add(johnrow); table.insert(builder.build(table)); // end::insert[] // tag::insertWSeq[] session.createSequence("seq", 100, 2, 10);// start at 2, increment by 10
ulong next_value = session.seqNextValue("seq"); Console.WriteLine("Next value: {0}", next_value); // reuse builder builder.add(0, next_value).add(1, "912345678B").add(2, "Jane"); int janebirthday = (int)(new DateTimeOffset(new DateTime(1972, 10, 7)).ToUnixTimeSeconds() / 86400); builder.add(6, "0034698765432").add(7, "janedoe@lx.com").add(8, janebirthday) .add(9, 75).add(10, 1.79);
table.upsert(builder.build(table));
session.end(); // end::insertWSeq[]
Thread.Sleep(500);
// tag::getByKey[] session = new Session(); table = new Table(session, tablename);
lxapi.Tuple key = table.keyBuilder().add(0, 2).buildKey(table);
lxapi.Tuple tableTuple = table.get(key); int nflds = table.info.numOfFields(); for (int inx = 0; inx < nflds; inx++) { if (!tableTuple.isNull(inx)) { Console.WriteLine("Field #{0} -> {1}", inx, tableTuple.getString(inx)); } } // end::getByKey[]
// tag::update[] builder.add(tableTuple); builder.add(9, 62.7); // change weight
table.update(builder.build(table));
session.end(); // end::update[]
// tag::basicScan[] Console.WriteLine("basicScan"); session = new Session(); table = new Table(session, tablename);
Scan scan = table.scan(new ScanProperties(table).maxrows(2), 0);
scan.begin(); lxapi.Tuple tuple = scan.next(); int count = 0; while (tuple != null) { count++; tuple = scan.next(); } if (count != 2) { throw new Exception("Not the expected num of rows but " + count); }
scan.end(); Console.WriteLine("basicScan end"); // end::basicScan[]
Fields
info
table's info
Declaration
public readonly TableInfo info
Field Value
Type | Description |
---|---|
TableInfo |
kvTbl
Table Handle
Declaration
public readonly IntPtr kvTbl
Field Value
Type | Description |
---|---|
System.IntPtr |
session
Session which the table belongs to
Declaration
public readonly Session session
Field Value
Type | Description |
---|---|
Session |
Methods
addUpsertDefition(Expression[])
Supply a definition for updating the fields being added in case a previous version exists for the tuple.
The syntax for expressions is similar to that of a group-by expression groupBy(Expression[]). However, aggregation operators are not permitted. On the other hand, the old field operators may be used to refer to the field in the previous version of the tuple.
Declaration
public int addUpsertDefition(Expression[] expressions)
Parameters
Type | Name | Description |
---|---|---|
Expression[] | expressions | expressions Expression |
Returns
Type | Description |
---|---|
System.Int32 | 0 on success. Exception when error |
Examples
Expression[] exprs = new Expression[12];
exprs[0] = Expression.oldFieldLong(0); // keep old field
exprs[1] = Expression.oldFieldStr(1); // keep old field
exprs[2] = Expression.oldFieldLong(2); // keep old field
exprs[3] = Expression.oldFieldStr(3); // keep old field
exprs[4] = Expression.oldFieldStr(5); // keep #5 old field
exprs[5] = null; // update field
exprs[6] = null; // update field
exprs[7] = null; // update field
exprs[8] = Expression.oldFieldInt(8); // keep old field
exprs[9] = Expression(Expression.Op.KVMUL, Expression.fieldFloat(9),
Expression.oldFieldFloat(9)); // apply coeficient to old value
exprs[10] = null; // update field
exprs[11] = null; // update field
TupleBuilder builder = table.tupleBuilder();
int johnbirthday = (int)(new DateTimeOffset(new DateTime(1975, 1, 1)).ToUnixTimeSeconds() / 86400);
object[] johnrow = { 1, "123456789A", "John", "Doe", "No comments",
"Mulholland Drive", "555333695", "johndoe@nowhere.no", johnbirthday, 0.3, 1.79, null };
builder.add(johnrow);
table.upsert(builder.build(table));
addUpsertDefition(String)
Supply a definition for updating the fields being added in case a previous version exists for the tuple.
The syntax for expressions is similar to that of a group-by expression Expression and ScanProperties(Table, String). However, aggregation operators are not permitted. On the other hand, the old field operators may be used to refer to the field in the previous version of the tuple.
Declaration
public int addUpsertDefition(string expr)
Parameters
Type | Name | Description |
---|---|---|
System.String | expr | expressions Expression |
Returns
Type | Description |
---|---|
System.Int32 | 0 on succes. Exception when error |
delete(Tuple)
Delete a tuple
Declaration
public int delete(Tuple key)
Parameters
Type | Name | Description |
---|---|---|
Tuple | key | key tuple buildKey(Table) |
Returns
Type | Description |
---|---|
System.Int32 | 0 on success. Exception in other case |
Examples
lxapi.Tuple key = table.keyBuilder().add(0, 2).buildKey(table);
table.delete(key);
delete(TupleBuilder)
Delete a tuple from a table. It builds the key-tuple using the current data in tempTuple
This is equivalent to the following code
table.delete(tempTuple.buildKey(table));
Declaration
public int delete(TupleBuilder tempTuple)
Parameters
Type | Name | Description |
---|---|---|
TupleBuilder | tempTuple |
Returns
Type | Description |
---|---|
System.Int32 |
Examples
table.delete(table.keyBuilder().add(0, 2));
Dispose()
Dispose
Declaration
public void Dispose()
Dispose(Boolean)
Release Table Handle
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing |
Finalize()
Destructor
Declaration
protected void Finalize()
fullScan(Int32)
Create a full scan from a table object.
No filter is applied to the table rows. It is only possible to
to indicate how the server is going to iterate over the row with
param flags
, ScanPropFlags
Declaration
public Scan fullScan(int flags = 0)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | flags | scan type bitmask ScanPropFlags |
Returns
Type | Description |
---|---|
Scan | a new scan object |
Examples
Perform a sorted full scan in reverse order
session = new Session();
table = new Table(session, "person");
Scan scan = table.fullScan((int)ScanPropFlags.KVSort|(int)ScanPropFlags.KVReverse);
get(Tuple)
Get a tuple
Declaration
public Tuple get(Tuple key)
Parameters
Type | Name | Description |
---|---|---|
Tuple | key | key tuple buildKey(Table) |
Returns
Type | Description |
---|---|
Tuple | table's tuple with the given key when exist |
Examples
lxapi.Tuple key = table.keyBuilder().add(0, 2).buildKey(table);
lxapi.Tuple tableTuple = table.get(key);
get(Tuple, ScanProperties)
Get filtered tuple
Declaration
public Tuple get(Tuple key, ScanProperties filter)
Parameters
Type | Name | Description |
---|---|---|
Tuple | key | key tuple buildKey(Table) |
ScanProperties | filter | Filter predicate ScanProperties |
Returns
Type | Description |
---|---|
Tuple | table's filtered tuple when exist |
Examples
Expression expr = Expression.fieldFloat(9).op(Expression.Op.KVLE, new Expression((double)70));
ScanProperties properties = new ScanProperties(table).addPredicate(expr)
lxapi.Tuple key = table.keyBuilder().add(0, 2).buildKey(table);
lxapi.Tuple tableTuple = table.get(key, properties);
get(TupleBuilder)
Get a tuple from a table. It builds the key-tuple using the current data in tempTuple
This is equivalent to the following code
table.get(tempTuple.buildKey(table));
Declaration
public Tuple get(TupleBuilder tempTuple)
Parameters
Type | Name | Description |
---|---|---|
TupleBuilder | tempTuple |
Returns
Type | Description |
---|---|
Tuple |
Examples
table.get(table.keyBuilder().add(0, 2));
get(TupleBuilder, ScanProperties)
Get filtered tuple. It builds the key-tuple using the current data in tempTuple
This is equivalent to the following code
table.get(tempTuple.buildKey(table), filter);
Declaration
public Tuple get(TupleBuilder tempTuple, ScanProperties filter)
Parameters
Type | Name | Description |
---|---|---|
TupleBuilder | tempTuple | key tuple buildKey(Table) |
ScanProperties | filter | Filter predicate ScanProperties |
Returns
Type | Description |
---|---|
Tuple | table's filtered tuple when exist |
Examples
Expression expr = Expression.fieldFloat(9).op(Expression.Op.KVLE, new Expression((double)70));
ScanProperties properties = new ScanProperties(table).addPredicate(expr)
lxapi.Tuple tableTuple = table.get(table.keyBuilder().add(0, 2), properties);
gets(Tuple[])
Multiget. Get a list of tuples by invoking the server just once
Declaration
public Tuple[] gets(Tuple[] keys)
Parameters
Type | Name | Description |
---|---|---|
Tuple[] | keys | key tuples buildKey(Table) |
Returns
Type | Description |
---|---|
Tuple[] | table's tuples with the given keys when exist |
Examples
lxapi.Tuple[] keys = new lxapi.Tuple[3];
keys[0] = keybuilder.add(0, 555).buildKey(table);
keys[1] = keybuilder.add(0, 777).buildKey(table);
keys[2] = keybuilder.add(0, 999).buildKey(table);
lxapi.Tuple[] tuples = table.gets(keys);
gets(Tuple[], ScanProperties)
Get filtered tuples
Declaration
public Tuple[] gets(Tuple[] keys, ScanProperties filter)
Parameters
Type | Name | Description |
---|---|---|
Tuple[] | keys | key tuples buildKey(Table) |
ScanProperties | filter | Filter predicate ScanProperties |
Returns
Type | Description |
---|---|
Tuple[] | table's filtered tuples when exist |
Examples
Expression expr = Expression.fieldFloat(9).op(Expression.Op.KVLE, new Expression((double)70));
ScanProperties properties = new ScanProperties(table).addPredicate(expr)
lxapi.Tuple[] keys = new lxapi.Tuple[3];
keys[0] = keybuilder.add(0, 555).buildKey(table);
keys[1] = keybuilder.add(0, 777).buildKey(table);
keys[2] = keybuilder.add(0, 999).buildKey(table);
lxapi.Tuple[] tuples = table.gets(keys, properties);
index(String)
Retrieve table's index by its name
Declaration
public Index index(string iname)
Parameters
Type | Name | Description |
---|---|---|
System.String | iname | index name |
Returns
Type | Description |
---|---|
Index | index |
insert(Tuple)
Insert a tuple in table
Declaration
public int insert(Tuple tpl)
Parameters
Type | Name | Description |
---|---|---|
Tuple | tpl |
Returns
Type | Description |
---|---|
System.Int32 | 0 on success. Exception in other case |
Examples
TupleBuilder builder = table.tupleBuilder();
int johnbirthday = (int)(new DateTimeOffset(new DateTime(1975, 1, 1)).ToUnixTimeSeconds() / 86400);
object[] johnrow = { 1, "123456789A", "John", "Doe", "No comments",
"Mulholland Drive", "555333695", "johndoe@nowhere.no", johnbirthday, 70, 1.79, null };
builder.add(johnrow);
table.insert(builder.build(table));
insert(TupleBuilder)
Insert a tuple in table. It builds the tuple using the current data in tempTuple
This is equivalent to the following code
table.insert(tempTuple.build(table));
Declaration
public int insert(TupleBuilder tempTuple)
Parameters
Type | Name | Description |
---|---|---|
TupleBuilder | tempTuple |
Returns
Type | Description |
---|---|
System.Int32 |
Examples
TupleBuilder builder = table.tupleBuilder();
int johnbirthday = (int)(new DateTimeOffset(new DateTime(1975, 1, 1)).ToUnixTimeSeconds() / 86400);
object[] johnrow = { 1, "123456789A", "John", "Doe", "No comments",
"Mulholland Drive", "555333695", "johndoe@nowhere.no", johnbirthday, 70, 1.79, null };
builder.add(johnrow);
table.insert(builder);
insert(Object[])
Insert a tuple in table
For massive operations, better use insert(Tuple) with TupleBuilder
Declaration
public int insert(object[] arr)
Parameters
Type | Name | Description |
---|---|---|
System.Object[] | arr | array of values |
Returns
Type | Description |
---|---|
System.Int32 |
Examples
object[] jimrow = { 0, null, "Jim", "Doe", "No comments",
"Mulholland Drive", null, null, jimbirthday, 50, 3.26, null };
table.insert(jimrow);
keyBuilder()
Create table's key-tuple builder.
Declaration
public TupleBuilder keyBuilder()
Returns
Type | Description |
---|---|
TupleBuilder |
Remarks
The tuple builder might be used to create tuples for another table or index
tupleBuilder()
Create table's tuple builder.
Declaration
public TupleBuilder tupleBuilder()
Returns
Type | Description |
---|---|
TupleBuilder |
Remarks
The tuple builder might be used to create tuples for another table or index
update(Tuple)
Update a tuple
Declaration
public int update(Tuple tpl)
Parameters
Type | Name | Description |
---|---|---|
Tuple | tpl |
Returns
Type | Description |
---|---|
System.Int32 | 0 on success. Exception in other case |
Examples
lxapi.Tuple key = table.keyBuilder().add(0, 2).buildKey(table);
lxapi.Tuple tableTuple = table.get(key);
builder.add(tableTuple);
builder.add(9, 62.7); // change weight
table.update(builder.build(table));
update(TupleBuilder)
Update a tuple in table. It builds the tuple using the current data in tempTuple
This is equivalent to the following code
table.update(tempTuple.build(table));
Declaration
public int update(TupleBuilder tempTuple)
Parameters
Type | Name | Description |
---|---|---|
TupleBuilder | tempTuple |
Returns
Type | Description |
---|---|
System.Int32 |
Examples
lxapi.Tuple tableTuple = table.get(table.keyBuilder().add(0, 2));
builder.add(tableTuple);
builder.add(9, 62.7); // change weight
table.update(builder);
upsert(Tuple)
Upsert a tuple in table
Declaration
public int upsert(Tuple tpl)
Parameters
Type | Name | Description |
---|---|---|
Tuple | tpl |
Returns
Type | Description |
---|---|
System.Int32 | 0 on success. Exception in other case |
Examples
TupleBuilder builder = table.tupleBuilder();
int johnbirthday = (int)(new DateTimeOffset(new DateTime(1975, 1, 1)).ToUnixTimeSeconds() / 86400);
object[] johnrow = { 1, "123456789A", "John", "Doe", "No comments",
"Mulholland Drive", "555333695", "johndoe@nowhere.no", johnbirthday, 70, 1.79, null };
builder.add(johnrow);
table.upsert(builder.build(table));
upsert(TupleBuilder)
Upsert a tuple in a table. It builds the tuple using the current data in tempTuple
This is equivalent to the following code
table.upsert(tempTuple.build(table));
Declaration
public int upsert(TupleBuilder tempTuple)
Parameters
Type | Name | Description |
---|---|---|
TupleBuilder | tempTuple |
Returns
Type | Description |
---|---|
System.Int32 |
Examples
TupleBuilder builder = table.tupleBuilder();
int johnbirthday = (int)(new DateTimeOffset(new DateTime(1975, 1, 1)).ToUnixTimeSeconds() / 86400);
object[] johnrow = { 1, "123456789A", "John", "Doe", "No comments",
"Mulholland Drive", "555333695", "johndoe@nowhere.no", johnbirthday, 70, 1.79, null };
builder.add(johnrow);
table.upsert(builder);
upsert(Object[])
Upsert a tuple in table
For massive operations, better use upsert(Tuple) with TupleBuilder
Declaration
public int upsert(object[] arr)
Parameters
Type | Name | Description |
---|---|---|
System.Object[] | arr | array of values |
Returns
Type | Description |
---|---|
System.Int32 |
Examples
object[] jimrow = { 0, null, "Jim", "Doe", "No comments",
"Mulholland Drive", null, null, jimbirthday, 50, 3.26, null };
table.upsert(jimrow);
upsertDelta(TupleBuilder)
Upsert a delta tuple in a table. It builds the tuple using the current data in tempTuple
This is equivalent to the following code
table.upsert(tempTuple.buildDelta(table));
Declaration
public int upsertDelta(TupleBuilder tempTuple)
Parameters
Type | Name | Description |
---|---|---|
TupleBuilder | tempTuple |
Returns
Type | Description |
---|---|
System.Int32 |
Examples
table = new Table(session, "delta table");
builder.add(1, -100);
table.upsertDelta(builder);
upsertDelta(Object[])
Upsert a delta tuple in a table.
Declaration
public int upsertDelta(object[] arr)
Parameters
Type | Name | Description |
---|---|---|
System.Object[] | arr | array of values |
Returns
Type | Description |
---|---|
System.Int32 |
Examples
object[] jimrow = { 0, null, "Jim", "Doe", "No comments",
"Mulholland Drive", null, null, jimbirthday, 50, 3.26, null };
table.upsertDelta(jimrow);