You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by arthi <Ar...@nielsen.com> on 2016/03/09 07:02:18 UTC

C++ Client for SQL Queries

Hi,

We need to get a C++ client to run SQL queries on caches built from our
server ignite components.
I am not seeing an example for this in the GIT HUB, can you please help? I
need to understand how the objects are defined for SQL queries (query
entities or annotations) and how they are indexed in the configuration.

Thanks,
Arthi



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/C-Client-for-SQL-Queries-tp3407.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: C++ Client for SQL Queries

Posted by arthi <Ar...@nielsen.com>.
Thanks Igor. I used your master version of the header file and it worked!

Thanks for all your help.

Arthi



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/C-Client-for-SQL-Queries-tp3407p3433.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: C++ Client for SQL Queries

Posted by Igor Sapego <is...@gridgain.com>.
Arthi,

It is known issue [1]. It has been fixed already and this fix is going to be
included to the next release. You can try using code from master brach
or as a workaround you can try using no-throw method version instead
i.e. QueryFieldsRow::GetNext(IgniteError& err).

[1] - https://issues.apache.org/jira/browse/IGNITE-2652

Best Regards,
Igor

On Thu, Mar 10, 2016 at 1:31 PM, arthi <Ar...@nielsen.com>
wrote:

> Thanks Igor. It works!
>
> I am able to read the values from the cache using the C++ client.
>
> when I print the values from QueryFieldsCursor, I get a compilation error.
> This code follows your examples -
> Cache<int, Person> cache = grid.GetOrCreateCache<int, Person>("myCache");
>
> SqlFieldsQuery qry(
>   "select concat(FirstName, ' ', LastName), Organization.Name "
>   "from Person, Organization where "
>   "Person.OrgId = Organization.Id and "
>   "Person.Salary > ?");
>
> qry.AddArgument(1000);
>
> QueryFieldsCursor cursor = cache.Query(qry);
>
> // Iterate over results.
> while (cursor.HasNext())
> {
>   QueryFieldsRow row = cursor.GetNext();
>
>   std::cout << row.GetNext<std::string>() << " "
>             << row.GetNext<std::string>() << std::endl;
> }
>
>
> apache-ignite-fabric\platforms\cpp\core\include\ignite/cache/query/query_fields_row.h(112):
> error C2440: 'initializing' : cannot convert from 'std::string' to
> 'ignite::cache::query::QueryFieldsRow'
>
> Am I doing something wrong?
>
> thanks for all your help....
> Arthi
>
>
>
> --
> View this message in context:
> http://apache-ignite-users.70518.x6.nabble.com/C-Client-for-SQL-Queries-tp3407p3430.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>

Re: C++ Client for SQL Queries

Posted by arthi <Ar...@nielsen.com>.
Thanks Igor. It works!

I am able to read the values from the cache using the C++ client.

when I print the values from QueryFieldsCursor, I get a compilation error.
This code follows your examples -
Cache<int, Person> cache = grid.GetOrCreateCache<int, Person>("myCache");

SqlFieldsQuery qry(
  "select concat(FirstName, ' ', LastName), Organization.Name "
  "from Person, Organization where "
  "Person.OrgId = Organization.Id and "
  "Person.Salary > ?");

qry.AddArgument(1000);

QueryFieldsCursor cursor = cache.Query(qry);

// Iterate over results.
while (cursor.HasNext())
{
  QueryFieldsRow row = cursor.GetNext();

  std::cout << row.GetNext<std::string>() << " " 
            << row.GetNext<std::string>() << std::endl;
}

apache-ignite-fabric\platforms\cpp\core\include\ignite/cache/query/query_fields_row.h(112):
error C2440: 'initializing' : cannot convert from 'std::string' to
'ignite::cache::query::QueryFieldsRow'

Am I doing something wrong?

thanks for all your help....
Arthi



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/C-Client-for-SQL-Queries-tp3407p3430.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: C++ Client for SQL Queries

