我正在尝试使用新的 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;""")