You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by mamaco <ma...@163.com> on 2018/01/21 20:27:05 UTC

Option meta schema in cache level?

I'm trying to use Binary Marshaller to replace old OptimizedMarshaller which
is really a pain for deployment.
But according to document of Type Metadata, it could be changed at runtime,
that means if I access to a 3rd party cache which was created by someone
else without explicit type settings, I'll have to get a sample row to
retrieve its type manually prior to further operations. is this correct? why
not just set a default optional meta type in cache level? as an option, it
won't be negative for dynamic row schema.



#access to a cache 'SQL_PUBLIC_CITY' (created by JDBC 'Create Table'
statement) and do some normal operations.
#GetSchema() is weird

public class App 
{
	private static SchemaType schema=null;
    public static void main( String[] args )
    {
    	Ignite ignite =
Ignition.start("C://apache//ignite//apache-ignite-fabric-2.2.0-bin//config//client.xml");   	
    	CacheConfiguration<BinaryObject, BinaryObject> cfg = new
CacheConfiguration<BinaryObject, BinaryObject>("SQL_PUBLIC_CITY");
    	IgniteCache<BinaryObject, BinaryObject> cache =
ignite.getOrCreateCache(cfg).withKeepBinary();
    	
    	if(schema==null) schema=GetSchema(cache);
    	Put(ignite,cache,4L,"Los Angeles");
    	GetAll(cache);
    	Get(ignite,cache,4L);
    	Query(cache,4L);
    	ignite.close();
    }
    