Posted by Igor Sapego <is...@gridgain.com>.
Arthi,

You can just put your additional libraries to $IGNITE_HOME/libs directory.

Best Regards,
Igor

On Thu, Mar 10, 2016 at 7:56 AM, arthi <Ar...@nielsen.com>
wrote:

> Thanks Igor.
>
> Well, I tried using a cache config in the XML to start my C++ client. but,
> the factory store is not visible to the JNI.
> <bean class="org.apache.ignite.configuration.CacheConfiguration">
>                                         <property name="name"
> value="SHOP_ITEM_BITMAP_CACHE" />
>                                         <property name="cacheMode"
> value="PARTITIONED" />
>                                         <property name="cacheStoreFactory">
>                                                 <bean
> class="javax.cache.configuration.FactoryBuilder$SingletonFactory">
>                                                   <constructor-arg>
>                                                         <bean
>
> class="com.nielsen.poc.aggregation.ignite.datagrid.store.ShopItemBitmapStore">
>                                                         </bean>
>                                                   </constructor-arg>
>                                                 </bean>
>                                         </property>
>                                         <property name="queryEntities">
>                                                 ...
>                                         </property>
>                                 </bean>
>
>
> The error is -
>  nested exception is java.lang.ClassNotFoundException:
> com.nielsen.poc.aggregation.ignite.datagrid.store.ShopItemBitmapStore
>
> Seems like a class path issue. Is there a way I can pass on my additional
> libraries to the C++ client?
> I tried the VS2010 -> project properties -> Linker -> General -> Additional
> Library Directories.
> It did not work.
>
> I also tried to set the
> std::string stdOpt =
> "-Djava.class.path=C:/../aggregation-0.0.1-SNAPSHOT.jar;";
> in the C++ class, that also did not work.
>
> Can you please help?
>
> Thanks,
> Arthi
>
>
>
> --
> View this message in context:
> http://apache-ignite-users.70518.x6.nabble.com/C-Client-for-SQL-Queries-tp3407p3427.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>

Re: C++ Client for SQL Queries

Posted by arthi <Ar...@nielsen.com>.
Thanks Igor.

Well, I tried using a cache config in the XML to start my C++ client. but,
the factory store is not visible to the JNI.
<bean class="org.apache.ignite.configuration.CacheConfiguration">
					<property name="name" value="SHOP_ITEM_BITMAP_CACHE" />	
					<property name="cacheMode" value="PARTITIONED" />
					<property name="cacheStoreFactory">
						<bean
class="javax.cache.configuration.FactoryBuilder$SingletonFactory">
						  <constructor-arg>
							<bean
class="com.nielsen.poc.aggregation.ignite.datagrid.store.ShopItemBitmapStore">								 
							</bean>
						  </constructor-arg>
						</bean>
					</property> 
					<property name="queryEntities">
						...
					</property>
				</bean>


The error is -
 nested exception is java.lang.ClassNotFoundException:
com.nielsen.poc.aggregation.ignite.datagrid.store.ShopItemBitmapStore

Seems like a class path issue. Is there a way I can pass on my additional
libraries to the C++ client?
I tried the VS2010 -> project properties -> Linker -> General -> Additional
Library Directories.
It did not work.

I also tried to set the 
std::string stdOpt =
"-Djava.class.path=C:/../aggregation-0.0.1-SNAPSHOT.jar;";
in the C++ class, that also did not work. 

Can you please help?

Thanks,
Arthi



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/C-Client-for-SQL-Queries-tp3407p3427.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: C++ Client for SQL Queries

Posted by Igor Sapego <is...@gridgain.com>.
Well, in short, you do not need to do any additional steps if you has not
explicitly set any other marshaller for your grid.

Ignite uses marshaller to serialize and de-serialize objects. There are
different marshallers that Apache Ignite supports. They define format
of the serialized objects. In order to be able to de-serialize objects
using C++ client BinaryMarshaller should be used. By default if you
did not explicitly set some other marshaller BinaryMarshaller is used.

