예제 #1
0
void MergeJoin::InitializeFlatLayout(IRelationalOperator * lChild, 
				     IRelationalOperator * rChild,
				     const Columns & joinColumns)
{
  m_child[LEFT] = lChild;
  m_child[RIGHT] = rChild;

  /* create (left|right)+(proj|join) schemas. */
  for (int i = 0; i < N_BRANCHES; i++)
    {
      int idx = i * 2;
      Schema * joinSchema = new Schema();

      m_consumed[i] = true;
      m_inBuffer[i] = BufferManager::getInstance()->allocate();
      
      /* create projection & join schemas */
      m_tuple[idx|PROJ].schema(m_child[i]->schema());
      m_tuple[idx|JOIN].schema(m_child[i]->schema());

      for (int j = 0; j < joinColumns.count(); j++)
	{ 
	  const Column * column = joinColumns.at(j);
	  const Schema * schema = m_tuple[idx|PROJ].schema();
	  
	  if (schema->contains(column->m_qualified_name))
	    {
	      const Attribute * a = (*schema)[column->m_qualified_name];
	      m_joinCols[idx|PROJ].push_back(a);
	      m_joinCols[idx|JOIN].push_back(a);
	    }  
	}

      m_tuple[idx|PROJ].m_data = new byte[m_tuple[idx|PROJ].schema()->rsize()];
      m_tuple[idx|JOIN].m_data = new byte[m_tuple[idx|JOIN].schema()->rsize()];

      m_tsr[i] = new TupleStreamReader(*m_inBuffer[i]);
    }
  
  /* create merged schema */
  for (int i = 0; i < N_BRANCHES; i++)
    {
      int idx = i * 2;
      for (int j = 0; j < m_tuple[idx].schema()->nitems(); j++)
	{
	  m_schema.add(m_tuple[idx].schema()->at(j));
	}
    }
  
  m_data = new byte[m_schema.rsize()];
  m_buffer = BufferManager::getInstance()->allocate();
  m_tsw = new TupleStreamWriter(*m_buffer, m_schema.rsize());
}
예제 #2
0
void Retrieve_Template::intitialize(QString table,Columns columns,QString where){
        this->query=new QSqlQuery (theSarf->db);
	QString cols;
	for(int i=0;i<columns.count();i++)
	{
		if (i!=0)
			cols.append(" ,");
		cols.append(columns[i]);
	}
	QString stmt( "SELECT %2 FROM %1 %3");
	stmt=stmt.arg(table).arg(cols).arg(where==""?"":QString("WHERE ").append(where) );
	err= (!execute_query(stmt,*(this->query)));
	if (!err)
		this->columns=columns;
}
예제 #3
0
void MergeJoin::InitializePartitionLayout(IRelationalOperator * lChild, 
					  IRelationalOperator * rChild,
					  const Columns & joinColumns)
{
  std::vector<const Attribute *> layout;
  std::vector<const Attribute *> partition[2];

  m_child[LEFT] = lChild;
  m_child[RIGHT] = rChild;

  /* create (left|right)+(proj|join) schemas. */
  for (int i = 0; i < N_BRANCHES; i++)
    {
      int idx = i * 2;
      Schema * joinSchema = new Schema(); joinSchema->m_partitions = 1;

      layout.clear();
      layout.reserve(m_child[i]->schema()->nitems());

      m_consumed[i] = true;
      m_inBuffer[i] = BufferManager::getInstance()->allocate();

      /* create projection schema */
      m_tuple[idx|PROJ].schema(m_child[i]->schema());
            
      /* retrieve join columns for ith child */
      for (int j = 0; j < joinColumns.count(); j++)
	{ 
	  const Column * column = joinColumns.at(j);
	  const Schema * schema = m_tuple[idx|PROJ].schema();

	  if (schema->contains(column->m_qualified_name))
	    {
	      const Attribute * a = (*schema)[column->m_qualified_name];
	      m_joinCols[idx|PROJ].push_back(a);

	      joinSchema->add(a);
	      m_joinCols[idx|JOIN].push_back(a);
	    }  
	}

      /* create layouts for children. */
      partition[0].clear();
      partition[1].clear();
      m_layout[i] = new MaterializationLayout(2, m_inBuffer[i]->capacity(), 
					      m_tuple[idx|PROJ].schema()->rsize());

      for (int j = 0; j < m_tuple[idx|PROJ].schema()->nitems(); j++)
	{
	  const Attribute * a = m_tuple[idx|PROJ].schema()->at(j);
	  if (!joinColumns.contains(a->qualified_name()))
	    {
	      partition[1].push_back(a);
	    }
	  else
	    {
	      partition[0].push_back(a);
	      layout.push_back(a);
	    }
	}

      m_layout[i]->add(partition[0]);
      m_layout[i]->add(partition[1]);

      /* synchronize schemas for read optimization */
      for (int j = 0; j < partition[1].size(); j++)
	{
	  layout.push_back(partition[1][j]);
	}

      Schema * s = new Schema(&layout);
      s->m_partitions = 3;
      m_tuple[idx|PROJ].schema(s); 
      
      /* create join schema */
      m_tuple[idx|JOIN].schema(joinSchema);

      m_tuple[idx|PROJ].m_data = new byte[m_tuple[idx|PROJ].schema()->rsize()];
      m_tuple[idx|JOIN].m_data = new byte[m_tuple[idx|JOIN].schema()->rsize()];

      m_tsr[i] = new TupleStreamReader(*m_inBuffer[i]);
      m_tsr[i]->layout(m_layout[i]);
      m_child[i]->layout(m_layout[i]);
    }
  
  /* create merged schema */
  for (int i = 0; i < N_BRANCHES; i++)
    {
      int idx = i * 2;
      for (int j = 0; j < m_tuple[idx].schema()->nitems(); j++)
	{
	  m_schema.add(m_tuple[idx].schema()->at(j));
	}
    }
  
  m_data = new byte[m_schema.rsize()];
  m_buffer = BufferManager::getInstance()->allocate();
  m_tsw = new TupleStreamWriter(*m_buffer, m_schema.rsize());
}