You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by edwardkblk <ed...@blackrock.com> on 2016/04/01 21:26:50 UTC

How to configure user data type for sql queries?

One of my cache fields is a custom type MyCustomDateType implements
Serializable, Comparable.  How can I map this type to be able to query via
sql?

I have tried the following, but was not able to get the sql result.  H2
Console shows the column data type for this field as 1111 (OTHER):

/
<bean class="org.apache.ignite.cache.QueryEntity">
	<property name="keyType" value="MyKey"/>
	<property name="valueType" value="MyObj"/>
			
	<property name="fields">
		<map>
		<entry key="id" value="java.lang.Integer"/>
		<entry key="type" value="MyCustomDataType"/>	                        
		</map>
	</property>
			
	<property name="indexes">
		<list>
		<bean class="org.apache.ignite.cache.QueryIndex">
			<constructor-arg> 
			        <map>
			         <entry key="id" value="true"/>
			         <entry key="type" value="false"/>
                                 ....

String sql = "id = ? and type  <= ? ";

SqlQuery<AffinityKey&lt;MyKey>, MyObj> q = new SqlQuery<>(MyObj.class, sql);
q.setArgs(123, new MyCustomDataType("zzz");

List<Entry&lt;AffinityKey&lt;MyKey>, MyObj>> l = cache.query(q).getAll();
//<- no results
/



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/How-to-configure-user-data-type-for-sql-queries-tp3867.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: How to configure user data type for sql queries?

Posted by vkulichenko <va...@gmail.com>.
Kamal,

Generally, binary format is recommended for all use cases.
OptimizedMarshaller implements legacy serialization format, it's also
compact and efficient, but requires to have classes on all nodes and do not
support dynamic schema changes. If there are any limitations in binary
format, most likely they are just bugs that should be fixed (like the one
described above).

JDK marshaller is just a wrapper around native Java serialization, it's used
very rarely.

-Val



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/How-to-configure-user-data-type-for-sql-queries-tp3867p4190.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: How to configure user data type for sql queries?

Posted by Kamal C <ka...@gmail.com>.
Val,

Can you explain with use-case when to use Binary, Optimized, GridOptimized
and JDK Marshallers ?

--Kamal

On Tue, Apr 5, 2016 at 3:41 AM, edwardkblk <ed...@blackrock.com>
wrote:

> Yes, it works with OptimizedMarshaller.  Thank you.
>
>
>
> --
> View this message in context:
> http://apache-ignite-users.70518.x6.nabble.com/How-to-configure-user-data-type-for-sql-queries-tp3867p3912.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>

Re: How to configure user data type for sql queries?

Posted by edwardkblk <ed...@blackrock.com>.
Yes, it works with OptimizedMarshaller.  Thank you.



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/How-to-configure-user-data-type-for-sql-queries-tp3867p3912.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: How to configure user data type for sql queries?

Posted by vkulichenko <va...@gmail.com>.
Hi,

This is currently not supported with binary format, which is default. There
is a ticket to fix this: https://issues.apache.org/jira/browse/IGNITE-2208

As a workaround you can switch to OptimizedMarshaller. Add this to your
configuration:

    <property name="marshaller">
        <bean
class="org.apache.ignite.marshaller.optimized.OptimizedMarshaller"/>
    </property>

Let me know if it helps.

-Val





--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/How-to-configure-user-data-type-for-sql-queries-tp3867p3871.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.