1010data .net sdk user's guide › documentationcenter › prod › 1010data… · a 1010data...

23
(212) 405.1010 | [email protected] | Follow: @1010data | www.1010data.com 1010data .NET SDK User's Guide

Upload: others

Post on 28-Jun-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1010data .NET SDK User's Guide › documentationcenter › prod › 1010data… · A 1010data Insights Platform session is an instance of a particular user ID logged into the platform

(212) 405.1010 | [email protected] | Follow: @1010data | www.1010data.com

1010data .NET SDK User's Guide

Page 2: 1010data .NET SDK User's Guide › documentationcenter › prod › 1010data… · A 1010data Insights Platform session is an instance of a particular user ID logged into the platform

1010data .NET SDK User's Guide | Contents | 2

© 2017 1010data, Inc. All rights reserved.

Contents

Introduction.................................................................................................. 3

Getting started............................................................................................. 4Add TenTenSDK.Native.dll and TenTenSDK.dll.................................................................................5Add lib1010csdk-vs64.dll.....................................................................................................................6

Basic usage..................................................................................................8Setting up an application.................................................................................................................... 8Establishing a session.........................................................................................................................8

Login Types.............................................................................................................................. 9Connecting via proxy................................................................................................................9

Running a query................................................................................................................................10Accessing the results of a query...................................................................................................... 10Cleaning up a session...................................................................................................................... 11

Exception handling....................................................................................13

.NET result options................................................................................... 14

SAM pools and multi-threading............................................................... 15Warm a SAM pool.............................................................................................................................16

Best practices............................................................................................ 18

Updating existing applications................................................................ 19

Reference....................................................................................................22

Support requests....................................................................................... 23

Page 3: 1010data .NET SDK User's Guide › documentationcenter › prod › 1010data… · A 1010data Insights Platform session is an instance of a particular user ID logged into the platform

1010data .NET SDK User's Guide | Introduction | 3

Introduction

The 1010data .NET SDK enables developers to create applications that connect their applications to the1010data Insights Platform for processing and retrieval of big data.

This guide contains the information you need to start developing a new application if this is your first timeworking with the SDK. The .NET SDK enables the development of both single-threaded and multithreadedapplications, working with either single-user Insights Platform sessions or SAM pools.

The following sections may be particularly helpful:

• Getting started on page 4 contains the information you need to start using the .NET SDK. It alsoincludes instructions on how to try out the examples provided with the library files

• Basic usage on page 8 walks you through a basic workflow to create a single-threaded, single-userapplication.

• SAM pools and multi-threading on page 15 explains SAM pool logins and multithreaded applications.

For developers who are more familiar with our SDKs and developing on the Insights Platform, there is alsoreference material and lots of examples to answer your questions.

If you need information about a specific class or function, refer to the 1010data .NET SDK Reference.

Page 4: 1010data .NET SDK User's Guide › documentationcenter › prod › 1010data… · A 1010data Insights Platform session is an instance of a particular user ID logged into the platform

1010data .NET SDK User's Guide | Getting started | 4

Getting started

Before you start writing your first application to connect to the 1010data Insights Platform, you need toinstall Visual Studio and download the .NET SDK.

RequirementsThe 1010data .NET SDK is only available for Windows. You must have Visual Studio installed on yoursystem.

InstallationYou can download the .NET SDK files from https://www2.1010data.com/downloads/tools/dotNETv2/dotNetSDKv2.zip. The zip file contains two folders and a Readme file. The win64 and win32 directoriescontain the library files. Use the library files in the directory that matches the version you're using.

Version Directory to use

Windows 64-bit win64

Windows 32-bit win32

Two of the library files, TenTenSDK.Native.dll and TenTenSDK.dll, must be added asreferences to your Visual Studio project. The third file, lib1010csdk-vs64.dll or lib1010csdk-vs32.dll depending on the version, must be added as source file. For more information, see AddTenTenSDK.Native.dll and TenTenSDK.dll on page 5 and Add lib1010csdk-vs64.dll on page 6.

If you are not working with a Visual Studio project, add these files to your working directory. Theexamples directory contains sample Visual Studio projects. Each of these projects already references thelibrary files.

Example projectsThe examples folder contains six examples. Each example is set up as a Visual Studio project. Beforeyou can run the examples, you must replace the USER_NAME and USER_PASSWORD in each projectwith a valid 1010data user name and password before you attempt to run the sample applications.

To run a project, click Start in the toolbar.

The examples directory contains the following sample projects:

