コード例 #1
0
ファイル: Analyzer.cpp プロジェクト: yestodaylee/CLAIMS
void Analyzer::compute_table_stat(const TableID& tab_id) {
  TableDescriptor* table = Catalog::getInstance()->getTable(tab_id);

  LogicalOperator* scan = new LogicalScan(table->getProjectoin(0));
  std::vector<Attribute> group_by_attributes;
  std::vector<Attribute> aggregation_attributes;

  aggregation_attributes.push_back(Attribute(ATTRIBUTE_ANY));

  std::vector<PhysicalAggregation::State::Aggregation> aggregation_function;
  aggregation_function.push_back(PhysicalAggregation::State::kCount);
  LogicalOperator* agg = new LogicalAggregation(
      group_by_attributes, aggregation_attributes, aggregation_function, scan);
  LogicalOperator* root =
      new LogicalQueryPlanRoot(0, agg, LogicalQueryPlanRoot::kResultCollector);

  PhysicalOperatorBase* collector =
      root->GetPhysicalPlan(1024 * 64 - sizeof(unsigned));
  collector->Open();
  collector->Next(0);
  collector->Close();
  ResultSet* resultset = collector->GetResultSet();
  ResultSet::Iterator it = resultset->createIterator();
  BlockStreamBase::BlockStreamTraverseIterator* b_it =
      it.nextBlock()->createIterator();
  const unsigned long tuple_count = *(unsigned long*)b_it->nextTuple();
  BlockStreamBase* block;
  while (block = it.nextBlock()) {
    BlockStreamBase::BlockStreamTraverseIterator* b_it =
        block->createIterator();
  }
  TableStatistic* tab_stat = new TableStatistic();
  tab_stat->number_of_tuples_ = tuple_count;
  printf("Statistics for table %s is gathered!\n",
         Catalog::getInstance()->getTable(tab_id)->getTableName().c_str());
  tab_stat->print();
  StatManager::getInstance()->setTableStatistic(tab_id, tab_stat);
  resultset->destory();
  root->~LogicalOperator();
}
コード例 #2
0
ファイル: Analyzer.cpp プロジェクト: yestodaylee/CLAIMS
unsigned long Analyzer::getDistinctCardinality(const AttributeID& attr_id) {
  LogicalOperator* scan = new LogicalScan(
      Catalog::getInstance()->getTable(attr_id.table_id)->getProjectoin(0));

  std::vector<Attribute> group_by_attributes;
  group_by_attributes.push_back(
      Catalog::getInstance()->getTable(attr_id.table_id)->getAttribute(
          attr_id.offset));

  LogicalOperator* agg = new LogicalAggregation(
      group_by_attributes, std::vector<Attribute>(),
      std::vector<PhysicalAggregation::State::Aggregation>(), scan);

  std::vector<Attribute> aggregation_attributes;
  aggregation_attributes.push_back(Attribute(ATTRIBUTE_ANY));
  std::vector<PhysicalAggregation::State::Aggregation> aggregation_function;
  aggregation_function.push_back(PhysicalAggregation::State::kCount);

  LogicalOperator* count_agg =
      new LogicalAggregation(std::vector<Attribute>(), aggregation_attributes,
                             aggregation_function, agg);

  LogicalOperator* root = new LogicalQueryPlanRoot(
      0, count_agg, LogicalQueryPlanRoot::kResultCollector);

  PhysicalOperatorBase* collector =
      root->GetPhysicalPlan(1024 * 64 - sizeof(unsigned));
  collector->Open();
  collector->Next(0);
  collector->Close();
  ResultSet* resultset = collector->GetResultSet();
  ResultSet::Iterator it = resultset->createIterator();
  BlockStreamBase::BlockStreamTraverseIterator* b_it =
      it.nextBlock()->createIterator();
  const unsigned long distinct_cardinality = *(unsigned long*)b_it->nextTuple();

  resultset->destory();
  collector->~PhysicalOperatorBase();
  root->~LogicalOperator();
  return distinct_cardinality;
}