문제

기본적으로 나는 에서와 동일한 것을 묻고 있습니다. 질문 그러나 파이썬 카산드라 라이브러리의 경우 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')])
.

그러나 FinalScore 만 원할 경우, 나는 할 수 있다고 가정 할 것입니다 :

>>> 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')])
.

첫 번째 호출과 동일합니다.

뭔가 잘못하고 있습니까? 이 일을해야합니까? 아니면 cf.get (... columns= [( '20120216' 'finalscore')]을 사용하여 일부 구문이 있습니까?)? 나는 그것을 시도하고 예외를 얻었습니다. http : //www.datastastastastastax .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