AllTypesCasts Insights Platform data types (text, integer, decimal, bigint, date, time, and date+time) to theirappropriate .NET types.

ColumnPrinterPrints the columns of a table one at a time.

FsharpPrints the entire table. This example is written in F #.

IntPrinterPrints the title and values of columns that have the integer data type.

Page 5: 1010data .NET SDK User's Guide › documentationcenter › prod › 1010data… · A 1010data Insights Platform session is an instance of a particular user ID logged into the platform

1010data .NET SDK User's Guide | Getting started | 5

OddPrinterPrints the odd rows.

TablePrinterPrints the entire table.

Threads1Uses two threads to create two session objects, retrieves information from two tables, and downloadsthe data into two separate files.

ToDataTableCasts your result set to the .NET DataTable object.

VbnetPrints the entire table. This example is written in VB.NET.

Add TenTenSDK.Native.dll and TenTenSDK.dllYou must add the TenTenSDK.Native.dll and TenTenSDK.dllfiles as references in your VisualStudio project.

To TenTenSDK.Native.dll and TenTenSDK.dll to your project:

1. In the Solution Explorer, right-click on References.2. Select Add Reference.

The Reference Manager opens.

3. Click the Browse button.4. Navigate to and select the TenTenSDK.Native.dll and TenTenSDK.dll.5. Click Add.

The references are added to the Reference Manager.

Page 6: 1010data .NET SDK User's Guide › documentationcenter › prod › 1010data… · A 1010data Insights Platform session is an instance of a particular user ID logged into the platform

1010data .NET SDK User's Guide | Getting started | 6

6. Click OK.

Add lib1010csdk-vs64.dllYou must add the lib1010csdk-vs64.dll file as a source file in your Visual Studio project.

Note: If you have a 32-bit version of Windows, use lib1010csdk-vs32.dll instead.

To add lib1010csdk-vs64.dll to your project:

1. In the Solution Explorer, right-click on the name of your application.

2. Click Add > Existing Item3. Navigate to and select lib1010csdk-vs64.dll.

The file extensions filter in the Add Existing Item file browser may be set to show Visual C# Filesonly. Select All Files (*.*).

4. Click Add.5. Right-click on the lib1010csdk-vs64.dll file.6. Click Properties.

Page 7: 1010data .NET SDK User's Guide › documentationcenter › prod › 1010data… · A 1010data Insights Platform session is an instance of a particular user ID logged into the platform

1010data .NET SDK User's Guide | Getting started | 7

7. Set Copy to Output Directory to Copy if newer.

Page 8: 1010data .NET SDK User's Guide › documentationcenter › prod › 1010data… · A 1010data Insights Platform session is an instance of a particular user ID logged into the platform

1010data .NET SDK User's Guide | Basic usage | 8

Basic usage

Creating a new basic, single-threaded, single-user application with the 1010data .NET SDK includessetting up your application framework, establishing a session, submitting a query, receiving results, andcleaning up the session.

Setting up an applicationYour application setup includes referencing any required libraries, including the 1010data .NET SDK, andcreating a class that contains all of the functions that interact with the 1010data Insights Platform, the Mainmethod, and any additional functions contained within.

In this example, the DocumentationExample class contains the PrintTable function and the Mainmethod. In more complex applications, you are likely to have more functions with greater complexity.using System;using TenTenSDK;

public class DocumentationExample { public static void PrintTable(Session testSession, String path) { } public static void Main() { }}The function PrintTable takes the Session object (testSession) and the path of a table on the1010data Insights Platform (path). These parameters are common for functions written to interact with theInsights Platform because every interaction requires a session and interacts with a table.

Establishing a sessionA 1010data Insights Platform session is an instance of a particular user ID logged into the platform withina certain environment. A session is comprised of a dedicated set of resources that can serve a singlerequest at a time.

A single platform session may have multiple Session objects attached to it. When a user logs into theplatform, if no session is active, a new one is created. If a session is currently active for that user, the logintype determines if the current session is possessed by the user; a new session is started after the currentone is killed; or the connection fails if an active session exists. Currently, each user ID can only have oneplatform session associated with it. For more information, see Login Types on page 9.

In this example, the Session object is created in the Main() method. The new Session objecttestSession takes four parameters:

• a URI (gateway)• a valid Insights Platform user name (user)• that user's password (pwd)• the login type, which is LoginType.POSSESS in this example

If you are connecting via a proxy server, your gateway string contains your proxy server address and anycredentials. For more information, see Connecting via proxy on page 9.using System;using TenTenSDK;

