Pycassa: как запросить части композитного типа

StackOverflow https://stackoverflow.com/questions/9526641

  •  15-11-2019
  •  | 
  •  

Вопрос

в основном я спрашиваю то же самое, что и в это Вопрос Но для библиотеки Python Cassandra, Pycassa.

Позволяет сказать, что у вас есть данные с композитным типом, хранящие данные, такие как это:

[20120228:finalscore] = '31-17'
[20120228:halftimescore]= '17-17'
[20120221:finalscore] = '3-14'
[20120221:halftimescore]= '3-0'
[20120216:finalscore] = '54-0'
[20120216:halftimescore]= '42-0'
.

Итак, я знаю, что я могу легко нарезать на основе первой части композитного типа, делая:

>>> cf.get('1234', column_start('20120216',), column_finish('20120221',))
OrderedDict([((u'20120216', u'finalscore'), u'54-0'),
((u'20120216', u'halftimescore'), u'42-0')])
.

Но если я хочу только финалкор, я бы предположил, что я мог бы сделать:

>>> cf.get('1234', column_start('20120216', 'finalscore'),
column_finish('20120221', 'finalscore'))
.

Чтобы получить:

OrderedDict([((u'20120216', u'finalscore'), u'54-0')])
.

Но вместо этого я получаю:

OrderedDict([((u'20120216', u'finalscore'), u'54-0'),
((u'20120216', u'halftimescore'), u'42-0')])
.

То же, что и 1-й вызов.

Я делаю что-то не так? Должна ли эта работа? Или есть какой-то синтаксис с использованием CF.Get (... Columns= [('20120216', 'finalscore')])? Я тоже пробовал и получил исключение.

Согласно http://www.datastaxax .com / dev / blog / Введение-к-композит-столбцы-части-1 , я должен быть в состоянии сделать что-то подобное ...

Спасибо

Это было полезно?

Решение

If know all the components of the composite column then you should the 'columns' option:

cf.get('1234', columns=[('20120216', 'finalscore')])

You said you got an error trying to do this, but I would suggest trying again. It works fine for me.

When you are slicing composite columns you need to think about how they are sorted. Composite columns sort starting first with the left most component, and then sorting each component toward the right. So In your example the columns would look like this:

+------------+---------------+------------+---------------+------------+----------------+
| 20120216   | 20120216      | 20120221   | 20120221      | 20120228   | 20120228       |
| finalscore | halftimescore | finalscore | halftimescore | finalscore | halftimescore  |
+------------+---------------+------------+---------------+------------+----------------+

Thus when you slice from ('20120216', 'finalscore') to ('20120221', 'finalscore') you get both values for '20120216'. To make your query work as you want it to you could change the column_finish to ('20120216', 'halftimescore').

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top