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
                            ]
                        ]
                    ]
                ]])
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥15 QT6颜色选择对话框显示不完整
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥15 DS18B20内部ADC模数转换器