duandang9434 2016-03-17 17:59
浏览 43
已采纳

如何使用duoshuo的PHP客户端库定义嵌套在UDT中的Cassandra CollectionMap?

I have a CollectionSet<UDT> where UDT contains a CollectionMap<int,boolean>. I have not been able to find any documentation or example of how to define this when creating a new Cassandra\Type\CollectionSet for inserting into the table. There is a great example with a CollectionList (found here) which is like this:

// CollectionSet<UDT>, where UDT contains: Int, Text, Boolean, 
// CollectionList<Text>, CollectionList<UDT>

new Cassandra\Type\CollectionSet([
    [
        'id' => 1,
        'name' => 'string',
        'active' => true,
        'friends' => ['string1', 'string2', 'string3'],
        'drinks' => [['qty' => 5, 'brand' => 'Pepsi'], ['qty' => 3, 'brand' => 'Coke']]
    ],[
        'id' => 2,
        'name' => 'string',
        'active' => false,
        'friends' => ['string4', 'string5', 'string6'],
        'drinks' => []
    ]
], [
    [
    'type' => Cassandra\Type\Base::UDT,
    'definition' => [
        'id' => Cassandra\Type\Base::INT,
        'name' => Cassandra\Type\Base::VARCHAR,
        'active' => Cassandra\Type\Base::BOOLEAN,
        'friends' => [
            'type' => Cassandra\Type\Base::COLLECTION_LIST,
            'value' => Cassandra\Type\Base::VARCHAR
        ],
        'drinks' => [
            'type' => Cassandra\Type\Base::COLLECTION_LIST,
            'value' => [
                'type' => Cassandra\Type\Base::UDT,
                'typeMap' => [
                    'qty' => Cassandra\Type\Base::INT,
                    'brand' => Cassandra\Type\Base::VARCHAR
                ]
            ]
        ]
    ]
]
]);

I've tried using the above example with several variations to accommodate the CollectionMap but nothing is working. My last attempt was this

new Cassandra\Type\CollectionSet($udt_array, [[
                'type'=>Cassandra\Type\Base::UDT,
                'definition' => [
                    'map_name' => [
                        'type' => Cassandra\Type\Base::COLLECTION_MAP,
                        'value' => [
                            Cassandra\Type\Base::INT,
                            Cassandra\Type\Base::BOOLEAN
                        ]
                    ]
                ]
            ]])

which gives the error Caught exception: Since v0.7, collection types should have \"definition\" directive. I've also tried using 'definition' instead of 'value'. I'm running out of ideas, any help would be greatly appreciated.

  • 写回答

1条回答 默认 最新

  • dsepcxw181184853 2016-03-21 20:03
    关注

    Use "definition" instead of "value". I tried this before but apparently I was doing something else wrong because this worked.

    new Cassandra\Type\CollectionSet($udt_array, [[
                    'type'=>Cassandra\Type\Base::UDT,
                    'definition' => [
                        'map_name' => [
                            'type' => Cassandra\Type\Base::COLLECTION_MAP,
                            'definition' => [
                                Cassandra\Type\Base::INT,
                                Cassandra\Type\Base::BOOLEAN
                            ]
                        ]
                    ]
                ]])
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器