public class DocumentationExample { public static void PrintTable(Session testSession, String path) {

Page 9: 1010data .NET SDK User's Guide › documentationcenter › prod › 1010data… · A 1010data Insights Platform session is an instance of a particular user ID logged into the platform

1010data .NET SDK User's Guide | Basic usage | 9

}

public static void Main() { Uri gateway = new Uri("https://www2.1010data.com/cgi-bin/gw.k"); String user = "[USER_NAME]"; String pwd = "[USER_PASSWORD]"; String path = "[TABLE_PATH]"; Session testSession = new Session(gateway, user, pwd, LoginType.POSSESS); PrintTable(testSession, path); }}

Note: [USER_NAME], [USER_PASSWORD], and [TABLE_PATH] are placeholders for valid InsightsPlatform user name, password, and table path.

Login TypesThe login type determines what happens when the application establishes a connection to the InsightsPlatform and another session is currently active.

There are three valid login types: LoginType.POSSESS, LoginType.KILL, and LoginType.NOKILL.

• LoginType.POSSESS attaches the new connection to an existing session if one is active when theconnection is established.

• LoginType.KILL ends an existing session and starts a new one when the connection is established.• LoginType.NOKILL fails to connect if an existing session is active when the connection is

established.

Connecting via proxyIf your application is connecting to the Insights Platform via a proxy server, your gateway string needs to bemodified to include the proxy server's address (MYCORPORATEPROXYADDRESS)

Depending on your proxy server's configuration, you may also need to include:

• user name (PROXY_USERNAME)• password (PROXY_PASSWORD)• port (PORT)

The proxy server's information is added to the beginning of the gateway string between square brackets([]).[http://PROXY_USERNAME:PROXY_PASSWORD@MYCORPORATEPROXYADDRESS:PORT]https://www2.1010data.com/cgi-bin/gwIf you're unsure of whether or not you need to specify a proxy server, or you need your proxy servercredentials, contact your corporate technology support team or IT department.

Note: This example does not use square brackets ([]) to denote variables.

