示例#1
0
void BuildIndex(std::shared_ptr<index::Index> index,
                storage::DataTable *table) {
  auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
  auto txn = txn_manager.BeginTransaction();

  oid_t start_tile_group_count = START_OID;
  oid_t table_tile_group_count = table->GetTileGroupCount();

  while (start_tile_group_count < table_tile_group_count) {
    auto tile_group = table->GetTileGroup(start_tile_group_count++);
    auto column_count = table->GetSchema()->GetColumnCount();
    oid_t active_tuple_count = tile_group->GetNextTupleSlot();

    for (oid_t tuple_id = 0; tuple_id < active_tuple_count; tuple_id++) {
      std::unique_ptr<storage::Tuple> tuple_ptr(
          new storage::Tuple(table->GetSchema(), true));
      CopyTuple(tuple_id, tuple_ptr.get(), tile_group.get(), column_count);
      ItemPointer location(tile_group->GetTileGroupId(), tuple_id);

      ItemPointer *index_entry_ptr = nullptr;
      table->InsertInIndexes(tuple_ptr.get(), location, txn, &index_entry_ptr);
    }
    index->IncrementIndexedTileGroupOffset();
  }

  txn_manager.CommitTransaction(txn);
}
示例#2
0
void IndexTuner::BuildIndex(storage::DataTable* table,
                            std::shared_ptr<index::Index> index) {

  auto table_schema = table->GetSchema();
  auto index_tile_group_offset = index->GetIndexedTileGroupOff();
  auto table_tile_group_count = table->GetTileGroupCount();
  oid_t tile_groups_indexed = 0;

  auto index_schema = index->GetKeySchema();
  auto indexed_columns = index_schema->GetIndexedColumns();
  std::unique_ptr<storage::Tuple> key(new storage::Tuple(index_schema, true));

  while (index_tile_group_offset < table_tile_group_count &&
         (tile_groups_indexed < max_tile_groups_indexed)) {

    std::unique_ptr<storage::Tuple> tuple_ptr(
        new storage::Tuple(table_schema, true));

    auto tile_group = table->GetTileGroup(index_tile_group_offset);
    auto tile_group_id = tile_group->GetTileGroupId();
    oid_t active_tuple_count = tile_group->GetNextTupleSlot();

    for (oid_t tuple_id = 0; tuple_id < active_tuple_count; tuple_id++) {
      // Copy over the tuple
      tile_group->CopyTuple(tuple_id, tuple_ptr.get());

      // Set the location
      ItemPointer location(tile_group_id, tuple_id);

      // Set the key
      key->SetFromTuple(tuple_ptr.get(), indexed_columns, index->GetPool());

      // Insert in specific index
      // index->InsertEntry(key.get(), location);
    }

    // Update indexed tile group offset (set of tgs indexed)
    index->IncrementIndexedTileGroupOffset();

    // Sleep a bit
    // std::this_thread::sleep_for(std::chrono::microseconds(sleep_duration));

    index_tile_group_offset++;
    tile_groups_indexed++;
  }
}
示例#3
0
cep_state_ptr stateful_within::create_state(tuple_ptr context, cep_state* parent) {
        
        universal_state* state = new universal_state(this, parent);
        
        std::vector<boost::any> data;
        for(int i=0; i<context->size()-2; i++) {
                data.push_back((*context)[i]);
        }
        
        data.push_back(boost::posix_time::second_clock::local_time() + boost::posix_time::seconds(range) );
        data.push_back(boost::posix_time::second_clock::local_time() );
        tuple_ptr result = tuple_ptr(new tuple(data));
        
        evaluate_true(NULL, state, result);
        cep_state_ptr result_state = cep_state_ptr(state);
        within_timer* timer = new within_timer(this, result_state, range);
        
        state->set_property("timer", timer);
        
        return result_state;
}
示例#4
0
//don't check, if statement is NULL
tuple_ptr sqlite_source::get_tuple() const throw()
{
	int col_count = m_stream_schema->num_columns();
	boost::any tuple_data[col_count];
	for (int col = 0; col < col_count; ++col)
	{
		column_info current_column = m_stream_schema->get_column_info(col);
		switch (current_column.get_column_type())
		{
			case column_info::IntType:
			{
				tuple_data[col] = sqlite3_column_int(m_data, col);
				break;
			}
			case column_info::DoubleType:
			{
				tuple_data[col] = sqlite3_column_double(m_data, col);
				break;
			}
			case column_info::UnknownType:
			case column_info::StringType:
			{
				std::stringstream help;
				help << sqlite3_column_text(m_data, col);
				tuple_data[col] = std::string(help.str());
				break;
			}
			default:
			{
				//should never happens, because, stream_schema was created
				//by this instance, and DteType and NullType wasn't used
			}
		}

	}
	return tuple_ptr(new tuple(tuple_data, tuple_data + col_count));
}