Wajih

Attached you'll find a small example how to store cells and query them 
again. In addition you'll find useful code fragments in the ht4n test 
suite, see https://github.com/andysoftdev/ht4n/tree/master/src/ht4n.Test.

 -Andy


On Monday, April 9, 2012 8:15:00 AM UTC+2, Wajihullah Baig wrote:
>
> Ok I have just sent a feed back with a request for a sample code.
>
> Thank you
>
> Wajih
>
> On Thursday, March 29, 2012 8:32:46 PM UTC+5, Andy wrote:
>>
>> ..feel free to use the ht4n feedback form 
>> http://ht4n.softdev.ch/index.php/feedback 
>>
>> I'll send you a small getting started code fragment. 
>>
>> -Andy 
>>
>> On Mar 29, 5:30 pm, Andy <[email protected]> wrote: 
>> > Hi Wajih 
>> > 
>> > the ht4n downloads and the API reference documentation are up-to-date, 
>> > please seehttp://ht4n.softdev.ch/index.php/documentation/api-reference 
>> > 
>> > I guess I'm able to get the getting started and a small tutorial ready 
>> > in the next few weeks. 
>> > 
>> > -Andy 
>> > 
>> > On Mar 29, 1:56 pm, Wajihullah Baig <[email protected]> wrote: 
>> > 
>> > 
>> > 
>> > 
>> > 
>> > 
>> > 
>> > > Sorry for the incorrect subject line in my previous post. 
>> > 
>> > > Wajih
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Hypertable Development" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/hypertable-dev/-/hqUiCByIGG4J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/hypertable-dev?hl=en.

public void GettingStarted() {

    //
    // Define the table schema in XML
    //
    var tableSchema =  "<Schema><AccessGroup name=\"default\"><ColumnFamily><Name>MyCF</Name></ColumnFamily></AccessGroup></Schema>";

    //
    // Create Hypertable context and a client using the connection string specified
    //
    using( var context = Context.Create("Provider=Hyper; Uri=net.tcp://localhost") ) // for Thrift use "Provider=Thrift; Uri=net.tcp://localhost"
    using( var client = context.CreateClient() )
    
    //
    // Open or create namespace
    //
    using( var ns = client.OpenNamespace("MyNamespace", OpenDispositions.OpenAlways | OpenDispositions.CreateIntermediate) )
    
    //
    // Open or create table
    //
    using( var table = ns.OpenTable("MyTable", tableSchema, OpenDispositions.OpenAlways) ) {

        //
        // Write some cells, using a table mutator
        //
        MutatorSpec mutatorSpec = null; // here configure the mutator, using new MutatorSpec(..) { ... };
        using( var mutator = table.CreateMutator(mutatorSpec) ) {
            // write some cells
            var key = new Key { ColumnFamily = "MyCF" };
            for( int n = 0; n < 1000; ++n ) {
                key.Row = null; // force base85 encoded guid row id
                mutator.Set(key, BitConverter.GetBytes(n));
            }
        }

        //
        // Read the previously written cells, using a table scanner
        //
        ScanSpec scanSpec = null; // here configure the scan specification, add any query predicates, using new ScanSpec(..) { ... };
        using( var scanner = table.CreateScanner(scanSpec) ) {
            var cell = new Cell();
            while( scanner.Next(cell) ) { // caution - re-use cell instance
                // do something with the cell
            }
        }
        // or
        using( var scanner = table.CreateScanner(scanSpec) ) {
            Cell cell;
            while( scanner.Next(out cell) ) {
                // do something with the cell
            }
        }
        // or
        using( var scanner = table.CreateScanner(scanSpec) ) {
            foreach( var cell in scanner ) {
                // do something with the cell
            }
        }
    }
}

Reply via email to