本文整理汇总了Python中wtdataset.SimpleDataSet.value方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleDataSet.value方法的具体用法?Python SimpleDataSet.value怎么用?Python SimpleDataSet.value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wtdataset.SimpleDataSet
的用法示例。
在下文中一共展示了SimpleDataSet.value方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_search_eot
# 需要导入模块: from wtdataset import SimpleDataSet [as 别名]
# 或者: from wtdataset.SimpleDataSet import value [as 别名]
def test_search_eot(self):
# Populate the tree and reopen the connection, forcing it to disk
# and moving the records to an on-page format.
ds = SimpleDataSet(self, self.uri, 100, key_format=self.key_format,
value_format=self.value_format)
ds.populate()
self.reopen_conn()
# Open a cursor.
cursor = self.session.open_cursor(self.uri, None)
# Search for a record at the end of the table, which should succeed.
cursor.set_key(ds.key(100))
self.assertEqual(cursor.search(), 0)
self.assertEqual(cursor.get_key(), ds.key(100))
self.assertEqual(cursor.get_value(), ds.value(100))
# Search-near for a record at the end of the table, which should
# succeed, returning the last record.
cursor.set_key(ds.key(100))
self.assertEqual(cursor.search_near(), 0)
self.assertEqual(cursor.get_key(), ds.key(100))
self.assertEqual(cursor.get_value(), ds.value(100))
# Search for a record past the end of the table, which should fail.
cursor.set_key(ds.key(200))
self.assertEqual(cursor.search(), wiredtiger.WT_NOTFOUND)
# Search-near for a record past the end of the table, which should
# succeed, returning the last record.
cursor.set_key(ds.key(200))
self.assertEqual(cursor.search_near(), -1)
self.assertEqual(cursor.get_key(), ds.key(100))
self.assertEqual(cursor.get_value(), ds.value(100))
示例2: test_search_invisible_two
# 需要导入模块: from wtdataset import SimpleDataSet [as 别名]
# 或者: from wtdataset.SimpleDataSet import value [as 别名]
def test_search_invisible_two(self):
# Populate the tree and reopen the connection, forcing it to disk
# and moving the records to an on-page format.
ds = SimpleDataSet(self, self.uri, 100, key_format=self.key_format,
value_format=self.value_format)
ds.populate()
self.reopen_conn()
# Add some additional visible records.
cursor = self.session.open_cursor(self.uri, None)
for i in range(100, 120):
cursor[ds.key(i)] = ds.value(i)
cursor.close()
# Begin a transaction, and add some additional records.
self.session.begin_transaction()
cursor = self.session.open_cursor(self.uri, None)
for i in range(120, 140):
cursor[ds.key(i)] = ds.value(i)
# Open a separate session and cursor.
s = self.conn.open_session()
cursor = s.open_cursor(self.uri, None)
# Search for an invisible record.
cursor.set_key(ds.key(130))
if self.empty:
# Invisible updates to fixed-length column-store objects are
# invisible to the reader, but the fact that they exist past
# the end of the initial records causes the instantiation of
# empty records: confirm successful return of an empty row.
cursor.search()
self.assertEqual(cursor.get_key(), 130)
self.assertEqual(cursor.get_value(), 0)
else:
# Otherwise, we should not find any matching records.
self.assertEqual(cursor.search(), wiredtiger.WT_NOTFOUND)
# Search-near for an invisible record, which should succeed, returning
# the last visible record.
cursor.set_key(ds.key(130))
cursor.search_near()
if self.empty:
# Invisible updates to fixed-length column-store objects are
# invisible to the reader, but the fact that they exist past
# the end of the initial records causes the instantiation of
# empty records: confirm successful return of an empty row.
cursor.search()
self.assertEqual(cursor.get_key(), 130)
self.assertEqual(cursor.get_value(), 0)
else:
# Otherwise, we should find the closest record for which we can see
# the value.
self.assertEqual(cursor.get_key(), ds.key(119))
self.assertEqual(cursor.get_value(), ds.value(119))
示例3: test_smoke
# 需要导入模块: from wtdataset import SimpleDataSet [as 别名]
# 或者: from wtdataset.SimpleDataSet import value [as 别名]
def test_smoke(self):
ds = SimpleDataSet(self, self.uri, self.nentries,
config=self.config, key_format=self.keyfmt)
ds.populate()
self.reopen_conn()
c = self.session.open_cursor(self.uri, None)
c.set_key(ds.key(100))
self.assertEqual(c.search(), 0)
self.assertEqual(c.get_value(), ds.value(100))
c.set_key(ds.key(101))
self.assertEqual(c.search(), 0)
self.assertEqual(c.get_value(), ds.value(101))
c.set_key(ds.key(9999))
self.assertEqual(c.search(), 0)
self.assertEqual(c.get_value(), ds.value(9999))
示例4: test_insert_over_delete_replace
# 需要导入模块: from wtdataset import SimpleDataSet [as 别名]
# 或者: from wtdataset.SimpleDataSet import value [as 别名]
def test_insert_over_delete_replace(self):
msg = '/WT_CACHE_FULL.*/'
ds = SimpleDataSet(self, self.uri, 10000000, key_format=self.keyfmt,
value_format=self.valuefmt, config=self.table_config)
self.assertRaisesHavingMessage(wiredtiger.WiredTigerError,
ds.populate, msg)
cursor = self.session.open_cursor(self.uri, None)
cursor.prev()
last_key = int(cursor.get_key())
# Now that the database contains as much data as will fit into
# the configured cache, verify removes succeed.
cursor = self.session.open_cursor(self.uri, None)
for i in range(1, last_key / 4, 1):
cursor.set_key(ds.key(i))
cursor.remove()
cursor.reset()
# Spin inserting to give eviction a chance to reclaim space
inserted = False
for i in range(1, 1000):
try:
cursor[ds.key(1)] = ds.value(1)
except wiredtiger.WiredTigerError:
cursor.reset()
sleep(1)
continue
inserted = True
break
self.assertTrue(inserted)
示例5: test_column_store_gap_traverse
# 需要导入模块: from wtdataset import SimpleDataSet [as 别名]
# 或者: from wtdataset.SimpleDataSet import value [as 别名]
def test_column_store_gap_traverse(self):
uri = 'table:gap'
# Initially just create tables.
ds = SimpleDataSet(self, uri, 0, key_format='r')
ds.populate()
cursor = self.session.open_cursor(uri, None, None)
self.nentries = 0
# Create a column store with key gaps. The particular values aren't
# important, we just want some gaps.
v = [ 1000, 1001, 2000, 2001]
for i in v:
cursor[ds.key(i)] = ds.value(i)
self.nentries += 1
# In-memory cursor forward, backward.
self.forward(cursor, v)
self.backward(cursor, list(reversed(v)))
self.reopen_conn()
cursor = self.session.open_cursor(uri, None, None)
# Disk page cursor forward, backward.
self.forward(cursor, v)
self.backward(cursor, list(reversed(v)))
# Insert some new records, so there are in-memory updates and an
# on disk image. Put them in the middle of the existing values
# so the traversal walks to them.
v2 = [ 1500, 1501 ]
for i in v2:
cursor[ds.key(i)] = ds.value(i)
self.nentries += 1
# Tell the validation what to expect.
v = [ 1000, 1001, 1500, 1501, 2000, 2001 ]
self.forward(cursor, v)
self.backward(cursor, list(reversed(v)))
示例6: test_missing
# 需要导入模块: from wtdataset import SimpleDataSet [as 别名]
# 或者: from wtdataset.SimpleDataSet import value [as 别名]
def test_missing(self):
ds = SimpleDataSet(self, self.uri, self.nentries,
config=self.config, key_format=self.keyfmt)
ds.populate()
c = self.session.open_cursor(self.uri, None)
for i in range(self.nentries + 3000, self.nentries + 5001):
c[ds.key(i)] = ds.value(i)
self.reopen_conn()
c = self.session.open_cursor(self.uri, None)
self.forward(c, ds, self.nentries + 5000,
list(range(self.nentries + 1, self.nentries + 3000)))
self.backward(c, ds, self.nentries + 5000,
list(range(self.nentries + 1, self.nentries + 3000)))
# Insert into the empty space so we test searching inserted items.
for i in range(self.nentries + 1000, self.nentries + 2001):
c[ds.key(i)] = ds.value(i)
self.forward(c, ds, self.nentries + 5000,
list(list(range(self.nentries + 1, self.nentries + 1000)) +\
list(range(self.nentries + 2001, self.nentries + 3000))))
self.backward(c, ds, self.nentries + 5000,
list(list(range(self.nentries + 1, self.nentries + 1000)) +\
list(range(self.nentries + 2001, self.nentries + 3000))))
示例7: test_column_store_gap
# 需要导入模块: from wtdataset import SimpleDataSet [as 别名]
# 或者: from wtdataset.SimpleDataSet import value [as 别名]
def test_column_store_gap(self):
uri = 'table:gap'
# Initially just create tables.
ds = SimpleDataSet(self, uri, 0, key_format='r')
ds.populate()
cursor = self.session.open_cursor(uri, None, None)
self.nentries = 0
# Create a column-store table with large gaps in the name-space.
v = [ 1000, 2000000000000, 30000000000000 ]
for i in v:
cursor[ds.key(i)] = ds.value(i)
self.nentries += 1
# In-memory cursor forward, backward.
self.forward(cursor, v)
self.backward(cursor, list(reversed(v)))
self.reopen_conn()
cursor = self.session.open_cursor(uri, None, None)
# Disk page cursor forward, backward.
self.forward(cursor, v)
self.backward(cursor, list(reversed(v)))
示例8: test_truncate_simple
# 需要导入模块: from wtdataset import SimpleDataSet [as 别名]
# 或者: from wtdataset.SimpleDataSet import value [as 别名]
def test_truncate_simple(self):
uri = self.type + self.name
# layout:
# the number of initial skipped records
# the number of initial inserted records
# the number of trailing skipped records
# the number of trailing inserted records
layout = [
# simple set of rows
(0, 0, 0, 0),
# trailing append list, no delete point overlap
(0, 0, 0, self.skip - 3),
# trailing append list, delete point overlap
(0, 0, 0, self.skip + 3),
# trailing skipped list, no delete point overlap
(0, 0, self.skip - 3, 1),
# trailing skipped list, delete point overlap
(0, 0, self.skip + 3, 1),
# leading insert list, no delete point overlap
(0, self.skip - 3, 0, 0),
# leading insert list, delete point overlap
(0, self.skip + 3, 0, 0),
# leading skipped list, no delete point overlap
(self.skip - 3, 1, 0, 0),
# leading skipped list, delete point overlap
(self.skip + 3, 1, 0, 0),
]
# list: truncation patterns applied on top of the layout.
#
# begin and end: -1 means pass None for the cursor arg to truncate. An
# integer N, with 1 <= N < self.nentries, truncates from/to a cursor
# positioned at that row.
list = [
(-1, self.nentries), # begin to end, begin = None
(1, -1), # begin to end, end = None
(1, self.nentries), # begin to end
(-1, self.nentries - self.skip), # begin to middle, begin = None
(1, self.nentries - self.skip), # begin to middle
(self.skip, -1), # middle to end, end = None
(self.skip, self.nentries), # middle to end
(self.skip, # middle to different middle
self.nentries - self.skip),
(1, 1), # begin to begin
(self.nentries, self.nentries), # end to end
(self.skip, self.skip) # middle to same middle
]
# Using this data set to compare only, it doesn't create or populate.
ds = SimpleDataSet(self, uri, 0, key_format=self.keyfmt,
value_format=self.valuefmt, config=self.config)
# Build the layout we're going to test
total = self.nentries
for begin_skipped,begin_insert,end_skipped,end_insert in layout:
# skipped records require insert/append records
if begin_skipped and not begin_insert or \
end_skipped and not end_insert:
raise AssertionError('test error: skipped set without insert')
for begin,end in list:
'''
print '===== run:'
print 'key:', self.keyfmt, 'begin:', begin, 'end:', end
print 'total: ', total, \
'begin_skipped:', begin_skipped, \
'begin_insert:', begin_insert, \
'end_skipped:', end_skipped, \
'end_insert:', end_insert
'''
# Build a dictionary of what the object should look like for
# later comparison
expected = {}
# Create the object.
self.session.create(
uri, self.config + ',key_format=' + self.keyfmt +
',value_format=' + self.valuefmt)
# Insert the records that aren't skipped or inserted.
start = begin_skipped + begin_insert
stop = self.nentries - (end_skipped + end_insert)
cursor = self.session.open_cursor(uri, None)
for i in range(start + 1, stop + 1):
k = ds.key(i)
v = ds.value(i)
cursor[k] = v
expected[k] = [v]
cursor.close()
#.........这里部分代码省略.........
示例9: test_search_invisible_one
# 需要导入模块: from wtdataset import SimpleDataSet [as 别名]
# 或者: from wtdataset.SimpleDataSet import value [as 别名]
def test_search_invisible_one(self):
# Populate the tree.
ds = SimpleDataSet(self, self.uri, 100, key_format=self.key_format,
value_format=self.value_format)
ds.populate()
# Delete a range of records.
for i in range(5, 10):
cursor = self.session.open_cursor(self.uri, None)
cursor.set_key(ds.key(i))
self.assertEqual(cursor.remove(), 0)
# Reopen the connection, forcing it to disk and moving the records to
# an on-page format.
self.reopen_conn()
# Add updates to the existing records (in both the deleted an undeleted
# range), as well as some new records after the end. Put the updates in
# a separate transaction so they're invisible to another cursor.
self.session.begin_transaction()
cursor = self.session.open_cursor(self.uri, None)
for i in range(5, 10):
cursor[ds.key(i)] = ds.value(i + 1000)
for i in range(30, 40):
cursor[ds.key(i)] = ds.value(i + 1000)
for i in range(100, 140):
cursor[ds.key(i)] = ds.value(i + 1000)
# Open a separate session and cursor.
s = self.conn.open_session()
cursor = s.open_cursor(self.uri, None)
# Search for an existing record in the deleted range, should not find
# it.
for i in range(5, 10):
cursor.set_key(ds.key(i))
if self.empty:
# Fixed-length column-store rows always exist.
self.assertEqual(cursor.search(), 0)
self.assertEqual(cursor.get_key(), i)
self.assertEqual(cursor.get_value(), 0)
else:
self.assertEqual(cursor.search(), wiredtiger.WT_NOTFOUND)
# Search for an existing record in the updated range, should see the
# original value.
for i in range(30, 40):
cursor.set_key(ds.key(i))
self.assertEqual(cursor.search(), 0)
self.assertEqual(cursor.get_key(), ds.key(i))
# Search for a added record, should not find it.
for i in range(120, 130):
cursor.set_key(ds.key(i))
if self.empty:
# Invisible updates to fixed-length column-store objects are
# invisible to the reader, but the fact that they exist past
# the end of the initial records causes the instantiation of
# empty records: confirm successful return of an empty row.
self.assertEqual(cursor.search(), 0)
self.assertEqual(cursor.get_key(), i)
self.assertEqual(cursor.get_value(), 0)
else:
# Otherwise, we should not find any matching records.
self.assertEqual(cursor.search(), wiredtiger.WT_NOTFOUND)
# Search-near for an existing record in the deleted range, should find
# the next largest record. (This depends on the implementation behavior
# which currently includes a bias to prefix search.)
for i in range(5, 10):
cursor.set_key(ds.key(i))
if self.empty:
# Fixed-length column-store rows always exist.
self.assertEqual(cursor.search_near(), 0)
self.assertEqual(cursor.get_key(), i)
self.assertEqual(cursor.get_value(), 0)
else:
self.assertEqual(cursor.search_near(), 1)
self.assertEqual(cursor.get_key(), ds.key(10))
# Search-near for an existing record in the updated range, should see
# the original value.
for i in range(30, 40):
cursor.set_key(ds.key(i))
self.assertEqual(cursor.search_near(), 0)
self.assertEqual(cursor.get_key(), ds.key(i))
# Search-near for an added record, should find the previous largest
# record.
for i in range(120, 130):
cursor.set_key(ds.key(i))
if self.empty:
# Invisible updates to fixed-length column-store objects are
# invisible to the reader, but the fact that they exist past
# the end of the initial records causes the instantiation of
# empty records: confirm successful return of an empty row.
self.assertEqual(cursor.search_near(), 0)
self.assertEqual(cursor.get_key(), i)
self.assertEqual(cursor.get_value(), 0)
else:
#.........这里部分代码省略.........
示例10: test_truncate_fast_delete
# 需要导入模块: from wtdataset import SimpleDataSet [as 别名]
# 或者: from wtdataset.SimpleDataSet import value [as 别名]
def test_truncate_fast_delete(self):
uri = self.type + self.name
'''
print '===== run:'
print 'config:', self.config + self.keyfmt, \
'overflow=', self.overflow, \
'readafter=', self.readafter, 'readbefore=', self.readbefore, \
'writeafter=', self.writeafter, 'writebefore=', self.writebefore, \
'commit=', self.commit
'''
# Create the object.
ds = SimpleDataSet(self, uri, self.nentries,
config=self.config, key_format=self.keyfmt)
ds.populate()
# Optionally add a few overflow records so we block fast delete on
# those pages.
if self.overflow:
cursor = self.session.open_cursor(uri, None, 'overwrite=false')
for i in range(1, self.nentries, 3123):
cursor.set_key(ds.key(i))
cursor.set_value(ds.value(i))
cursor.update()
cursor.close()
# Close and re-open it so we get a disk image, not an insert skiplist.
self.reopen_conn()
# Optionally read/write a few rows before truncation.
if self.readbefore or self.writebefore:
cursor = self.session.open_cursor(uri, None, 'overwrite=false')
if self.readbefore:
for i in range(1, self.nentries, 737):
cursor.set_key(ds.key(i))
cursor.search()
if self.writebefore:
for i in range(1, self.nentries, 988):
cursor.set_key(ds.key(i))
cursor.set_value(ds.value(i + 100))
cursor.update()
cursor.close()
# Begin a transaction, and truncate a big range of rows.
self.session.begin_transaction(None)
start = self.session.open_cursor(uri, None)
start.set_key(ds.key(10))
end = self.session.open_cursor(uri, None)
end.set_key(ds.key(self.nentries - 10))
self.session.truncate(None, start, end, None)
start.close()
end.close()
# Optionally read/write a few rows after truncation.
if self.readafter or self.writeafter:
cursor = self.session.open_cursor(uri, None, 'overwrite=false')
if self.readafter:
for i in range(1, self.nentries, 1123):
cursor.set_key(ds.key(i))
cursor.search()
if self.writeafter:
for i in range(1, self.nentries, 621):
cursor.set_key(ds.key(i))
cursor.set_value(ds.value(i + 100))
cursor.update()
cursor.close()
# A cursor involved in the transaction should see the deleted records.
# The number 19 comes from deleting row 10 (inclusive), to row N - 10,
# exclusive, or 9 + 10 == 19.
remaining = 19
cursor = self.session.open_cursor(uri, None)
self.cursor_count(cursor, remaining)
cursor.close()
# A separate, read_committed cursor should not see the deleted records.
self.outside_count("isolation=read-committed", self.nentries)
# A separate, read_uncommitted cursor should see the deleted records.
self.outside_count("isolation=read-uncommitted", remaining)
# Commit/rollback the transaction.
if self.commit:
self.session.commit_transaction()
else:
self.session.rollback_transaction()
# Check a read_committed cursor sees the right records.
cursor = self.session.open_cursor(uri, None)
if self.commit:
self.cursor_count(cursor, remaining)
else:
self.cursor_count(cursor, self.nentries)
cursor.close()