    public static void GetAll(IgniteCache<BinaryObject, BinaryObject> cache)
{
    	Iterator<Cache.Entry&lt;BinaryObject, BinaryObject>>  itr =
cache.iterator();
    	while(itr.hasNext()){
    		Cache.Entry<BinaryObject, BinaryObject> item = itr.next();
    		System.out.println("id="+item.getKey().field("id")+" 
KeyType="+item.getKey().type().typeName().toString()+" 
V="+item.getKey().type().field("id"));
    		System.out.println("CITY="+item.getValue().field("name")+ "  of
id="+item.getValue().field("id"));
    	}
    }
    
    public static SchemaType GetSchema(IgniteCache<BinaryObject,
BinaryObject> cache) {
    	SchemaType sch=new SchemaType();
		Cache.Entry<BinaryObject, BinaryObject> item = cache.iterator().next();
		sch.KeyType=item.getKey().type().typeName();
		sch.KeyFields=item.getKey().type().fieldNames();
		sch.ValueType=item.getValue().type().typeName();
		sch.ValueFields=item.getValue().type().fieldNames();
    	return sch;
    }
    
    
    
    public static void Get(Ignite ignite, IgniteCache<BinaryObject,
BinaryObject> cache, Long CityId) {
        BinaryObjectBuilder keyBuilder =
ignite.binary().builder(schema.KeyType)
                .setField("id", CityId);
        
        BinaryObject value = cache.get(keyBuilder.build());
    	if(value!=null) System.out.println("CITY="+value.field("name"));
    }
    
    public static void Put(Ignite ignite, IgniteCache<BinaryObject,
BinaryObject> cache,Long CityId,String CityName) {
        BinaryObjectBuilder keyBuilder =
ignite.binary().builder(schema.KeyType)
                .setField("id", CityId);
        BinaryObjectBuilder valueBuilder =
ignite.binary().builder(schema.ValueType)
                .setField("name", CityName);
        
        cache.put(keyBuilder.build(),valueBuilder.build());
    }
    
    public static void Query(IgniteCache<BinaryObject, BinaryObject> cache,
Long CityId) {
        QueryCursor<List&lt;?>> query = cache.query(new
SqlFieldsQuery("select * from City where id="+CityId));
        System.out.println(query.getAll());
    }
}






--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: Optional meta schema in cache level?

Posted by mcherkasov <mc...@gridgain.com>.
Hi Mamaco

I filed an improvement request for data types:
https://issues.apache.org/jira/browse/IGNITE-7607

Could you please review it and add couple lines about your case to JIRA?

Thanks,
Mike.



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: Optional meta schema in cache level?

Posted by "ilya.kasnacheev" <il...@gmail.com>.
Hello!

So you are suggesting to store types of keys and values which are supposed
to be stored in cache?

I think it is already present, as cacheConfiguration.queryEntities[].keyType
and cacheConfiguration.queryEntities[].valType.

They're not always present, but they often are. They're somewhat tied to SQL
but don't really carry much overhead otherwise.

Note that they're strings which are not guaranteed to be a valid class name.

Regards.



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: Option meta schema in cache level?

Posted by Andrey Mashenkov <an...@gmail.com>.
Hi,

To get metadata prior to iterating over cursor, you can try to cast cursor
to internal class QueryCursorImpl and call #fieldsMetadata().


On Sun, Jan 21, 2018 at 11:27 PM, mamaco <ma...@163.com> wrote:

> I'm trying to use Binary Marshaller to replace old OptimizedMarshaller
> which
> is really a pain for deployment.
> But according to document of Type Metadata, it could be changed at runtime,
> that means if I access to a 3rd party cache which was created by someone
> else without explicit type settings, I'll have to get a sample row to
> retrieve its type manually prior to further operations. is this correct?
> why
> not just set a default optional meta type in cache level? as an option, it
> won't be negative for dynamic row schema.
>
>
>
> #access to a cache 'SQL_PUBLIC_CITY' (created by JDBC 'Create Table'
> statement) and do some normal operations.
> #GetSchema() is weird
>
> public class App
> {
>         private static SchemaType schema=null;
>     public static void main( String[] args )
>     {
>         Ignite ignite =
> Ignition.start("C://apache//ignite//apache-ignite-fabric-
> 2.2.0-bin//config//client.xml");
>         CacheConfiguration<BinaryObject, BinaryObject> cfg = new
> CacheConfiguration<BinaryObject, BinaryObject>("SQL_PUBLIC_CITY");
>         IgniteCache<BinaryObject, BinaryObject> cache =
> ignite.getOrCreateCache(cfg).withKeepBinary();
>
>         if(schema==null) schema=GetSchema(cache);
>         Put(ignite,cache,4L,"Los Angeles");
>         GetAll(cache);
>         Get(ignite,cache,4L);
>         Query(cache,4L);
>         ignite.close();
>     }
>
>     public static void GetAll(IgniteCache<BinaryObject, BinaryObject>
> cache)
> {
>         Iterator<Cache.Entry&lt;BinaryObject, BinaryObject>>  itr =
> cache.iterator();
>         while(itr.hasNext()){
>                 Cache.Entry<BinaryObject, BinaryObject> item = itr.next();
>                 System.out.println("id="+item.getKey().field("id")+"
> KeyType="+item.getKey().type().typeName().toString()+"
> V="+item.getKey().type().field("id"));
>                 System.out.println("CITY="+item.getValue().field("name")+
> "  of
> id="+item.getValue().field("id"));
>         }
>     }
>
>     public static SchemaType GetSchema(IgniteCache<BinaryObject,
> BinaryObject> cache) {
>         SchemaType sch=new SchemaType();
>                 Cache.Entry<BinaryObject, BinaryObject> item =
> cache.iterator().next();
>                 sch.KeyType=item.getKey().type().typeName();
>                 sch.KeyFields=item.getKey().type().fieldNames();
>                 sch.ValueType=item.getValue().type().typeName();
>                 sch.ValueFields=item.getValue().type().fieldNames();
>         return sch;
>     }
>
>
>
>     public static void Get(Ignite ignite, IgniteCache<BinaryObject,
> BinaryObject> cache, Long CityId) {
>         BinaryObjectBuilder keyBuilder =
> ignite.binary().builder(schema.KeyType)
>                 .setField("id", CityId);
>
>         BinaryObject value = cache.get(keyBuilder.build());
>         if(value!=null) System.out.println("CITY="+value.field("name"));
>     }
>
>     public static void Put(Ignite ignite, IgniteCache<BinaryObject,
> BinaryObject> cache,Long CityId,String CityName) {
>         BinaryObjectBuilder keyBuilder =
> ignite.binary().builder(schema.KeyType)
>                 .setField("id", CityId);
>         BinaryObjectBuilder valueBuilder =
> ignite.binary().builder(schema.ValueType)
>                 .setField("name", CityName);
>
>         cache.put(keyBuilder.build(),valueBuilder.build());
>     }
>
>     public static void Query(IgniteCache<BinaryObject, BinaryObject>
> cache,
> Long CityId) {
>         QueryCursor<List&lt;?>> query = cache.query(new
> SqlFieldsQuery("select * from City where id="+CityId));
>         System.out.println(query.getAll());
>     }
> }
>
>
>
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>



-- 
Best regards,
Andrey V. Mashenkov