2013-10-24 26 views
1

我試圖使用新datastax蟒蛇司機python腳本自動執行某些表和索引創建的Python驅動程序。但是,似乎某些語句被跳過或不按順序執行。我甚至試圖在每個命令後面放上10秒鐘的睡眠事件,希望它能夠工作,但事實並非如此。表和索引創建使用的卡桑德拉

通常只有第二和第三索引創建。有時創建索引不會在索引創建之前發生,並且出錯。

import logging 
from cassandra.cluster import Cluster 
from time import sleep 


log = logging.getLogger() 
log.setLevel('DEBUG') 
handler = logging.StreamHandler() 
handler.setFormatter(logging.Formatter("%(asctime)s [%(levelname)s] %(name)s: %(message)s")) 
log.addHandler(handler) 

cluster = Cluster(['128.32.xxx.xxx','128.32.xxx.xxx','128.32.xxx.xxx']) 
session = cluster.connect() 

session.execute("""use test;""") 
#session.execute("""drop table test.devices;""") 
log.info('dropped table devices.') 

session.execute("""CREATE TABLE devices (
         device_uuid uuid, 
         external_identifier text, 
         geohash text, 
         latitude float, 
         longitude float, 
         measures set<text>, 
         name text, 
         parent_device_id uuid, 
         tags map<text, text>, 
         PRIMARY KEY (device_uuid) 
         ) WITH 
         compression={'sstable_compression': 'SnappyCompressor'} USING CONSISTENCY ALL;""") 

session.execute("""CREATE INDEX external_id_ind ON devices (external_identifier) USING CONSISTENCY ALL;""") 

session.execute("""CREATE INDEX name_ind ON devices (name) USING CONSISTENCY ALL;""") 

session.execute("""CREATE INDEX geohash_ind ON devices (geohash) USING CONSISTENCY ALL;""") 

session.execute("""CREATE INDEX parent_device_id_ind ON devices (parent_device_id) USING CONSISTENCY ALL;""") 

回答

0

我相信你正在寫使用cql3-β語法(的運用一致性),它不應該與蟒蛇司機工作的陳述。 python驅動只適用於Cassandra 1.2+(CQL3)。

的主要區別是,現在的一致性是由客戶端而不是在查詢本身就是一個指令集的狀態。使用Python驅動程序的一致性設置像這樣

session.execute(SimpleStatement("SELECT * FROM...", consistency_level=ConsistencyLevel.QUORUM))"