本文整理汇总了C++中TableTuple类的典型用法代码示例。如果您正苦于以下问题:C++ TableTuple类的具体用法?C++ TableTuple怎么用?C++ TableTuple使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TableTuple类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: computeOffsets
size_t DRTupleStream::computeOffsets(DRRecordType &type,
const std::pair<const TableIndex*, uint32_t> &indexPair,
TableTuple &tuple,
size_t &rowHeaderSz,
size_t &rowMetadataSz,
const std::vector<int> *&interestingColumns) {
interestingColumns = NULL;
rowMetadataSz = sizeof(int32_t);
int columnCount;
switch (type) {
case DR_RECORD_DELETE:
case DR_RECORD_UPDATE:
if (indexPair.first) {
// The index-optimized versions of these types have values exactly
// 5 larger than the unoptimized versions (asserted in test)
// DR_RECORD_DELETE => DR_RECORD_DELETE_BY_INDEX
// DR_RECORD_UPDATE => DR_RECORD_UPDATE_BY_INDEX
type = static_cast<DRRecordType>((int)type + 5);
interestingColumns = &(indexPair.first->getColumnIndices());
rowMetadataSz += sizeof(int32_t);
columnCount = static_cast<int>(interestingColumns->size());
} else {
columnCount = tuple.sizeInValues();
}
break;
default:
columnCount = tuple.sizeInValues();
break;
}
int nullMaskLength = ((columnCount + 7) & -8) >> 3;
rowHeaderSz = rowMetadataSz + nullMaskLength;
return rowHeaderSz + tuple.maxDRSerializationSize(interestingColumns);
}
示例2: TEST_F
TEST_F(AntiCacheEvictionManagerTest, TestEvictionOrder)
{
int num_tuples = 100;
initTable(true);
TableTuple tuple = m_table->tempTuple();
int tuple_size = m_tableSchema->tupleLength() + TUPLE_HEADER_SIZE;
for(int i = 0; i < num_tuples; i++) // insert 10 tuples
{
tuple.setNValue(0, ValueFactory::getIntegerValue(m_tuplesInserted++));
tuple.setNValue(1, ValueFactory::getIntegerValue(rand()));
m_table->insertTuple(tuple);
}
EvictionIterator itr(m_table);
itr.reserve(20 * tuple_size);
ASSERT_TRUE(itr.hasNext());
uint32_t oldTimeStamp = 0;
while(itr.hasNext()) {
itr.next(tuple);
uint32_t newTimeStamp = tuple.getTimeStamp();
ASSERT_LE(oldTimeStamp, newTimeStamp);
oldTimeStamp = newTimeStamp;
}
cleanupTable();
}
示例3: VOLT_INFO
void AntiCacheEvictionManager::printLRUChain(PersistentTable* table, int max, bool forward)
{
VOLT_INFO("num tuples in chain: %d", table->getNumTuplesInEvictionChain());
VOLT_INFO("oldest tuple id: %u", table->getOldestTupleID());
VOLT_INFO("newest tuple id: %u", table->getNewestTupleID());
char chain[max * 4];
int tuple_id;
TableTuple tuple = table->tempTuple();
if(forward)
tuple_id = table->getOldestTupleID();
else
tuple_id = table->getNewestTupleID();
chain[0] = '\0';
int iterations = 0;
while(iterations < table->getNumTuplesInEvictionChain() && iterations < max)
{
strcat(chain, itoa(tuple_id));
strcat(chain, " ");
tuple.move(table->dataPtrForTuple(tuple_id));
if(forward)
tuple_id = tuple.getNextTupleInChain();
else
tuple_id = tuple.getPreviousTupleInChain();
iterations++;
}
VOLT_INFO("LRU CHAIN: %s", chain);
}
示例4: throwFatalException
Table* AntiCacheEvictionManager::evictBlock(PersistentTable *table, long blockSize, int numBlocks) {
int32_t lastTuplesEvicted = table->getTuplesEvicted();
int32_t lastBlocksEvicted = table->getBlocksEvicted();
int64_t lastBytesEvicted = table->getBytesEvicted();
if (table->evictBlockToDisk(blockSize, numBlocks) == false) {
throwFatalException("Failed to evict tuples from table '%s'", table->name().c_str());
}
int32_t tuplesEvicted = table->getTuplesEvicted() - lastTuplesEvicted;
int32_t blocksEvicted = table->getBlocksEvicted() - lastBlocksEvicted;
int64_t bytesEvicted = table->getBytesEvicted() - lastBytesEvicted;
m_evictResultTable->deleteAllTuples(false);
TableTuple tuple = m_evictResultTable->tempTuple();
int idx = 0;
tuple.setNValue(idx++, ValueFactory::getStringValue(table->name()));
tuple.setNValue(idx++, ValueFactory::getIntegerValue(static_cast<int32_t>(tuplesEvicted)));
tuple.setNValue(idx++, ValueFactory::getIntegerValue(static_cast<int32_t>(blocksEvicted)));
tuple.setNValue(idx++, ValueFactory::getBigIntValue(static_cast<int32_t>(bytesEvicted)));
m_evictResultTable->insertTuple(tuple);
return (m_evictResultTable);
}
示例5: assert
bool TableIndex::replaceEntryNoKeyChange(const TableTuple &destinationTuple, const TableTuple &originalTuple)
{
assert(originalTuple.address() != destinationTuple.address());
if (isPartialIndex()) {
const AbstractExpression* predicate = getPredicate();
if (!predicate->eval(&destinationTuple, NULL).isTrue() && !predicate->eval(&originalTuple, NULL).isTrue()) {
// both tuples fail the predicate. Nothing to do. Return TRUE
return true;
} else if (predicate->eval(&destinationTuple, NULL).isTrue() && !predicate->eval(&originalTuple, NULL).isTrue()) {
// The original tuple fails the predicate meaning the tuple is not indexed.
// Simply add the new tuple
TableTuple conflict(destinationTuple.getSchema());
addEntryDo(&destinationTuple, &conflict);
return conflict.isNullTuple();
} else if (!predicate->eval(&destinationTuple, NULL).isTrue() && predicate->eval(&originalTuple, NULL).isTrue()) {
// The destination tuple fails the predicate. Simply delete the original tuple
return deleteEntryDo(&originalTuple);
} else {
// both tuples pass the predicate.
assert(predicate->eval(&destinationTuple, NULL).isTrue() && predicate->eval(&originalTuple, NULL).isTrue());
return replaceEntryNoKeyChangeDo(destinationTuple, originalTuple);
}
} else {
return replaceEntryNoKeyChangeDo(destinationTuple, originalTuple);
}
}
示例6: notifyTupleDelete
bool CopyOnWriteContext::notifyTupleDelete(TableTuple &tuple) {
assert(m_iterator != NULL);
if (tuple.isDirty() || m_finishedTableScan) {
return true;
}
/**
* Find out which block the address is contained in. Lower bound returns the first entry
* in the index >= the address. Unless the address happens to be equal then the block
* we are looking for is probably the previous entry. Then check if the address fits
* in the previous entry. If it doesn't then the block is something new.
*/
TBPtr block = PersistentTable::findBlock(tuple.address(), m_blocks, getTable().getTableAllocationSize());
if (block.get() == NULL) {
// tuple not in snapshot region, don't care about this tuple
return true;
}
/**
* Now check where this is relative to the COWIterator.
*/
CopyOnWriteIterator *iter = reinterpret_cast<CopyOnWriteIterator*>(m_iterator.get());
return !iter->needToDirtyTuple(block->address(), tuple.address());
}
示例7: updateWithNullsTest
void updateWithNullsTest() {
beginTxn(99, 99, 98, 70);
TableTuple first_tuple = insertTuple(m_table, prepareTempTuple(m_table, 42, 31241, "349508345.34583", "a thing", "a totally different thing altogether", 5433));
TableTuple second_tuple = insertTuple(m_table, prepareTempTuple(m_table, 24, 2321, "23455.5554", "and another", "this is starting to get even sillier", 2222));
endTxn(true);
flushAndApply(99);
EXPECT_EQ(2, m_tableReplica->activeTupleCount());
beginTxn(100, 100, 99, 71);
TableTuple tuple_to_update = m_table->lookupTupleByValues(first_tuple);
ASSERT_FALSE(tuple_to_update.isNullTuple());
TableTuple updated_tuple = secondTupleWithNulls(m_table);
m_table->updateTuple(tuple_to_update, updated_tuple);
endTxn(true);
flushAndApply(100);
EXPECT_EQ(2, m_tableReplica->activeTupleCount());
TableTuple expected_tuple = secondTupleWithNulls(m_table);
TableTuple tuple = m_tableReplica->lookupTupleByValues(expected_tuple);
ASSERT_FALSE(tuple.isNullTuple());
tuple = m_table->lookupTupleByValues(second_tuple);
ASSERT_FALSE(tuple.isNullTuple());
}
示例8: TEST_F
TEST_F(DRBinaryLogTest, PartialTxnRollback) {
beginTxn(98, 98, 97, 69);
TableTuple first_tuple = insertTuple(m_table, prepareTempTuple(m_table, 99, 29058, "92384598.2342", "what", "really, why am I writing anything in these?", 3455));
endTxn(true);
beginTxn(99, 99, 98, 70);
TableTuple second_tuple = insertTuple(m_table, prepareTempTuple(m_table, 42, 55555, "349508345.34583", "a thing", "a totally different thing altogether", 5433));
// Simulate a second batch within the same txn
UndoQuantum* uq = m_undoLog.generateUndoQuantum(m_undoToken + 1);
m_context->setupForPlanFragments(uq, addPartitionId(99), addPartitionId(99),
addPartitionId(98), addPartitionId(70));
insertTuple(m_table, prepareTempTuple(m_table, 24, 2321, "23455.5554", "and another", "this is starting to get even sillier", 2222));
m_undoLog.undo(m_undoToken + 1);
endTxn(true);
flushAndApply(100);
EXPECT_EQ(2, m_tableReplica->activeTupleCount());
TableTuple tuple = m_tableReplica->lookupTupleByValues(first_tuple);
ASSERT_FALSE(tuple.isNullTuple());
tuple = m_tableReplica->lookupTupleByValues(second_tuple);
ASSERT_FALSE(tuple.isNullTuple());
}
示例9: TEST_F
TEST_F(TableTupleTest, ComputeNonInlinedMemory)
{
UniqueEngine engine = UniqueEngineBuilder().build();
Pool *pool = ExecutorContext::getTempStringPool();
// Make sure that inlined strings are actually inlined
int32_t maxInlinableLength = UNINLINEABLE_OBJECT_LENGTH/MAX_BYTES_PER_UTF8_CHARACTER - 1;
ScopedTupleSchema allInlineSchema{Tools::buildSchema(VALUE_TYPE_BIGINT,
std::make_pair(VALUE_TYPE_VARCHAR, maxInlinableLength))};
PoolBackedTupleStorage tupleStorage;
tupleStorage.init(allInlineSchema.get(), pool);
tupleStorage.allocateActiveTuple();
TableTuple inlineTuple = tupleStorage;
Tools::setTupleValues(&inlineTuple, int64_t(0), "dude");
EXPECT_EQ(0, inlineTuple.getNonInlinedMemorySizeForPersistentTable());
// Now check that an non-inlined schema returns the right thing.
int32_t nonInlinableLength = UNINLINEABLE_OBJECT_LENGTH + 10000;
ScopedTupleSchema nonInlinedSchema{Tools::buildSchema(VALUE_TYPE_BIGINT,
std::make_pair(VALUE_TYPE_VARCHAR, nonInlinableLength))};
tupleStorage.init(nonInlinedSchema.get(), pool);
tupleStorage.allocateActiveTuple();
TableTuple nonInlinedTuple = tupleStorage;
NValue nonInlinedString = Tools::nvalueFromNative("123456");
Tools::setTupleValues(&nonInlinedTuple, int64_t(0), nonInlinedString);
EXPECT_EQ(nonInlinedString.getAllocationSizeForObjectInPersistentStorage(),
nonInlinedTuple.getNonInlinedMemorySizeForPersistentTable());
}
示例10: deleteNVMEvictedTuple
void NVMEvictedTable::deleteNVMEvictedTuple(TableTuple source) {
if(source.address() == NULL)
return;
source.freeObjectColumns();
deleteTupleStorage(source);
}
示例11: TEST_F
TEST_F(DRBinaryLogTest, PartitionedTableRollbacks) {
m_singleColumnTable->setDR(false);
beginTxn(99, 99, 98, 70);
TableTuple source_tuple = insertTuple(m_table, prepareTempTuple(m_table, 42, 55555, "349508345.34583", "a thing", "a totally different thing altogether", 5433));
endTxn(false);
// Intentionally ignore the fact that a rollback wouldn't have actually advanced the
// lastCommittedSpHandle. Our goal is to tick such that, if data had been produced,
// it would flush itself out now
ASSERT_FALSE(flush(99));
EXPECT_EQ(-1, m_drStream.getLastCommittedSequenceNumberAndUniqueId().first);
EXPECT_EQ(0, m_tableReplica->activeTupleCount());
beginTxn(100, 100, 99, 71);
source_tuple = insertTuple(m_table, prepareTempTuple(m_table, 99, 29058, "92384598.2342", "what", "really, why am I writing anything in these?", 3455));
endTxn(true);
// Roll back a txn that hasn't applied any binary log data
beginTxn(101, 101, 100, 72);
TableTuple temp_tuple = m_singleColumnTable->tempTuple();
temp_tuple.setNValue(0, ValueFactory::getTinyIntValue(1));
insertTuple(m_singleColumnTable, temp_tuple);
endTxn(false);
flushAndApply(101);
EXPECT_EQ(1, m_tableReplica->activeTupleCount());
TableTuple tuple = m_tableReplica->lookupTupleByValues(source_tuple);
ASSERT_FALSE(tuple.isNullTuple());
EXPECT_EQ(0, m_drStream.getLastCommittedSequenceNumberAndUniqueId().first);
}
示例12: deleteSomeRecords
// Delete some records from the table, forcing update of the geospatial index.
static int deleteSomeRecords(PersistentTable* table, int totalTuples, int numTuplesToDelete) {
std::cout << " Deleting " << numTuplesToDelete << " tuples...\n";
int numDeleted = 0;
StandAloneTupleStorage tableTuple(table->schema());
tableTuple.tuple().setNValue(GEOG_COL_INDEX, NValue::getNullValue(VALUE_TYPE_GEOGRAPHY));
auto start = std::chrono::high_resolution_clock::now();
std::chrono::microseconds usSpentDeleting = std::chrono::duration_cast<microseconds>(start - start);
// Choose a random row, and delete it, and do this until we've
// deleted as many rows as the caller has requested.
// Sometimes the random number generator will select a
// previously deleted row, and we just try again when this
// happens. This might seem like it would take a long time,
// but practically it happens instantaneously.
while (numDeleted < numTuplesToDelete) {
int idOfTupleToDelete = std::rand() % totalTuples;
tableTuple.tuple().setNValue(PK_COL_INDEX, ValueFactory::getIntegerValue(idOfTupleToDelete));
TableTuple tupleToDelete = table->lookupTupleByValues(tableTuple.tuple());
if (! tupleToDelete.isNullTuple()) {
start = std::chrono::high_resolution_clock::now();
table->deleteTuple(tupleToDelete);
auto end = std::chrono::high_resolution_clock::now();
usSpentDeleting += std::chrono::duration_cast<microseconds>(end - start);
++numDeleted;
}
}
std::cout << " Average duration of delete: " << (usSpentDeleting.count() / numDeleted) << " us\n";
return numDeleted;
}
示例13: addRandomUniqueTuples
void addRandomUniqueTuples(Table *table, int numTuples) {
TableTuple tuple = table->tempTuple();
for (int ii = 0; ii < numTuples; ii++) {
tuple.setNValue(0, ValueFactory::getIntegerValue(m_primaryKeyIndex++));
tuple.setNValue(1, ValueFactory::getIntegerValue(rand()));
table->insertTuple(tuple);
}
}
示例14: processTupleDelete
void MaterializedViewMetadata::processTupleDelete(TableTuple &oldTuple) {
// don't change the view if this tuple doesn't match the predicate
if (m_filterPredicate && (m_filterPredicate->eval(&oldTuple, NULL).isFalse()))
return;
// this will assert if the tuple isn't there as param expected is true
findExistingTuple(oldTuple, true);
// clear the tuple that will be built to insert or overwrite
memset(m_updatedTupleBackingStore, 0, m_target->schema()->tupleLength() + 1);
//printf(" Existing tuple: %s.\n", m_existingTuple.debugNoHeader().c_str());
//fflush(stdout);
// set up the first column, which is a count
NValue count = m_existingTuple.getNValue(m_groupByColumnCount).op_decrement();
//printf(" Count is: %d.\n", (int)(m_existingTuple.getSlimValue(m_groupByColumnCount).getBigInt()));
//fflush(stdout);
// check if we should remove the tuple
if (count.isZero()) {
m_target->deleteTuple(m_existingTuple, true);
return;
}
// assume from here that we're just updating the existing row
int colindex = 0;
// set up the first n columns, based on group-by columns
for (colindex = 0; colindex < m_groupByColumnCount; colindex++) {
m_updatedTuple.setNValue(colindex, oldTuple.getNValue(m_groupByColumns[colindex]));
}
m_updatedTuple.setNValue(colindex, count);
colindex++;
// set values for the other columns
for (int i = colindex; i < m_outputColumnCount; i++) {
NValue oldValue = oldTuple.getNValue(m_outputColumnSrcTableIndexes[i]);
NValue existingValue = m_existingTuple.getNValue(i);
if (m_outputColumnAggTypes[i] == EXPRESSION_TYPE_AGGREGATE_SUM) {
m_updatedTuple.setNValue(i, existingValue.op_subtract(oldValue));
}
else if (m_outputColumnAggTypes[i] == EXPRESSION_TYPE_AGGREGATE_COUNT) {
m_updatedTuple.setNValue(i, existingValue.op_decrement());
}
else {
throw SerializableEEException(VOLT_EE_EXCEPTION_TYPE_EEEXCEPTION,
"Error in materialized view table"
" update.");
}
}
// update the row
// shouldn't need to update indexes as this shouldn't ever change the key
m_target->updateTuple(m_updatedTuple, m_existingTuple, false);
}
示例15: processTupleInsert
void MaterializedViewMetadata::processTupleInsert(TableTuple &newTuple) {
// don't change the view if this tuple doesn't match the predicate
if (m_filterPredicate
&& (m_filterPredicate->eval(&newTuple, NULL).isFalse()))
return;
bool exists = findExistingTuple(newTuple);
if (!exists) {
// create a blank tuple
m_existingTuple.move(m_emptyTupleBackingStore);
}
// clear the tuple that will be built to insert or overwrite
memset(m_updatedTupleBackingStore, 0, m_target->schema()->tupleLength() + 1);
int colindex = 0;
// set up the first n columns, based on group-by columns
for (colindex = 0; colindex < m_groupByColumnCount; colindex++) {
m_updatedTuple.setNValue(colindex,
newTuple.getNValue(m_groupByColumns[colindex]));
}
// set up the next column, which is a count
m_updatedTuple.setNValue(colindex,
m_existingTuple.getNValue(colindex).op_increment());
colindex++;
// set values for the other columns
for (int i = colindex; i < m_outputColumnCount; i++) {
NValue newValue = newTuple.getNValue(m_outputColumnSrcTableIndexes[i]);
NValue existingValue = m_existingTuple.getNValue(i);
if (m_outputColumnAggTypes[i] == EXPRESSION_TYPE_AGGREGATE_SUM) {
m_updatedTuple.setNValue(i, newValue.op_add(existingValue));
}
else if (m_outputColumnAggTypes[i] == EXPRESSION_TYPE_AGGREGATE_COUNT) {
m_updatedTuple.setNValue(i, existingValue.op_increment());
}
else {
char message[128];
sprintf(message, "Error in materialized view table update for"
" col %d. Expression type %d", i, m_outputColumnAggTypes[i]);
throw SerializableEEException(VOLT_EE_EXCEPTION_TYPE_EEEXCEPTION,
message);
}
}
// update or insert the row
if (exists) {
// shouldn't need to update indexes as this shouldn't ever change the
// key
m_target->updateTuple(m_updatedTuple, m_existingTuple, false);
}
else {
m_target->insertTuple(m_updatedTuple);
}
}