You can read more about binary marshaller at the documentation [1].

Also, you should not use withKeepBinary() method as it intended to
be used for other purposes and you should not perform any additional
steps on C++ client.

[1] - https://apacheignite.readme.io/docs/binary-marshaller

Best Regards,
Igor

On Wed, Mar 9, 2016 at 4:34 PM, arthi <Ar...@nielsen.com>
wrote:

> Thank you! This sounds promising...
>
> I went through your BinaryMarshaller. If I understand rightly, when I build
> the cache in Java, I can place the objects as they are (just that the Pojo
> need to be serializable). But, in the C++ client, I will need to invoke the
> cache with binary - somthing like -
> // Get an instance of binary-enabled cache.
> IgniteCache<Integer, BinaryObject> binaryCache =
> ignite.cache("myCache").withKeepBinary();
>
> am I right ? I also saw my cache entries using visor, and they appear to be
> o.a.i.i.binary.BinaryObjectImpl.
>
> Do you have a sample using C++ API please? I dont see it in the git hub.
>
> Thanks for all the help,
> Arthi
>
>
>
> --
> View this message in context:
> http://apache-ignite-users.70518.x6.nabble.com/C-Client-for-SQL-Queries-tp3407p3418.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>

Re: C++ Client for SQL Queries

Posted by arthi <Ar...@nielsen.com>.
Thank you! This sounds promising...

I went through your BinaryMarshaller. If I understand rightly, when I build
the cache in Java, I can place the objects as they are (just that the Pojo
need to be serializable). But, in the C++ client, I will need to invoke the
cache with binary - somthing like -
// Get an instance of binary-enabled cache.
IgniteCache<Integer, BinaryObject> binaryCache =
ignite.cache("myCache").withKeepBinary();

am I right ? I also saw my cache entries using visor, and they appear to be
o.a.i.i.binary.BinaryObjectImpl.

Do you have a sample using C++ API please? I dont see it in the git hub.

Thanks for all the help,
Arthi



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/C-Client-for-SQL-Queries-tp3407p3418.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: C++ Client for SQL Queries

Posted by Igor Sapego <is...@gridgain.com>.
Arthi,

The short answer to all your questions is "yes" - C++ client is able to
de-serialize Java objects if you are using BinaryMarshaller and it is
also able to trigger read-through requests to Java factory store if there
are cache misses.


Best Regards,
Igor

On Wed, Mar 9, 2016 at 2:35 PM, arthi <Ar...@nielsen.com>
wrote:

> Thanks Igor.
>
> I could get the C++ code work with the sample XML configuration.
>
> One more question. Can the C++ client see the objects in a cache populated
> by a Java server node?
> I have Java server that creates the cache with objects and the cache is
> connected to a persistent  store on top of a RDBMS. I configured this cache
> to be a "read-through" cache.
> Will the query from the C++ client be able to de-serialize the Java binary
> objects? and also trigger read-through requests to Java factory store if
> there are cache misses?
>
> Thanks,
> Arthi
>
>
>
> --
> View this message in context:
> http://apache-ignite-users.70518.x6.nabble.com/C-Client-for-SQL-Queries-tp3407p3416.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>

Re: C++ Client for SQL Queries

Posted by arthi <Ar...@nielsen.com>.
Thanks Igor.

I could get the C++ code work with the sample XML configuration.

One more question. Can the C++ client see the objects in a cache populated
by a Java server node? 
I have Java server that creates the cache with objects and the cache is
connected to a persistent  store on top of a RDBMS. I configured this cache
to be a "read-through" cache. 
Will the query from the C++ client be able to de-serialize the Java binary
objects? and also trigger read-through requests to Java factory store if
there are cache misses?

Thanks,
Arthi



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/C-Client-for-SQL-Queries-tp3407p3416.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: C++ Client for SQL Queries

