Frage

I'm trying to access a map column type using Astyanax. From the examples I've taken the following. I'm looping the rows and can get the data from all the columns except the column storename which has datatype MAP. I assume I need to loop over the elements of the map to get the data into my object but I can't figure out how to do get the map data from the column.

I'm trying column.getValue and have tried getByteBuffer but can't get either to work. I can get a column object and I see there is a ColumnMap interface but I can't figure out how to get the data into an object that extends or uses it. I also see a MapSerializer interfaces but not sure how to implement that either...

        List<Store> stores = new ArrayList<Store>();

        for (Row<Integer, String> row : result.getResult().getRows()) {

            Store store = new Store();

            ColumnList<String> columns = row.getColumns();

            store.setStoreID(columns.getStringValue("store_id", null));
            store.setShopName(columns.getStringValue("shopname", null));

            // lost trying to get the columns Map data here
            // should I loop the map or pass the data straight to my store object as a map?
            // How do I access the map data in this column?
            for ( Map<String, String> map : columns.getValue("storename", imap, result).getResult() )
            {
                store.setStoreNames( "lang", "storename");
            }

            stores.add(store);
        }

I'm a bit confused with getValue() as it takes a Serializer as it's 2nd argument and a default as it's 3rd. How do I pass the MapSerializer in as the 2nd argument or should I even be using getValue() method? Is the default a key value from the Map? If I want to return all values in the map what then? Thanks.

War es hilfreich?

Lösung

In the end this worked for me. And I was able to loop through the entries in the Map using the technique provided for looping maps here.

Map<String, String> map = columns.getValue("storename", 
                    new MapSerializer<String, String>(UTF8Type.instance, UTF8Type.instance)
                    , new HashMap<String ,String>());
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top