ignite-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ozgurnevres <ozgur.nev...@gmail.com>
Subject Re: How can I perform SqlFieldsQuery on DateTime field (binary cache)?
Date Mon, 27 Mar 2017 11:54:33 GMT
Hi, Pitupitsyn
Thanks for the quick reply!

After trying a bit more, I realized that there might be another problem.
Here my steps if you want to reproduce (Five steps total):

1- I downloaded Apache.Ignite.Examples sln and working on it.

2- On BinaryCodeExample.cs, I first added a DateTime field to Person like
below:

var cache0 = ignite.GetOrCreateCache<object, object>(new CacheConfiguration
{
	Name = CacheName,
	QueryEntities = new[]
	{
		new QueryEntity
		{
			KeyType = typeof(int),
			ValueTypeName = PersonType,
			Fields = new[]
			{
				new QueryField(NameField, typeof(string)),
				new QueryField(CompanyIdField, typeof(int)),
				new QueryField("birthday", typeof(DateTime))
			},
			Indexes = new[] {new QueryIndex(false, QueryIndexType.FullText,
NameField)}
		},
		new QueryEntity
		{
			KeyType = typeof(int),
			ValueTypeName = CompanyType,
			Fields = new[]
			{
				new QueryField(IdField, typeof(int)),
				new QueryField(NameField, typeof(string))
			}
		}
	}
});

// Switch to binary mode to work with data in serialized form.
var cache = cache0.WithKeepBinary<int, IBinaryObject>();

                // Clean up caches on all nodes before run.
                cache.Clear();

                // Populate cache with sample data entries.
                PopulateCache(cache);
				
                // Run SQL fields query example.
                SqlFieldsQueryExample(cache);

3- Then, I modified the PopulateCache method like below:

        private static void PopulateCache(ICache<int, IBinaryObject> cache)
        {
            IBinary binary = cache.Ignite.GetBinary();

            // Populate persons.
            cache[1] = binary.GetBuilder(PersonType)
                .SetField(NameField, "James Wilson")
                .SetField(CompanyIdField, -1)
                .SetField("birthday", new DateTime(1950, 1, 1))
                .Build();

            cache[2] = binary.GetBuilder(PersonType)
                .SetField(NameField, "Daniel Adams")
                .SetField(CompanyIdField, -1)
                .SetField("birthday", new DateTime(1960, 1, 1))
                .Build();

            cache[3] = binary.GetBuilder(PersonType)
                .SetField(NameField, "Cristian Moss")
                .SetField(CompanyIdField, -1)
                .SetField("birthday", new DateTime(1970, 1, 1))
                .Build();

            cache[4] = binary.GetBuilder(PersonType)
                .SetField(NameField, "Allison Mathis")
                .SetField(CompanyIdField, -2)
                .SetField("birthday", new DateTime(1980, 1, 1))
                .Build();

            cache[5] = binary.GetBuilder(PersonType)
                .SetField(NameField, "Breana Robbin")
                .SetField(CompanyIdField, -2)
                .SetField("birthday", new DateTime(1990, 1, 1))
                .Build();

            cache[6] = binary.GetBuilder(PersonType)
                .SetField(NameField, "Philip Horsley")
                .SetField(CompanyIdField, -2)
                .SetField("birthday", new DateTime(2000, 1, 1))
                .Build();

            cache[7] = binary.GetBuilder(PersonType)
                .SetField(NameField, "James Peters")
                .SetField(CompanyIdField, -2)
                .SetField("birthday", new DateTime(2010, 1, 1))
                .Build();

            // Populate companies.
            cache[-1] = binary.GetBuilder(CompanyType)
                .SetField(NameField, "Apache")
                .SetField(IdField, -1)
                .Build();

            cache[-2] = binary.GetBuilder(CompanyType)
                .SetField(NameField, "Microsoft")
                .SetField(IdField, -2)
                .Build();
        }

4- Finally, I changed the SqlFieldsQueryExample method like below:

        private static void SqlFieldsQueryExample(ICache<int, IBinaryObject>
cache)
        {
            var qry = cache.QueryFields(new SqlFieldsQuery("select name,
birthday from Person order by name"));

            Console.WriteLine();
            Console.WriteLine(">>> All person names:");

            foreach (IList row in qry)
                Console.WriteLine(">>>     " + row[0]);
        }

Please note that I only added "birthday" to the query text.
		
5- Then I get the error "Failed to run map query remotely"
	
	If I change the query to below, it works. So, I think, the problem is
"birthday" field, which is DateTime.
	var qry = cache.QueryFields(new SqlFieldsQuery("select name from Person
order by name"));



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/How-can-I-perform-SqlFieldsQuery-on-DateTime-field-binary-cache-tp11457p11469.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Mime
View raw message