[ 
https://issues.apache.org/jira/browse/IGNITE-3630?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Pavel Tupitsyn updated IGNITE-3630:
-----------------------------------
    Description: 
This is an important Ignite use case: having no classes at all, working with 
cache in binary mode and running SQL queries.

We should have a dedicated example for this (regular one and for LINQPad).

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}

  was:
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}


> .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
>              Labels: .net
>             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.
> We should have a dedicated example for this (regular one and for LINQPad).
> 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)

Reply via email to