5

range_keyを(0,9999)の間で取得するには、この方法で実行できますか?

conn = boto.connect_dynamodb()
table = conn.get_table("mytable")
...
result = table.query(
      hash_key = "66", 
      range_key_condition = {"0":"GE", "9999":"LE"}
      )

boto v2.2.2-devを使用すると、常に空の結果が得られます

編集:これは別のエラーサンプルです:

In [218]: qa = taa.query(hash_key = "1")

In [219]: qa.next()
Out[219]: {u'attra': u'this is attra', u'key': u'1', u'range': 1.1}

上記の「range_key_condition」がなくても大丈夫です

In [220]: qa = taa.query(hash_key = "1", range_key_condition = {0.1: "GE"})

In [221]: qa.next()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/home/user/python/enva/<ipython-input-221-dba0a498b6e1> in <module>()
----> 1 qa.next()

/home/user/python/enva/local/lib/python2.7/site-packages/boto-2.2.2_dev-py2.7.egg/boto/dynamodb/layer2.pyc
in query(self, table, hash_key, range_key_condition,
attributes_to_get, request_limit, max_results, consistent_read,
scan_index_forward, exclusive_start_key, item_class)
    559         """
    560         if range_key_condition:
--> 561             rkc = self.dynamize_range_key_condition(range_key_condition)
    562         else:
    563             rkc = None

/home/user/python/enva/local/lib/python2.7/site-packages/boto-2.2.2_dev-py2.7.egg/boto/dynamodb/layer2.pyc
in dynamize_range_key_condition(self, range_key_condition)
    83         structure required by Layer1.
    84         """
---> 85         return range_key_condition.to_dict()
   86
   87     def dynamize_scan_filter(self, scan_filter):

AttributeError: 'dict' object has no attribute 'to_dict'
4

2 に答える 2

5

最新バージョンのbotoを使用している場合(そしてあなたがそうであるように見える場合)、クエリを読みやすくするために、以前のバージョンから条件が変更されています。これを試して:

from boto.dynamodb.condition import *
conn = boto.connect_dynamodb()
table = conn.get_table("mytable")
...
result = table.query(
  hash_key = "66", 
  range_key_condition = BETWEEN(0, 9999))

この質問の調査中にBETWEENにバグを発見したため、botoコードを更新する必要がありますが、機能するはずです(https://github.com/boto/boto/issues/620を参照)。

于 2012-03-06T19:38:13.123 に答える
1

APIから、複数の条件を含めることが許可されているかどうかは明確ではありません。条件の1つだけを実行した場合、それは機能しますか?また、BETWEEN演算子がありrange_key_condition = {(0,10000):"BETWEEN"}ますが、値が数値ではなく文字列である場合は機能しない可能性があります。私はこのAPIを使用したことがないので、おそらくbotoメーリングリストまたはIRCで質問します。

更新:追加したばかりのエラーメッセージとgithubのBotoコードを見ると、これはBotoのバグだと思います。Table.queryを呼び出すだけLayer2.queryです。Layer2.queryrange_key_conditionがConditionオブジェクト(to_dictメソッドを持つ)であることが期待されますが、通常のオブジェクト(dict明らかにto_dictメソッドがない)を提供します。Table.querydictをConditionオブジェクトに変換し、に提供する必要がありますLayer2.queryが、そうではありません。メーリングリストまたはIRCに助けを求めます。

于 2012-03-06T14:51:30.847 に答える