Posted by Igor Sapego <is...@gridgain.com>.
Hello, Arthi

Your assumption is correct, in order to run queries you need to use proper
configuration
with "queryEntities" property defined for the cache as described in
documentation [1].

For the "Organization" type that you mentioned it should contain at least
the following:

<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="name" value="CacheName"/>

<property name="queryEntities">
<list>
<bean class="org.apache.ignite.cache.QueryEntity">
<property name="keyType" value="java.lang.Integer"/>
<property name="valueType" value="Organization"/>
<property name="fields">
<map>
<entry key="name" value="java.lang.String"/>
<entry key="addr" value="Address"/>
</map>
</property>
</bean>
</list>
</property>
</bean>

After that you can get "CacheName" cache and run queries on it using fields
that
you have declared in "queryEntities".

Hope it helps.

[1] -
https://apacheignite-cpp.readme.io/docs/sql-queries#query-configuration-using-queryentity

Best Regards,
Igor

On Wed, Mar 9, 2016 at 10:06 AM, arthi <Ar...@nielsen.com>
wrote:

> Thanks Vladimir.
>
> I did have a look at the URLs, and also your examples in git hub. I am
> using
> the organization.h in the git hub and want to just run a SQL query on a
> cache with Organization objects.
> I get this error -
>  Indexing is disabled for cache: myCache. Use setIndexedTypes or
> setTypeMetadata methods on CacheConfiguration to enable.
>
> I assume this is to do with the XML config (Query Entities ) I need to
> define in the
> platforms/cpp/examples/config/example-cache.xml.
>
> Can you please give me a sample for this?
>
> I am doing good with the Java API, I had used @QuerySqlField annotations in
> my Java code, and could build up the caches. But, I need to have a C++
> client to read this data, as my application is in C++.
>
> Pls let me know if I am missing something.
>
> Thanks,
> Arthi
>
>
>
> --
> View this message in context:
> http://apache-ignite-users.70518.x6.nabble.com/C-Client-for-SQL-Queries-tp3407p3411.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>

Re: C++ Client for SQL Queries

Posted by arthi <Ar...@nielsen.com>.
Thanks Vladimir.

I did have a look at the URLs, and also your examples in git hub. I am using
the organization.h in the git hub and want to just run a SQL query on a
cache with Organization objects.
I get this error -
 Indexing is disabled for cache: myCache. Use setIndexedTypes or
setTypeMetadata methods on CacheConfiguration to enable.

I assume this is to do with the XML config (Query Entities ) I need to
define in the 
platforms/cpp/examples/config/example-cache.xml.

Can you please give me a sample for this?

I am doing good with the Java API, I had used @QuerySqlField annotations in
my Java code, and could build up the caches. But, I need to have a C++
client to read this data, as my application is in C++.

Pls let me know if I am missing something.

Thanks,
Arthi



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/C-Client-for-SQL-Queries-tp3407p3411.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: C++ Client for SQL Queries

Posted by Vladimir Ozerov <vo...@gridgain.com>.
Hi Arthi,

Please have a look at Ignite C++ documentation about indexes and
serialization:
https://apacheignite-cpp.readme.io/docs/sql-queries
https://apacheignite-cpp.readme.io/docs/serialization

Let me know if you have any further questions.

We will add more SQL examples for C++ in the nearest time.

Vladimir.


On Wed, Mar 9, 2016 at 9:02 AM, arthi <Ar...@nielsen.com>
wrote:

> Hi,
>
> We need to get a C++ client to run SQL queries on caches built from our
> server ignite components.
> I am not seeing an example for this in the GIT HUB, can you please help? I
> need to understand how the objects are defined for SQL queries (query
> entities or annotations) and how they are indexed in the configuration.
>
> Thanks,
> Arthi
>
>
>
> --
> View this message in context:
> http://apache-ignite-users.70518.x6.nabble.com/C-Client-for-SQL-Queries-tp3407.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>