【问题标题】:Astyanax map data access cql3Astyanax地图数据访问cql3
【发布时间】:2013-04-04 07:23:29
【问题描述】:

我正在尝试使用 Astyanax 访问地图列类型。 从我已经采取以下的例子。我正在循环这些行,并且可以从所有列中获取数据,除了具有数据类型 MAP 的列存储名称。我假设我需要遍历地图的元素以将数据放入我的对象中,但我不知道如何从列中获取地图数据。

我正在尝试 column.getValue 并尝试过 getByteBuffer 但都无法正常工作。我可以获得一个列对象,我看到有一个 ColumnMap 接口,但我不知道如何将数据放入扩展或使用它的对象中。我还看到了 MapSerializer 接口,但不知道如何实现它......

        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);
        }

我对 getValue() 有点困惑,因为它需要一个 Serializer 作为它的第二个参数和一个默认值作为它的第三个参数。如何将 MapSerializer 作为第二个参数传递,或者我什至应该使用 getValue() 方法?默认值是 Map 中的键值吗?如果我想返回地图中的所有值,那该怎么办?谢谢。

【问题讨论】:

    标签: map cassandra astyanax cql3


    【解决方案1】:

    最后这对我有用。我能够使用为looping maps here. 提供的技术循环遍历地图中的条目

    Map<String, String> map = columns.getValue("storename", 
                        new MapSerializer<String, String>(UTF8Type.instance, UTF8Type.instance)
                        , new HashMap<String ,String>());
    

    【讨论】:

      猜你喜欢
      • 2013-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-09
      • 1970-01-01
      • 2019-08-08
      • 1970-01-01
      • 2013-05-15
      相关资源
      最近更新 更多