本文整理汇总了Python中couchbase.bucket.Bucket.n1ql_query方法的典型用法代码示例。如果您正苦于以下问题:Python Bucket.n1ql_query方法的具体用法?Python Bucket.n1ql_query怎么用?Python Bucket.n1ql_query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类couchbase.bucket.Bucket
的用法示例。
在下文中一共展示了Bucket.n1ql_query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import n1ql_query [as 别名]
def get(self,info):
device_id, temp, type, status = info.split(':')
bucket = Bucket('couchbase://46.101.11.33:8091/devices')
res = bucket.get(device_id, quiet=True)
if res.success:
bucket.n1ql_query('UPSERT INTO devices (KEY,VALUE) VALUES ("%s",{"device_id":"%s", "temp":"%s", "type":"%s", "status":"%s"})' % (device_id, device_id, temp, type, status)).execute()
res = bucket.get(device_id, quiet=True)
return res.value
else:
return {"errCode": "-1", "errMsg": "Could not find device %s" % device_id}
示例2: get_server_docs_with_prefix
# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import n1ql_query [as 别名]
def get_server_docs_with_prefix(self, bucket, prefix):
"""
Returns server doc ids matching a prefix (ex. '_sync:rev:')
"""
b = Bucket("couchbase://{}/{}".format(self.host, bucket))
found_ids = []
b.n1ql_query("CREATE PRIMARY INDEX ON `{}`".format(bucket)).execute()
for row in b.n1ql_query("SELECT meta(`{}`) FROM `{}`".format(bucket, bucket)):
log_info(row)
if row["$1"]["id"].startswith(prefix):
found_ids.append(row["$1"]["id"])
return found_ids
示例3: createids
# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import n1ql_query [as 别名]
def createids():
cb = Bucket('couchbase://172.23.123.38/bucket-1', password='password')
row_iter = cb.n1ql_query(N1QLQuery('select meta().id from `bucket-1` limit 10000'))
for resultid in row_iter:
'''
use following to create the docids set
'''
print(resultid["id"], None)
示例4: _get_documets
# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import n1ql_query [as 别名]
def _get_documets(self, bucket_name, field):
bucket = Bucket('couchbase://{ip}/{name}'.format(ip=self.master.ip, name=bucket_name))
if not bucket:
log.info("Bucket connection is not established.")
log.info("Updating {0} in all documents in bucket {1}...".format(field, bucket_name))
query = "SELECT * FROM {0}".format(bucket_name)
for row in bucket.n1ql_query(query):
yield row[bucket.bucket]['_id'], bucket.get(key=row[bucket.bucket]['_id']).value
示例5: get_word_type
# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import n1ql_query [as 别名]
def get_word_type (type):
cb = Bucket(COUCHBASE)
# fails if you do not create an index on type
# $ /Applications/Couchbase\ Server.app/Contents/Resources/couchbase-core/bin/cbq
# cbq> CREATE PRIMARY INDEX ON default USING GSI;
query = N1QLQuery("SELECT cnt, word, type FROM `default` WHERE type=$q_type", q_type=type)
print query
for row in cb.n1ql_query(query):
print row
示例6: delete_couchbase_server_cached_rev_bodies
# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import n1ql_query [as 别名]
def delete_couchbase_server_cached_rev_bodies(self, bucket):
"""
Deletes docs that follow the below format
_sync:rev:att_doc:34:1-e7fa9a5e6bb25f7a40f36297247ca93e
"""
b = Bucket("couchbase://{}/{}".format(self.host, bucket))
cached_rev_doc_ids = []
b.n1ql_query("CREATE PRIMARY INDEX ON `{}`".format(bucket)).execute()
for row in b.n1ql_query("SELECT meta(`{}`) FROM `{}`".format(bucket, bucket)):
if row["$1"]["id"].startswith("_sync:rev"):
cached_rev_doc_ids.append(row["$1"]["id"])
log_info("Found temp rev docs: {}".format(cached_rev_doc_ids))
for doc_id in cached_rev_doc_ids:
log_debug("Removing: {}".format(doc_id))
b.remove(doc_id)
示例7: query_sports
# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import n1ql_query [as 别名]
def query_sports (params):
cb = Bucket(COUCHBASE)
where = []
for key in params.keys():
where.append('%s="%s"' % (key, params[key]))
query = N1QLQuery('SELECT * FROM `sports` WHERE ' + ' AND '.join(where))
result = []
for row in cb.n1ql_query(query):
result.append(row)
return result
示例8: CBGen
# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import n1ql_query [as 别名]
class CBGen(CBAsyncGen):
TIMEOUT = 10 # seconds
def __init__(self, ssl_mode: str = 'none', n1ql_timeout: int = None, **kwargs):
connection_string = 'couchbase://{host}/{bucket}?password={password}&{params}'
connstr_params = parse.urlencode(kwargs["connstr_params"])
if ssl_mode == 'data':
connection_string = connection_string.replace('couchbase',
'couchbases')
connection_string += '&certpath=root.pem'
connection_string = connection_string.format(host=kwargs['host'],
bucket=kwargs['bucket'],
password=kwargs['password'],
params=connstr_params)
self.client = Bucket(connection_string=connection_string)
self.client.timeout = self.TIMEOUT
if n1ql_timeout:
self.client.n1ql_timeout = n1ql_timeout
logger.info("Connection string: {}".format(connection_string))
@quiet
@backoff
def create(self, *args, **kwargs):
super().create(*args, **kwargs)
@quiet
@backoff
@timeit
def read(self, *args, **kwargs):
super().read(*args, **kwargs)
@quiet
@backoff
@timeit
def update(self, *args, **kwargs):
super().update(*args, **kwargs)
@quiet
def delete(self, *args, **kwargs):
super().delete(*args, **kwargs)
@timeit
def view_query(self, ddoc: str, view: str, query: ViewQuery):
tuple(self.client.query(ddoc, view, query=query))
@quiet
@timeit
def n1ql_query(self, query: N1QLQuery):
tuple(self.client.n1ql_query(query))
示例9: cb_query
# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import n1ql_query [as 别名]
def cb_query(_tid, _total_threads, _key_prefix, _key_start, _key_end, _query_string, _query_iterations, _connection_string):
print ("Starting Thread %s" % _tid)
#establish connection
print ("Connecting: ", _connection_string)
b = Bucket(_connection_string)
for i in range(_query_iterations):
if (i % _total_threads == _tid):
_query_valued = _query_string.replace("$1", _key_prefix + str(((_key_start + i) % _key_end) + _key_start))
t0 = time.clock()
for row in b.n1ql_query(_query_valued):
# just measure retrieval time
pass
t1 = time.clock()
print ("Last execution time in milliseond: %3.3f" % ((t1 - t0) * 1000))
示例10: get_rev_ids
# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import n1ql_query [as 别名]
def get_rev_ids(cb_id_arr):
statement = ("SELECT _sync.rev as rev_id FROM "
+ BUCKET + " USE KEYS " + str(cb_id_arr))
try:
bucket = Bucket(URL)
bucket.n1ql_timeout = TIMEOUT
query = N1QLQuery(statement)
query.timeout = TIMEOUT
res = bucket.n1ql_query(query)
except (RequestException, CouchbaseTransientError, CouchbaseNetworkError) as err:
logger.error(err)
return _dict2json(res, False)
示例11: __init__
# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import n1ql_query [as 别名]
class Datefacet:
def __init__(self):
from couchbase.n1ql import N1QLQuery
from multiprocessing import Manager, Lock
self.cb = Bucket('couchbase://172.23.123.38/bucket-1')
self.row_iter = self.cb.n1ql_query(N1QLQuery('select meta().id from `bucket-1`'))
self.lock = Lock()
self.dsize = 1000000
self.dateiter = Manager().dict({key: None for key in ['2013-10-17', '2013-11-17', '2014-02-09', '2015-11-26']})
self.dateiter['2013-10-17'] = .65 * self.dsize
self.dateiter['2013-11-17'] = .2 * self.dsize
self.dateiter['2014-02-09'] = .1 * self.dsize
self.dateiter['2015-11-26'] = .05 * self.dsize
self.cycledates = itertools.cycle(self.dateiter.keys())
def createdateset(self):
for resultid in self.row_iter:
'''
Day 1 should have approximately 65% of the documents
Day 2 should have approximately 20% of the documents
Day 3 should have approximately 10% of the documents
Day 4 should have approximately 5% of the documents
format like this 2010-07-27
'''
val = self.cb.get(resultid["id"]).value
self.lock.acquire()
tmpdate = self.cycledates.next()
val["date"] = tmpdate
self.cb.set(resultid["id"], val)
'''
Critical section
'''
self.dateiter[tmpdate] -= 1
if self.dateiter[tmpdate] == 0:
self.dateiter.pop(tmpdate, None)
self.cycledates = itertools.cycle(self.dateiter.keys())
self.lock.release()
print(self.dateiter)
def run(self):
import concurrent.futures
with concurrent.futures.ProcessPoolExecutor(max_workers=10) as executor:
executor.submit(self.createdateset())
示例12: _get_all
# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import n1ql_query [as 别名]
def _get_all(statement):
try:
bucket = Bucket(URL)
bucket.n1ql_timeout = TIMEOUT
lg.write_to_log("\n", _log_file_name)
lg.write_to_log("<" + str(dt.datetime.utcnow()) + "> : ", _log_file_name)
lg.write_to_log("Query: " + statement + "; ", _log_file_name)
query = N1QLQuery(statement)
query.timeout = TIMEOUT
res = bucket.n1ql_query(query)
except (RequestException, CouchbaseTransientError, CouchbaseNetworkError) as err:
logger.error(err)
sys.exit(1)
return res
示例13: main
# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import n1ql_query [as 别名]
def main():
print 'Starting the perf regression runner'
usage = '%prog -f conf-file'
parser = OptionParser(usage)
#parser.add_option('-f', '--filename', dest='filename')
parser.add_option('-v', '--version', dest='version')
parser.add_option('-u', '--url', dest='url')
parser.add_option('-r', '--runStartTime', dest='runStartTime')
parser.add_option('-n', '--nop', dest='nop',default=False, action='store_true')
options, args = parser.parse_args()
runStartTime = options.runStartTime
summary = []
print 'version', options.version
print 'url', options.url
# open the bucket
bucket = Bucket('couchbase://'+ '172.23.105.177:8091/Daily-Performance')
testBucket = Bucket('couchbase://'+ '172.23.105.177:8091/Daily-Performance-Tests')
queryString = "select `Daily-Performance-Tests`.* from `Daily-Performance-Tests`;"
query = N1QLQuery(queryString )
testsToRun = testBucket.n1ql_query( queryString )
testsToRerun = []
for row in testsToRun:
if 'disabled' in row and row['disabled'].lower() == 'true':
print row['testName'], ' is disabled.'
else:
if not runTest( row, options.version, options.url, options.runStartTime, bucket ):
testsToRerun.append(row)
#time.sleep(10)
# end the for loop - print the results
print 'done'
示例14: main
# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import n1ql_query [as 别名]
def main():
usage = '%prog -f conf-file'
parser = OptionParser(usage)
parser.add_option('-r', '--runStart', dest='runStart')
parser.add_option('-v', '--version', dest='version')
parser.add_option('-o', '--os', dest='os',default='centos')
options, args = parser.parse_args()
summary = []
# open the bucket
resultsBucket = Bucket('couchbase://172.23.105.177/Daily-Performance')
testDescriptorBucket = Bucket('couchbase://172.23.105.177/Daily-Performance-Tests')
# query for everything based on the run id
queryBaseString = """
select testName, testMetric, pass, expectedValue,actualValue,`build`,reason,runStartTime, os from `Daily-Performance`
where runStartTime = '{0}' and `build`='{1}' order by testName, runStartTime;
"""
queryString = queryBaseString.format(options.runStart, options.version)
#print 'the query is', queryString
query = N1QLQuery(queryString )
results = resultsBucket.n1ql_query( queryString )
passingTests = []
failingTests = []
stabilizingTests = []
environmentalIssues = []
passedOnSecondRun = []
failedOnSecondRun = []
for row in results:
#print 'row is ',row
# a bit of a hack to remove the redundant information
#print 'the row is', row
row['testName'] = row['testName'].replace('perf_sanity_','') #perf_sanity_.... .test
if 'testMetric' in row:
row['testMetric'] = row['testMetric'].replace('perf_sanity_','').replace('_base_test','') #.replace('_perf_sanity_secondary','')
if row['testMetric'] == 'avg_query_requests': row['testMetric'] = 'throughput'
if 'n1ql_thr_lat_' in row['testMetric'] : row['testMetric'] = 'latency'
# check for other stuff like MBs
row['jira'] = ''
row['notes'] = ''
try:
res = testDescriptorBucket.get(row['testName']).value
#print '****res is', res
if 'notes' in res: row['notes'] = res['notes']
if 'jira' in res: row['jira'] = res['jira']
if 'status' in res: row['status'] = res['status']
except:
#print 'no record for',row['testName']
continue
#print row
if row['status'] == 'beta' or row['notes'] == 'stabilizing':
stabilizingTests.append( row)
else:
# check if this test failed already
alreadyPassed = False
alreadyFailed = False
for i in failingTests:
if row['testMetric'] == i['testMetric'] and row['testName'] == i['testName']:
alreadyFailed =True
break
for i in passingTests:
if row['testMetric'] == i['testMetric'] and row['testName'] == i['testName']:
alreadyPassed =True
break
if row['pass']:
if alreadyPassed:
pass # passed twice, this is a no-op
else:
passingTests.append( row )
if alreadyFailed:
# remove the failing record
testToRemove = -1
for i in range(len(failingTests)):
if row['testName'] == failingTests[i]['testName'] and \
row['testMetric'] == failingTests[i]['testMetric']:
testToRemove = i
passedOnSecondRun.append(failingTests[i])
break
if testToRemove >= 0:
#.........这里部分代码省略.........
示例15: main
# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import n1ql_query [as 别名]
def main():
print "Starting the perf regression runner"
usage = "%prog -f conf-file"
# parser = OptionParser(usage)
##parser.add_option('-f', '--filename', dest='filename')
# parser.add_option('-v', '--version', dest='version')
# parser.add_option('-u', '--url', dest='url')
# parser.add_option('-q', '--query', dest='query')
# parser.add_option('-s', '--specFile', dest='specFile')
# parser.add_option('-r', '--runStartTime', dest='runStartTime')
# parser.add_option('-b', '--betaTests', dest='betaTests', default=False, action='store_true')
# parser.add_option('-n', '--nop', dest='nop',default=False, action='store_true')
# options, args = parser.parse_args()
# the option parsing way
parser = argparse.ArgumentParser(description=usage)
parser.add_argument("-q", "--query", nargs="+")
parser.add_argument("-v", "--version", dest="version")
parser.add_argument("-u", "--url", dest="url")
parser.add_argument("-s", "--specFile", dest="specFile")
parser.add_argument("-r", "--runStartTime", dest="runStartTime")
parser.add_argument("-b", "--betaTests", dest="betaTests", default=False, action="store_true")
parser.add_argument("-a", "--allTests", dest="allTests", default=False, action="store_true")
parser.add_argument("-n", "--nop", dest="nop", default=False, action="store_true")
parser.add_argument("-p", "--patchScript", dest="patchScript", default=None)
parser.add_argument("-o", "--os", dest="os", default="centos")
parser.add_argument("-e", "--rerun", dest="rerun", default=True, action="store_false")
parser.add_argument("-y", "--queryOnly", dest="queryOnly", default=False, action="store_true")
parser.add_argument("-t", "--test", dest="test", default=False, action="store_true")
options = parser.parse_args()
print "query", options.query
print "specfile", options.specFile
print "the os is", options.os
runStartTime = options.runStartTime
summary = []
print "rerun", options.rerun
print "url", options.url
releaseVersion = float(".".join(options.version.split(".")[:2]))
print "the release version is", releaseVersion
# open the bucket
if options.nop:
bucket = None
else:
bucket = Bucket("couchbase://" + "172.23.105.177:8091/Daily-Performance")
testBucket = Bucket("couchbase://" + "172.23.105.177:8091/Daily-Performance-Tests")
if options.test:
queryString = 'select `Daily-Performance-Tests`.* from `Daily-Performance-Tests` where testName = "test"'
else:
queryString = (
"select `Daily-Performance-Tests`.* from `Daily-Performance-Tests` where status != 'unimplemented'"
)
wherePredicates = []
if options.query is not None:
wherePredicates.append(" ".join(options.query))
if not options.allTests:
if options.betaTests:
wherePredicates.append("status='beta'")
else:
wherePredicates.append("status!='beta'")
if len(wherePredicates) > 0:
for i in range(len(wherePredicates)):
queryString += " and " + wherePredicates[i]
# check for versioning
queryString += " and (implementedIn is missing or {0} >= implementedIn)".format(releaseVersion)
print "the query string is", queryString
query = N1QLQuery(queryString)
testsToRun = testBucket.n1ql_query(queryString)
tests = [row for row in testsToRun]
print "the tests are", len(tests), tests
testsToRerun = []
if options.queryOnly:
return
for row in tests:
try:
if row["status"].lower() == "disabled" and not options.test:
print row["testName"], " is disabled."
else:
if not runTest(row, options, bucket, considerRerun=options.rerun):
testsToRerun.append(row)
except:
print "Exception in ", row["testName"]
traceback.print_exc()
# end the for loop - print the results
#.........这里部分代码省略.........