ExamplesSome proxy servers will require a full set of credentials, for example:[http://aHamilton:[email protected]:8080]https://www2.1010data.com/cgi-bin/gwA proxy server may only require a user name, for example:[http://[email protected]:8080]https://www2.1010data.com/cgi-bin/gwA proxy server may not require any credentials or a port number, for example:

Page 10: 1010data .NET SDK User's Guide › documentationcenter › prod › 1010data… · A 1010data Insights Platform session is an instance of a particular user ID logged into the platform

1010data .NET SDK User's Guide | Basic usage | 10

[http://my.corporate.proxy]https://www2.1010data.com/cgi-bin/gw

Running a queryYour application should act as an intermediary between your users and the platform to pass in a query andreceive the queried data.

Gathering specific sets of data or scoping your data should occur within queries. Typically, the analyticalwork is done by the Macro Language query specified by the Query object. For more information on writingqueries using the Insights Platform Macro Language, see the 1010data Reference Manual.

There are two ways to run a query on the platform with the .NET SDK. You can use the Session method,RunQuery, or the Query method, RunOn. A Table object holds query results. These two methods arethe same, and the one you use is your choice. For more information about the RunOn and RunQuerymethods, see Session and Query in the 1010data .NET SDK Reference.

In this example, the Query object is created in the PrintTable function. The new Query objectexampleQuery takes the string containing the Macro Language query and the path to the table to whichthe query is applied. This Macro Language query selects the first 10 rows of the table. As a best practice,longer queries should be saved in a separate file and read.using System;using TenTenSDK;

public class DocumentationExample { public static void PrintTable(Session testSession, String path) { Query exampleQuery = new Query(path, "<sel value=""(between(i_;1;10))""/>"); Table resultTable = testSession.RunQuery(exampleQuery); }

public static void Main() { Uri gateway = new Uri("https://www2.1010data.com/cgi-bin/gw.k"); String user = "[USER_NAME]"; String pwd = "[USER_PASSWORD]"; String path = "[TABLE_PATH]"; Session testSession = new Session(gateway, user, pwd, LoginType.POSSESS); PrintTable(testSession, path); }}

Note: [USER_NAME], [USER_PASSWORD], and [TABLE_PATH] are placeholders for valid InsightsPlatform user name, password, and table path.

Accessing the results of a queryAfter querying the 1010data Insights Platform, your application receives a set of results, which can beaccessed via the Table object.

The Session method, RunQuery, runs the query. The Table object is the result of the query.

In this example, the resultTable is set to the result of testSession.RunQuery(exampleQuery).The application prints the title of each column and the first 10 rows of the table.using System;using TenTenSDK;

public class DocumentationExample { public static void PrintTable(Session testSession, String path) {

Page 11: 1010data .NET SDK User's Guide › documentationcenter › prod › 1010data… · A 1010data Insights Platform session is an instance of a particular user ID logged into the platform

1010data .NET SDK User's Guide | Basic usage | 11

Query exampleQuery = new Query(path, "<sel value=""(between(i_;1;10))""/>"); Table resultTable = testSession.RunQuery(exampleQuery); Console.WriteLine(String.Join("\t", resultTable.Columns.Select(c => c.Info.Title))); foreach(Row r in resultTable.Rows) { Console.WriteLine(String.Join("\t", r.Select(d => d.ToString()))); } }

public static void Main() { Uri gateway = new Uri("https://www2.1010data.com/cgi-bin/gw.k"); String user = "[USER_NAME]"; String pwd = "[USER_PASSWORD]"; String path = "[TABLE_PATH]"; Session testSession = new Session(gateway, user, pwd, LoginType.POSSESS); PrintTable(testSession, path); }}

Note: [USER_NAME], [USER_PASSWORD], and [TABLE_PATH] are placeholders for valid InsightsPlatform user name, password, and table path.

Cleaning up a sessionIf your application uses the using keyword, which implements the IDisposable interface, the Sessionobject is automatically cleaned up at the end of the using block. If your application does not implementusing, then you need to release the session when you've completed the transaction.

The Session class contains a Dispose method, which cleans up the 1010data Insights Platformsession when it is invoked. Depending on the login type that was used to create the Insights Platformsession, there are a few different ways they might be cleaned up. If you are a single user loggedin with LoginType.POSSESS, the session continues to run. If you're a single user logged in withLoginType.KILL or LoginType.NOKILL, the platform session is terminated. A SAM pool user'ssession is released back into the pool; it is never terminated before being released.

Cleaning up a platform session when it is no longer needed is particularly important if you have multipleusers sharing a pool of IDs (SAM pool). Waiting for the garbage collector to clean up Session objectsmay result in a pool that appears fully utilized, but is waiting for Session objects to be destroyed. Formore information about SAM pools, see SAM pools and multi-threading on page 15.

The most efficient and effective way to release user IDs back to the pool is to invoke the Dispose method,either by explicitly calling it or employing using, which invokes it at the end of the block.

Via the using statement:using System;using TenTenSDK;

public class DocumentationExample { public static void PrintTable(Session testSession, String path) { Query exampleQuery = new Query(path, "<sel value=""(between(i_;1;10))""/>"); using(Table resultTable = testSession.RunQuery(exampleQuery)) { Console.WriteLine(String.Join("\t", resultTable.Columns.Select(c => c.Info.Title))); foreach(Row r in resultTable.Rows) { Console.WriteLine(String.Join("\t", r.Select(d => d.ToString())));

Page 12: 1010data .NET SDK User's Guide › documentationcenter › prod › 1010data… · A 1010data Insights Platform session is an instance of a particular user ID logged into the platform

1010data .NET SDK User's Guide | Basic usage | 12

} } }

public static void Main() { Uri gateway = new Uri("https://www2.1010data.com/cgi-bin/gw.k"); String user = "[USER_NAME]"; String pwd = "[USER_PASSWORD]"; String path = "[TABLE_PATH]"; using(Session testSession = new Session(gateway, user, pwd, LoginType.POSSESS)) { PrintTable(testSession, path); } }}

Note: [USER_NAME], [USER_PASSWORD], and [TABLE_PATH] are placeholders for valid InsightsPlatform user name, password, and table path.

Explicitly calling the Dispose method:using System;using TenTenSDK;

public class DocumentationExample { public static void PrintTable(Session testSession, String path) { Query exampleQuery = new Query(path, "<sel value=""(between(i_;1;10))""/>"); Table resultTable = testSession.RunQuery(exampleQuery); Console.WriteLine(String.Join("\t", resultTable.Columns.Select(c => c.Info.Title))); foreach(Row r in resultTable.Rows) { Console.WriteLine(String.Join("\t", r.Select(d => d.ToString()))); } }

public static void Main() { Uri gateway = new Uri("https://www2.1010data.com/cgi-bin/gw.k"); String user = "[USER_NAME]"; String pwd = "[USER_PASSWORD]"; String path = "[TABLE_PATH]"; Session testSession = new Session(gateway, user, pwd, LoginType.POSSESS); PrintTable(testSession, path); testSession.Dispose(); }}

Note: [USER_NAME], [USER_PASSWORD], and [TABLE_PATH] are placeholders for valid InsightsPlatform user name, password, and table path.

Page 13: 1010data .NET SDK User's Guide › documentationcenter › prod › 1010data… · A 1010data Insights Platform session is an instance of a particular user ID logged into the platform

1010data .NET SDK User's Guide | Exception handling | 13

Exception handling

The .NET SDK contains the TenTenException class.

The TenTenException class can be caught with try/catch. The TenTenException class is theparent class of all of the 1010data .NET SDK exceptions. The following example uses try/catch forexception handling:using System;using System.Linq;using TenTenSDK;

namespace ColumnPrinter { public static class TestProgram { public static void PrintTable(Session s, String path, String ops) { var q = new Query(path, ops); using(Table t = q.RunOn(s)) { foreach(Column c in t.Columns) { Console.WriteLine("Column {0} ({1})", c.Info.Title, c.Info.Name); Console.WriteLine("\t" + String.Join<String>(", ", c.AsStrings)); } } } public static void Main(String[] args) { Uri gateway = new Uri("https://www2.1010data.com/cgi-bin/gw.k"); String user = "[USERNAME]"; String pwd = "[PASSWORD]"; String table = "pub.demo.weather.stations"; String ops = "<sel value=""(i_<100)""/>"; try { using(Session s = new Session(gateway, user, pwd, LoginType.POSSESS)) { PrintTable(s, table, ops); } } catch (TenTenSDK.Exceptions.TenTenException exc) { Console.Error.WriteLine("1010 Exception occurred: " + exc.ToString()); } Console.Write("Press Enter to finish"); } }}

Page 14: 1010data .NET SDK User's Guide › documentationcenter › prod › 1010data… · A 1010data Insights Platform session is an instance of a particular user ID logged into the platform

1010data .NET SDK User's Guide | .NET result options | 14

.NET result options

There are multiple ways to work with the results returned by the 1010data .NET SDK.

Casting to a DataTableYou can export a small result set with the .NET object DataTable.

In the following example, the CrossSection method is used to take a portion of the Table object andcast it to a DataTable.using(Session s = new Session(gateway, user, pwd, LoginType.POSSESS)) { var q = new Query(tablename, ops); using(Table t = q.RunOn(s)) { Console.WriteLine("Exporting to .NET DataFrame..."); DataTable dt = t.CrossSection(0, Math.Min(t.Rows.Count, 500)); foreach(var z in dt.Rows) { Console.WriteLine(z); } }}

Using IQueryableWhile none of the .NET SDK Objects implement the IQueryable interface LINQ allows you to treat anObject that implements IEnumerable in much the same way. If you want to leverage the LINQ IQueryable-like features, you can use the RowSet object. The RowSet object is a collection of the table's rows,and it implements the IEnumerable interface. There is a possible runtime performance issue, because itdownloads the entire dataset into memory before the LINQ query is performed.

Scrolling through a large data setAll of the objects that access data in the .NET SDK implement IEnumerable. This interface enables youto enumerate through the results, even if they are too large to fit in memory. Most of the examples in thisdocument access data in this fashion.

Page 15: 1010data .NET SDK User's Guide › documentationcenter › prod › 1010data… · A 1010data Insights Platform session is an instance of a particular user ID logged into the platform

1010data .NET SDK User's Guide | SAM pools and multi-threading | 15

SAM pools and multi-threading

A SAM pool enables a single set of credentials to be shared between client side threads to leveragemultiple threads of parallelism on the 1010data Insights Platform.

Creating a new Session object for a SAM pool user is similar to creating a single-user Session object.Session session = new Session(gateway, owner, group, pw, LoginType.POSSESS)The SAM pool user session takes two different parameters. Instead of the individual user name user,this Session object takes the owner parameter. The owner parameter is the group owner's user name.The group parameter is the group ID. The SAM pool Session constructor takes the following parametervariables:

• gateway - a 1010data Insights Platform URI• group - a group ID• owner - the group owner ID• password - the group owner password

If your users are using a SAM pool to log in, they will not have their own platform IDs. The users sharea single set of credentials to log into the platform. A SAM pool has a number of IDs to use, but it is notlimitless. You may have to account for cases where peak utilization creates a situation where more threadsare trying to access the platform than your SAM pool is configured to handle.

The .NET SDK is designed to queue during Session object construction when a SAM pool is fully utilized.During this queuing time the thread trying to construct a new Session object retries the request every tenseconds.

To ensure that your SAM pool is fully utilized, release sessions as soon as your thread is done to preventa full pool of IDs where all of the threads of database concurrency are in use at the same time. For moreinformation, see Cleaning up a session on page 11.

In this example, two threads construct two separate Session objects and log in with a SAM pool. Theapplication retrieves data from two different tables and downloads them into two separate files.using System;using System.Threading;using System.Linq;using TenTenSDK;

private static void DownloadTable(Object obj) { Uri gateway = new Uri(((String[])obj)[0]); String owner = ((String[])obj)[1]; String group = ((String[])obj)[2]; String pwd = ((String[])obj)[3]; String path = ((String[])obj)[4]; String outpath = ((String[])obj)[5]; using (Session s = new Session(gateway, owner, group, pwd, LoginType.POSSESS)) { var query = new Query(path, "<sel value=""(i_<200000)""/>"); Table t = query.RunOn(s); using (var file = new System.IO.StreamWriter(outpath, false)) { foreach (Row row in t.Rows) { file.WriteLine(String.Join("\t", row.Select(d => d.ToString()))); } } } }

Page 16: 1010data .NET SDK User's Guide › documentationcenter › prod › 1010data… · A 1010data Insights Platform session is an instance of a particular user ID logged into the platform

1010data .NET SDK User's Guide | SAM pools and multi-threading | 16

public static void Main(String[] args) { String gateway = "https://www2.1010data.com/cgi-bin/gw.k"; String group = "[GROUPID]"; String owner = "[OWNERNAME]"; String pwd = "[PASSWORD]"; String path1 = "pub.public_data.census.acs.all_acs_processed_tables"; String path2 = "pub.public_data.census.acs.reference.column_names"; String[] args1 = {gateway, owner, group, pwd, path1, Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Output1.txt" }; String[] args2 = {gateway, owner, group, pwd, path2, Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Output2.txt" }; Thread t1 = new Thread(DownloadTable); Thread t2 = new Thread(DownloadTable); t1.Start(args1); t2.Start(args2); t1.Join(); t2.Join(); }}

Note: [GROUPID], [OWNERNAME], and [PASSWORD] are placeholders for valid Insights Platformgateway, group ID, owner name, and password.

Warm a SAM poolOne way to reduce the amount of time it takes to retrieve results from the 1010data Insights Platform is to"warm" the SAM pool by logging in IDs ahead of time.

The WarmPool function logs in available SAM pool user IDs. Additionally, when warming the pool you canprovide queries to run on the IDs when they are logged in. This can speed the retrieval of results for users.

The WarmPool function takes the following parameters:

• URI (gateway)• Group owner name (owner)• Group ID (group)• Group owner password (password)WarmPool(gateway, owner, group, password)You can run WarmPool without logging in or from a session that is logged in, in which case, you will nothave to re-input your information (gateway, owner, group, and password) again.

The used IDs should be released at the end of their activity with the platform. When they are released, theyare not warmed automatically.

The example below uses WarmPool to warm the SAM pool and Query to provide a query:

using System;using System.Linq;using TenTenSDK;

public class DocumentationExample{ public static void PrintTable(Session testSession, String path) { Query xmplQuery = new Query(path,""); using (Table resultTable = testSession.RunQuery(xmplQuery)) { Console.WriteLine(String.Join("\t", resultTable.Columns.Select(c => c.Info.ComponentType))); }

Page 17: 1010data .NET SDK User's Guide › documentationcenter › prod › 1010data… · A 1010data Insights Platform session is an instance of a particular user ID logged into the platform

1010data .NET SDK User's Guide | SAM pools and multi-threading | 17

} public static void Main() { Uri gateway = new Uri("http://www2.1010data.com/prod-latest/gw"); String owner = "USERNAME"; String pwd = "PASSWORD"; String group = "GROUP"; String path = "pub.demo.weather.stations"; Session session=null;

var qqs = new Query[2];

qqs[0] = new Query("pub.demo.weather.stations", "<sel value=\"elev&lt;100\"/>"); qqs[1] = new Query("pub.demo.weather.conditions", "woop"); try { int i = Session.WarmPool(gateway, owner, group, pwd, qqs); Console.WriteLine("Back now"); Console.WriteLine("Got {0}",i); } catch (TenTenSDK.Exceptions.TenTenException e) { Console.WriteLine("Exception caught: {0}", e); } Console.WriteLine("Done now, hit enter."); String q9 = Console.ReadLine(); }}

Note: USERNAME, GROUP, and PASSWORD are placeholders for valid Insights Platform group ownername. group name, and password.

Page 18: 1010data .NET SDK User's Guide › documentationcenter › prod › 1010data… · A 1010data Insights Platform session is an instance of a particular user ID logged into the platform

1010data .NET SDK User's Guide | Best practices | 18

Best practices

There are several recommended best practices when using the 1010data .NET SDK.

Clean up your sessions upon query completionUse the using keyword to clean up sessions. For more information, see Cleaning up a session onpage 11.

Scroll through data sequentiallyWhen accessing data, scrolling sequentially produces better performance results. You may want tofilter or sort the data before scrolling through it to ensure liner access.

Use XML queries for random access or set window size to 1When sequential access is not possible, users should facilitate random access via queries. Theexample query below requests a random 10% sample:Query xmplQuery = new Query(path, "<sel value=""draw_(33;10)""/>");If your users are going to ask for a random set of data intersections that do not progress incrementallywithout using a query, the best practice is to set your window size to 1. The window is the numberof rows of data that buffered when the .NET SDK requests results from the platform. By setting thewindow to 1, each row is retrieved individually. This prevents the system from retrieving larger sets ofunneeded data at random points and the unnecessary transfer of data. In general, you won't have toworry about the window. It is worth noting that even with a window size of 1, this kind of access willmost likely perform poorly.

If you do want to change the window size, you can set the SessionPolicy, which is a Sessionproperty.SESSION_NAME.SessionPolicy = new BasicPolicy(1, 0, 1);

Have each thread create a Session object

In a multithreaded application, each thread should create its own Session object. If multiple threadsthat share a single Session object interact with the object in parallel, all but one of the threads will bequeued. Users will experience much better performance if each thread has its own Session object.These objects can all be connected to the same Insights Platform session via LoginType.POSSESS.

Page 19: 1010data .NET SDK User's Guide › documentationcenter › prod › 1010data… · A 1010data Insights Platform session is an instance of a particular user ID logged into the platform

1010data .NET SDK User's Guide | Updating existing applications | 19

Updating existing applications

The latest 1010data .NET SDK is designed for developing applications in a style that is more closelycompatible with .NET development, specifically object-oriented programming.

Applications developed with the original 1010data .NET SDK must be updated to use the object-oriented1010data .NET SDK. When you're updating your existing application, keep that applications developed forthe original 1010data .NET SDK:

• Required you to instantiate exactly one instance of the CppCLISDK1010 class. The object-oriented1010data .NET SDK does not require you to instantiate any instance of the CppCLISDK1010 class.

• Required you to synchronize multiple threads yourself. The object-oriented 1010data .NET SDK,handles thread synchronization. As a best practice, each thread should create its own Session object.For more information, see Best practices on page 18 or Establishing a session on page 8.

• Required you to check for error codes after each method invocation. The object-oriented .NET SDKuses an exception-based model. For more information, see Exception handling on page 13.

• Required applications using a SAM pool to manually acquire a UID via calls to GetUID1010. In theobject-oriented 1010data .NET SDK, this is not required. For more information, see SAM pools andmulti-threading on page 15.

• Required you to manually clean up a 1010data Insights Platform session. In the object-oriented .NETSDK, you can take advantage of the using pattern, which cleans up the session automatically.

This example contains code written for the original 1010data .NET SDK:using System;

public class PrintTable { public static void Main(String[] args) { CppCLISDK1010 link; int login; String username = "USERNAME"; String password = "PASSWORD"; String gateway; String queryXML; String tablePath; int queryID, block, windowSize, finRows; long numRows; String[][] colInfo; Object[][] table;

gateway = "https://www2.1010data.com/cgi-bin/gw"; queryXML = "<sel value=\"(year&gt;1900)\"/>"; tablePath = "pub.demo.baseball.batting"; windowSize = 10000; block = 40000; finRows = 0;

// Create exactly one CppCLISDK1010 Object. link = new CppCLISDK1010(); login = link.login1010(gateway, username, password, 1); // We need to check the return code after every action to // make sure it succeeded. if (login < 0) { Console.Error.WriteLine("Failed " + login + ": " + link.msg1010(login)); Environment.Exit(1); } try { queryID = link.newquery1010(); if(queryID < 0) {

Page 20: 1010data .NET SDK User's Guide › documentationcenter › prod › 1010data… · A 1010data Insights Platform session is an instance of a particular user ID logged into the platform

1010data .NET SDK User's Guide | Updating existing applications | 20

Console.Error.WriteLine("Failed to create query: (" + link.rc1010(login) + ") " + link.msg1010(login)); Environment.Exit(1); } // -2 is COMPRESSED_BINARY link.querymode1010(queryID, windowSize, -2); link.prepquery1010(queryID, tablePath, queryXML);

// Run the query. if(link.runquery1010(login, queryID) < 0) { Console.Error.WriteLine("Failed to run query: (" + link.rc1010(login) + ") " + link.msg1010(login)); Environment.Exit(1); } colInfo = link.querycols1010(queryID); if(colInfo == null) { Console.Error.WriteLine("Failed to get column info: (" + link.rc1010(login) + ") " + link.msg1010(login)); Environment.Exit(1); }

numRows = link.queryrows1010(queryID);

// For testing, limit the number of rows to 5000. numRows = Math.Min(5000, numRows); block = 1000;

while (finRows < numRows) { // Pull down one block at a time. // Start at finRows and get all the columns. table = link.getdataRM1010(queryID, finRows, block, colInfo); if(table == null) { Console.Error.WriteLine("Failed to get data: (" + link.rc1010(login) + ") " + link.msg1010(login)); Environment.Exit(1); } finRows += block;

// For each row in this block... for (int i = 0; i < table.Length; i++) { // for each column in this row... for (int j = 0; j < table[i].Length; j++) { Console.Write(table[i][j] + "\t"); } Console.WriteLine(); } // It is important to set the table to null // when you are finished using it. table = null; } } finally { link.logout1010(login); } }}This example contains code written for the object-oriented 1010data .NET SDK:using System;

Page 21: 1010data .NET SDK User's Guide › documentationcenter › prod › 1010data… · A 1010data Insights Platform session is an instance of a particular user ID logged into the platform

1010data .NET SDK User's Guide | Updating existing applications | 21

using System.Linq;using TenTenSDK;

public class PrintTable{ public static void Main(string[] args) { String username; String password; Uri gateway; String queryXML; String tablePath; Session session; Query query; Table results;

username = "USERNAME"; password = "PASSWORD";

gateway = new Uri("https://www2.1010data.com/cgi-bin/gw"); queryXML = "<sel value=\"(year&gt;1900)\"/>"; tablePath = "pub.demo.baseball.batting";

try { using (session = new Session(gateway, username, password, LoginType.POSSESS)) { query = new Query(tablePath, queryXML); using (results = query.RunOn(session)) { int count = 0; foreach (Row row in results.Rows) { Console.WriteLine(String.Join("\t", row.Select(d => d.ToString()))); count++; // Limit rows to 5000 for testing purposes. if (count > 5000) { break; } } } } } catch (TenTenSDK.Exceptions.TenTenException exc) { Console.Error.WriteLine("1010 Exception occurred: " + exc.ToString()); } }}

Page 22: 1010data .NET SDK User's Guide › documentationcenter › prod › 1010data… · A 1010data Insights Platform session is an instance of a particular user ID logged into the platform

1010data .NET SDK User's Guide | Reference | 22

Reference

The 1010data .NET SDK Reference contains detailed information about its classes and methods.

For more information, refer to the 1010data .NET SDK Reference.

Page 23: 1010data .NET SDK User's Guide › documentationcenter › prod › 1010data… · A 1010data Insights Platform session is an instance of a particular user ID logged into the platform

1010data .NET SDK User's Guide | Support requests | 23

Support requests

If you are using the 1010data Insights Platform SDKs, 1010data offers full support.

Including information such as the log file generated by the .NET SDK or the source code containing theproblems enables 1010data to respond more effectively to your request.

Include a log fileYou must submit a log file with your support request. The .NET SDK includes a feature to turn on logging.Use the Session constructor that includes the logPath parameter. Specify the logPath and appendvalue, and reproduce the issue. Include the log file in your support request.new Session(gateway, username, password, loginType, logPath, append)The logPath specifies the file path of where to write the log. The append parameter determines if thenewly logged information is appended to the log (true) or overwrites the log (false).

Include additional informationTo expedite the support process, include any:

• Runtime error messages• Stack traces• Core dumps• Exceptions

Include source codeCreating or isolating standalone source code is not always feasible, however sending in source codegreatly expedites the support process. Wherever possible, send reproducible source code that can be runand tested.