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

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,
		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.

                // Populate cache with sample data entries.
                // Run SQL fields query example.

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))

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

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

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

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

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

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

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

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

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

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

            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.

View raw message