ignite-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Pavel Tupitsyn (JIRA)" <j...@apache.org>
Subject [jira] [Created] (IGNITE-3630) .NET: Add pure binary mode example with SQL
Date Fri, 05 Aug 2016 09:57:20 GMT
Pavel Tupitsyn created IGNITE-3630:
--------------------------------------

             Summary: .NET: Add pure binary mode example with SQL
                 Key: IGNITE-3630
                 URL: https://issues.apache.org/jira/browse/IGNITE-3630
             Project: Ignite
          Issue Type: Improvement
          Components: platforms
            Reporter: Pavel Tupitsyn
             Fix For: 1.8


This is an important Ignite use case: having no classes at all, working with cache in binary
mode and running SQL queries.

Below is a piece of code that I used for Gitter user question:
{code}
using (var ignite = Ignition.Start())
{
	// Configure queries for Person object with FirstName, LastName fields
	var cacheConfig = new CacheConfiguration
	{
		Name = "persons",  // can be anything
		QueryEntities = new[]
		{
			new QueryEntity
			{
				KeyType = typeof(int),
				ValueTypeName = "Person",  // name of the dynamically created type
				Fields = new[]  // define fields to be available in queries
				{
					new QueryField("FirstName", typeof(string)),
					new QueryField("LastName", typeof(string))
				}
			}
		}
	};
	
    // Create new cache, switch to binary mode
    var cache = ignite.CreateCache<int, object>(cacheConfig).WithKeepBinary<int,
IBinaryObject>();

	// Populate the cache
	for (var i = 0; i < 10; i++)
	{
		var person = ignite.GetBinary().GetBuilder("Person")  // same name as in ValueTypeName above
			.SetField<string>("FirstName", "Name-" + i)
			.SetField<string>("LastName", "LastName-" + i)
			.Build();
			
			cache[i] = person;
    }
	
	// SQL query for FirstName ending with "-3"
	var qry = cache.Query(new SqlQuery("Person", "where FirstName like '%-3'"));

	foreach (ICacheEntry<int, IBinaryObject> cacheEntry in qry)
	{
		Console.WriteLine("Person {0}:", cacheEntry.Key);
		
		IBinaryObject person = cacheEntry.Value;
		
		IBinaryType personType = person.GetBinaryType();
		
		// Show all fields
		foreach (var fieldName in personType.Fields)
			Console.WriteLine("  {0}: {1}", fieldName, person.GetField<object>(fieldName));
	}
}
{code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message