[ 
https://issues.apache.org/jira/browse/AVRO-680?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14088027#comment-14088027
 ] 

Sachin Goyal commented on AVRO-680:
-----------------------------------

I am not sure how to find that the given map has non-string map-keys in isMap() 
and isArray() functions.
This is because the type information of a parameterized map-object is lost due 
to type-erasure.

Consider the following code:
{code}
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.util.Map;
import java.util.HashMap;

public class NonStringMapTest
{
    public static void main (String args[]) throws Exception
    {
        NSMFoo obj = new NSMFoo();
        Field field = obj.getClass().getDeclaredFields()[0];
        Class<?> type = field.getType();
        ParameterizedType pt = (ParameterizedType)field.getGenericType();
        Object map = field.get(obj);
        System.out.println ("Field: " + field);
        System.out.println ("Type: " + type);
        System.out.println ("GenericType (Field): " + pt);
        System.out.println ("Class (Datum): " + map.getClass());
    }
}

class NSMFoo
{
    Map <NSMKey, String> map = new HashMap<NSMKey, String>();
}

class NSMKey
{
    int i;
}
{code}

And the output from it is:
{code}
Field: java.util.Map reflection.NSMFoo.map
Type: interface java.util.Map
GenericType (Field): java.util.Map<reflection.NSMKey, java.lang.String>
Class (Datum): class java.util.HashMap
{code}

The isMap and isArray functions are receiving just the datum and no Field 
object.
If there is a way to deduce that the given map datum has non-string keys, then 
I can add that logic in those functions.

I don't think passing the Field object all the way to isArray and isMap would 
be good.
What do you think?

> Allow for non-string keys
> -------------------------
>
>                 Key: AVRO-680
>                 URL: https://issues.apache.org/jira/browse/AVRO-680
>             Project: Avro
>          Issue Type: Improvement
>    Affects Versions: 1.7.6, 1.7.7
>            Reporter: Jeremy Hanna
>         Attachments: AVRO-680.patch, non_string_map_keys.zip, 
> non_string_map_keys2.zip, non_string_map_keys3.zip, 
> non_string_map_keys4.patch, non_string_map_keys5.patch
>
>
> Based on an email thread back in April, Doug Cutting proposed a possible 
> solution for having non-string keys:
> Stu Hood wrote:
> > I can understand the reasoning behind AVRO-9, but now I need to look for an 
> > alternative to a 'map' that will allow me to store an association of bytes 
> > keys to values.
> A map of Foo has the same binary format as an array of records, each
> with a string field and a Foo field.  So an application can use an array
> schema similar to this to represent map-like structures with, e.g.,
> non-string keys.
> Perhaps we could establish standard properties that indicate that a
> given array of records should be represented in a map-like way if
> possible?  E.g.,:
> {"type": "array", "isMap": true, "items": {"type":"record", ...}}
> Doug



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to