当前位置: 首页>>代码示例>>C++>>正文


C++ TableDescriptor类代码示例

本文整理汇总了C++中TableDescriptor的典型用法代码示例。如果您正苦于以下问题:C++ TableDescriptor类的具体用法?C++ TableDescriptor怎么用?C++ TableDescriptor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TableDescriptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: test_logical_index_scan

static void test_logical_index_scan()
{
	vector<IndexScanIterator::query_range> q_range;
	TableDescriptor* table = Catalog::getInstance()->getTable("cj");
	IndexScanIterator::query_range q;
	int value = 0;
	while (true)
	{
		q_range.clear();
		cout << "Input the search sec_code: ";
		cin >> value;

		q.value_low = malloc(sizeof(int));		//newmalloc
		q.value_low = (void*)(&value);
		q.comp_low = EQ;
		q.value_high = malloc(sizeof(int));		//newmalloc
		q.value_high = (void*) (&value);
		q.comp_high = EQ;
		q.c_type.type = t_int;
		q.c_type.operate = new OperateInt();
		q_range.push_back(q);

		LogicalOperator* index_scan = new LogicalIndexScan(table->getProjectoin(0)->getProjectionID(), table->getAttribute("sec_code"), q_range);
		const NodeID collector_node_id = 0;
		LogicalOperator* root = new LogicalQueryPlanRoot(collector_node_id, index_scan, LogicalQueryPlanRoot::PRINT);
		BlockStreamIteratorBase* executable_query_plan = root->getIteratorTree(1024 * 64);
		executable_query_plan->open();
		while (executable_query_plan->next(0));
		executable_query_plan->close();
		executable_query_plan->~BlockStreamIteratorBase();
		root->~LogicalOperator();
	}
}
开发者ID:egraldlo,项目名称:CLAIMS,代码行数:33,代码来源:test_IndexManager_serialize.cpp

示例2: analyse

void Analyzer::analyse(TableID table_id, analysis_level level) {
  TableStatistic* tab_stat =
      StatManager::getInstance()->getTableStatistic(table_id);
  TableDescriptor* table = Catalog::getInstance()->getTable(table_id);
  if (tab_stat == 0) {
    //    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<BlockStreamAggregationIterator::State::aggregation>
    //    aggregation_function;
    //    aggregation_function.push_back(
    //        BlockStreamAggregationIterator::State::count);
    //    LogicalOperator* agg = new Aggregation(group_by_attributes,
    //                                           aggregation_attributes,
    //                                           aggregation_function, scan);
    //    LogicalOperator* root = new LogicalQueryPlanRoot(
    //        0, agg, LogicalQueryPlanRoot::RESULTCOLLECTOR);
    //
    //    BlockStreamIteratorBase* collector = root->getIteratorTree(
    //        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();
    //
    //    }
    //    tab_stat = new TableStatistic();
    //    tab_stat->number_of_tuples_ = tuple_count;
    //    printf("Statistics for table %s is
    //        gathered!\n",Catalog::getInstance()->getTable(table_id)
    //    ->getTableName().c_str());
    //        tab_stat->print();
    //        StatManager::getInstance()->setTableStatistic(table_id, tab_stat);
    //        resultset->destory();
    //        root->~LogicalOperator();
    compute_table_stat(table_id);
  }

  if (level == a_l_attribute) {
    std::vector<Attribute> attribute_list = table->getAttributes();
    for (unsigned i = 0; i < attribute_list.size(); i++) {
      compute_attribute_stat(attribute_list[i].getID());
    }
  }
}
开发者ID:yestodaylee,项目名称:CLAIMS,代码行数:57,代码来源:Analyzer.cpp

示例3: bulk_test_logical_index_scan

static void bulk_test_logical_index_scan() {
  vector<IndexScanIterator::query_range> q_range;
  int count = 1022;
  ifstream infile("/home/scdong/code/sec_code", ios::in);
  ofstream outfile("/home/scdong/code/fail_log.dat", ios::out);
  unsigned long int value = 0;
  unsigned long int expect_num;
  TableDescriptor* table = Catalog::getInstance()->getTable("cj");
  IndexScanIterator::query_range q2;
  while (count > 0) {
    q_range.clear();
    infile >> value >> expect_num;

    q2.value_low = malloc(sizeof(int));  // newmalloc
    q2.value_low = (void*)(&value);
    q2.comp_low = EQ;
    q2.value_high = malloc(sizeof(int));  // newmalloc
    q2.value_high = (void*)(&value);
    q2.comp_high = EQ;
    q2.c_type.type = t_int;
    q2.c_type.operate = new OperateInt();
    q_range.push_back(q2);

    LogicalOperator* index_scan =
        new LogicalIndexScan(table->getProjectoin(0)->getProjectionID(),
                             table->getAttribute("sec_code"), q_range);
    const NodeID collector_node_id = 0;

    LogicalOperator* root = new LogicalQueryPlanRoot(
        collector_node_id, index_scan, LogicalQueryPlanRoot::kResultCollector);
    PhysicalOperatorBase* executable_query_plan =
        root->GetPhysicalPlan(1024 * 64);
    executable_query_plan->Open();
    while (executable_query_plan->Next(0))
      ;
    executable_query_plan->Close();

    ResultSet* result_set = executable_query_plan->getResultSet();

    const unsigned long int number_of_tuples = result_set->getNumberOftuples();
    executable_query_plan->~PhysicalOperatorBase();
    root->~LogicalOperator();
    cout << 1022 - count << ": Sec_code: " << value
         << "\t Result: " << number_of_tuples << endl;
    if (!print_test_name_result(number_of_tuples == expect_num, "Index Scan")) {
      printf("\tIndex Scan sec_code = %d, Expected:%d actual: %d\n", value,
             expect_num, number_of_tuples);
      outfile << "Index Scan sec_code = " << value << "\tFAIL!\n";
      outfile << "\tExcepted: " << expect_num
              << "\tActual: " << number_of_tuples << endl;
    }
    count--;
  }
}
开发者ID:JolyZhang,项目名称:CLAIMS,代码行数:54,代码来源:test_IndexManager_serialize.cpp

示例4: GetOrderByKey

int LogicalSort::GetOrderByKey(const char *table_name, const char *attr) {
  // Use table name and attribute name to get the number.
  for (unsigned attr_id = 0;
       attr_id < child_plan_context_.attribute_list_.size(); attr_id++) {
    TableDescriptor *table = Catalog::getInstance()->getTable(
        child_plan_context_.attribute_list_[attr_id].table_id_);
    string tablename = table->getTableName();
    if ((tablename.compare(table_name) == 0) &&
        (child_plan_context_.attribute_list_[attr_id].attrName.compare(attr) ==
         0)) {
      return attr_id;
    }
  }
}
开发者ID:FishYoung,项目名称:CLAIMS,代码行数:14,代码来源:logical_sort.cpp

示例5: test_index_filter_performance

static void test_index_filter_performance(int value_high) {
  unsigned long long int start = curtick();
  vector<IndexScanIterator::query_range> q_range;
  q_range.clear();
  int value_low = 10107;
  //	int value_high = 600257;
  TableDescriptor* table = Catalog::getInstance()->getTable("cj");

  IndexScanIterator::query_range q;
  q.value_low = malloc(sizeof(int));  // newmalloc
  q.value_low = (void*)(&value_low);
  q.comp_low = GEQ;
  q.value_high = malloc(sizeof(int));  // newmalloc
  q.value_high = (void*)(&value_high);
  q.comp_high = L;
  q.c_type.type = t_int;
  q.c_type.operate = new OperateInt();
  q_range.push_back(q);

  LogicalOperator* index_scan =
      new LogicalIndexScan(table->getProjectoin(0)->getProjectionID(),
                           table->getAttribute("sec_code"), q_range);
  const NodeID collector_node_id = 0;
  LogicalOperator* root = new LogicalQueryPlanRoot(
      collector_node_id, index_scan, LogicalQueryPlanRoot::PERFORMANCE);
  //	root->print();

  PerformanceMonitor* executable_query_plan =
      (PerformanceMonitor*)root->GetPhysicalPlan(1024 * 64);
  executable_query_plan->Open();
  while (executable_query_plan->Next(0))
    ;
  executable_query_plan->Close();

  //	ResultSet* result_set = executable_query_plan->getResultSet();

  const unsigned long int number_of_tuples =
      executable_query_plan->GetNumberOfTuples();
  delete executable_query_plan;
  root->~LogicalOperator();
  //	cout << "Sec_code: " << value_low << "\t Result: " << number_of_tuples
  //<< endl;
  printf("execution time: %4.4f seconds.\n", getSecond(start));
  if (!print_test_name_result(number_of_tuples == 26820, "Index Scan")) {
    printf("\tIndex Scan sec_code = %d, Expected:%d actual: %d\n", value_low,
           26820, number_of_tuples);
  }
}
开发者ID:JolyZhang,项目名称:CLAIMS,代码行数:48,代码来源:test_IndexManager_serialize.cpp

示例6: test_logical_index_building

static void test_logical_index_building()
{
	TableDescriptor* table = Catalog::getInstance()->getTable("cj");
	LogicalOperator* csb_building = new LogicalCSBIndexBuilding(table->getProjectoin(0)->getProjectionID(), table->getAttribute(3), "sec_code_index");
	const NodeID collector_node_id=0;
	LogicalOperator* root=new LogicalQueryPlanRoot(collector_node_id,csb_building,LogicalQueryPlanRoot::RESULTCOLLECTOR);
	root->print();
	BlockStreamIteratorBase* executable_query_plan=root->getIteratorTree(1024*64);
	executable_query_plan->open();
	while (executable_query_plan->next(0));
	executable_query_plan->close();

//	ResultSet* result_set = executable_query_plan->getResultSet();

	executable_query_plan->~BlockStreamIteratorBase();
	root->~LogicalOperator();
	cout << "index building finished!\n";
}
开发者ID:egraldlo,项目名称:CLAIMS,代码行数:18,代码来源:test_IndexManager_serialize.cpp

示例7: SemanticAnalisys

RetCode AstLoadTable::SemanticAnalisys(SemanticContext* sem_cnxt) {
  RetCode ret = rSuccess;

  TableDescriptor* table =
      Environment::getInstance()->getCatalog()->getTable(table_name_);
  if (NULL == table) {
    sem_cnxt->error_msg_ =
        "the table " + table_name_ + " does not exist during loading!";
    ret = rTableNotExisted;
    return ret;
  }
  if (0 == table->getNumberOfProjection()) {
    sem_cnxt->error_msg_ = "the table has not been created a projection!";
    ret = rNoProjection;
    return ret;
  }
  return ret;
}
开发者ID:JolyZhang,项目名称:CLAIMS,代码行数:18,代码来源:ast_load_stmt.cpp

示例8: SafeSprintf

bool ObjectMgr::Initialize(IKernel * kernel) {
	_kernel = kernel;
	_nextTypeId = 1;

	char path[512] = { 0 };
	SafeSprintf(path, sizeof(path), "%s/config/object.xml", tools::GetAppPath());
	olib::XmlReader conf;
	if (!conf.LoadXml(path)) {
		OASSERT(false, "load object.xml failed");
		return false;
	}

	if (conf.Root().IsExist("prop")) {
		const olib::IXmlObject& props = conf.Root()["prop"];
		for (s32 i = 0; i < props.Count(); ++i)
			_defines[props[i].GetAttributeString("name")] = (1 << i);
	}

	if (conf.Root().IsExist("table")) {
		const olib::IXmlObject& tables = conf.Root()["table"];
		for (s32 i = 0; i < tables.Count(); ++i) {
			TableDescriptor * tableModel = NEW TableDescriptor();
			const char * name = tables[i].GetAttributeString("name");
			if (!tableModel->LoadFrom(tables[i]))
				return false;

			_tableModels[tools::CalcStringUniqueId(name)] = tableModel;
		}
	}
    
    SafeSprintf(path, sizeof(path), "%s/config/dccenter/", tools::GetAppPath());
	tools::ListFileInDirection(path, ".xml", [this](const char * name, const char * path) {
		if (_namePathMap.end() != _namePathMap.find(name)) {
			OASSERT(false, "prop xml name repeated");
			return;
		}
		_namePathMap.insert(std::make_pair(name, path));
	});

	for (auto itr = _namePathMap.begin(); itr != _namePathMap.end(); ++itr)
		CreateTemplate(kernel, itr->first.GetString());

    return true;
}
开发者ID:ooeyusea,项目名称:hyper_net,代码行数:44,代码来源:ObjectMgr.cpp

示例9: compute_table_stat

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();
}
开发者ID:yestodaylee,项目名称:CLAIMS,代码行数:40,代码来源:Analyzer.cpp

示例10: test_logical_index_building

static void test_logical_index_building() {
  TableDescriptor* table = Catalog::getInstance()->getTable("cj");
  LogicalOperator* csb_building =
      new LogicalCSBIndexBuilding(table->getProjectoin(0)->getProjectionID(),
                                  table->getAttribute(3), "sec_code_index");
  const NodeID collector_node_id = 0;
  LogicalOperator* root = new LogicalQueryPlanRoot(
      collector_node_id, csb_building, LogicalQueryPlanRoot::kResultCollector);
  root->Print();
  PhysicalOperatorBase* executable_query_plan =
      root->GetPhysicalPlan(1024 * 64);
  executable_query_plan->Open();
  while (executable_query_plan->Next(0))
    ;
  executable_query_plan->Close();

  //	ResultSet* result_set = executable_query_plan->getResultSet();

  executable_query_plan->~PhysicalOperatorBase();
  root->~LogicalOperator();
  cout << "index building finished!\n";
}
开发者ID:JolyZhang,项目名称:CLAIMS,代码行数:22,代码来源:test_IndexManager_serialize.cpp

示例11: test_scan_filter_performance

static void test_scan_filter_performance(int value) {
  unsigned long long int start = curtick();
  TableDescriptor* table = Catalog::getInstance()->getTable("cj");
  LogicalOperator* cj_scan = new LogicalScan(table->getProjectoin(0));

  LogicalFilter::Condition filter_condition_1;
  filter_condition_1.add(table->getAttribute(3), AttributeComparator::GEQ,
                         std::string("10107"));
  filter_condition_1.add(table->getAttribute(3), AttributeComparator::L,
                         (void*)&value);
  LogicalOperator* filter_1 = new LogicalFilter(filter_condition_1, cj_scan);

  const NodeID collector_node_id = 0;
  LogicalOperator* root = new LogicalQueryPlanRoot(
      collector_node_id, filter_1, LogicalQueryPlanRoot::PERFORMANCE);

  PerformanceMonitor* executable_query_plan =
      (PerformanceMonitor*)root->GetPhysicalPlan(1024 * 64);
  //	executable_query_plan->print();
  executable_query_plan->Open();
  while (executable_query_plan->Next(0))
    ;
  executable_query_plan->Close();

  //	ResultSet *result_set=executable_query_plan->getResultSet();

  const unsigned long int number_of_tuples =
      executable_query_plan->GetNumberOfTuples();
  printf("execution time: %4.4f seconds.\n", getSecond(start));
  if (!print_test_name_result(number_of_tuples == 26820,
                              "Low selectivity filter")) {
    printf("\tExpected:26695 actual: %d\n", number_of_tuples);
  }
  //	result_set->~ResultSet();
  delete executable_query_plan;
  root->~LogicalOperator();
}
开发者ID:JolyZhang,项目名称:CLAIMS,代码行数:37,代码来源:test_IndexManager_serialize.cpp

示例12: query_select_fzh

static void query_select_fzh() {
  /*
   * select sum(a+1)+count(a),b
   * from T
   * group by b
   *
   * notation: p a p s
   * */
  unsigned long long int start = curtick();
  TableDescriptor* table =
      Environment::getInstance()->getCatalog()->getTable("LINEITEM");
  //===========================scan===========================
  LogicalOperator* scan = new LogicalScan(table->getProjectoin(0));

  //==========================project=========================
  vector<vector<ExpressionItem> > expr_list1;

  vector<ExpressionItem> expr1;
  vector<ExpressionItem> expr2;
  vector<ExpressionItem> expr3;
  vector<ExpressionItem> expr4;
  vector<ExpressionItem> expr5;
  vector<ExpressionItem> expr6;
  vector<ExpressionItem> expr7;
  vector<ExpressionItem> expr8;
  vector<ExpressionItem> expr9;
  vector<ExpressionItem> expr10;
  vector<ExpressionItem> expr11;
  vector<ExpressionItem> expr12;
  vector<ExpressionItem> expr13;
  vector<ExpressionItem> expr14;
  vector<ExpressionItem> expr15;
  vector<ExpressionItem> expr16;
  vector<ExpressionItem> expr17;

  ExpressionItem ei1;
  ExpressionItem ei1_1;
  ExpressionItem ei1_2;
  ExpressionItem ei1_3;
  ExpressionItem ei1_4;
  ExpressionItem ei1_5;
  ExpressionItem ei1_6;
  ExpressionItem ei1_7;
  ExpressionItem ei1_8;
  ExpressionItem ei1_9;
  ExpressionItem ei2;
  ExpressionItem ei3;
  ExpressionItem ei4;
  ExpressionItem ei5;
  ExpressionItem ei6;
  ExpressionItem ei7;
  ExpressionItem ei8;
  ExpressionItem ei9;
  ExpressionItem ei10;
  ExpressionItem ei11;
  ExpressionItem ei12;
  ExpressionItem ei13;
  ExpressionItem ei14;
  ExpressionItem ei15;
  ExpressionItem ei16;
  ExpressionItem ei17;

  ei1_1.setVariable("LINEITEM.row_id");
  //	ei1_2.setVariable("LINEITEM.L_ORDERKEY");
  ei1_2.setIntValue("1");
  ei1_3.setOperator("+");

  expr1.push_back(ei1_1);
  expr1.push_back(ei1_2);
  expr1.push_back(ei1_3);

  expr_list1.push_back(expr1);

  LogicalOperator* project1 = new LogicalProject(scan, expr_list1);

  //========================aggregation=======================
  std::vector<Attribute> group_by_attributes;
  group_by_attributes.push_back(table->getAttribute("L_RETURNFLAG"));
  group_by_attributes.push_back(table->getAttribute("L_LINESTATUS"));
  std::vector<Attribute> aggregation_attributes;
  aggregation_attributes.push_back(table->getAttribute("L_QUANTITY"));
  aggregation_attributes.push_back(table->getAttribute("L_EXTENDEDPRICE"));
  aggregation_attributes.push_back(table->getAttribute("L_DISCOUNT"));
  aggregation_attributes.push_back(Attribute(ATTRIBUTE_ANY));

  std::vector<PhysicalAggregation::State::Aggregation> aggregation_function;

  aggregation_function.push_back(PhysicalAggregation::State::kSum);
  aggregation_function.push_back(PhysicalAggregation::State::kSum);
  aggregation_function.push_back(PhysicalAggregation::State::kSum);
  aggregation_function.push_back(PhysicalAggregation::State::kCount);
  LogicalOperator* aggregation =
      new LogicalAggregation(group_by_attributes, aggregation_attributes,
                             aggregation_function, project1);

  //==========================project=========================
  vector<vector<ExpressionItem> > expr_list2;

  ExpressionItem ei21_1;
  ei21_1.setVariable("LINEITEM.row_id+1");
//.........这里部分代码省略.........
开发者ID:JolyZhang,项目名称:CLAIMS,代码行数:101,代码来源:issue27ing.cpp

示例13: CreateProjection

void CreateProjection(Catalog *catalog, Node *node, ResultSet *&result_set, bool & result_flag,  string &error_msg, string &info) {
	bool is_correct = true;
	Create_projection_stmt *newnode = (Create_projection_stmt *)node;
	int partition_num = newnode->partition_num;
	string tablename = newnode->tablename;
	TableDescriptor *table = NULL;

	if((table = catalog->getTable(tablename)) == NULL)	// 2014-4-30---add check---by Yu
	{
		error_msg="There is no table named "+ tablename+" during creating projection";
		result_flag=false;
		result_set = NULL;
		return;
		is_correct = false;
		return;
	}
	TableID table_id=catalog->getTable(tablename)->get_table_id();
	string partition_attribute_name = newnode->partition_attribute_name;

	std::vector<ColumnOffset> index;
	index.push_back(0);		// add by scdong: add row_id column to each projection automatically
	Columns *col_list = (Columns *)newnode->column_list;
	string colname;
	while(col_list)
	{
		if (col_list->parameter2 != NULL)
		{
			colname = col_list->parameter2;
		}
		else if (col_list->parameter1 != NULL)
		{
			colname = col_list->parameter1;
		}
		else
		{
			error_msg="NO column name during creating projection!";
			result_flag=false;
			result_set = NULL;
			return;
			is_correct = false;
			break;
		}
		cout<<tablename+"."+colname<<endl;
		if(table->isExist(tablename+"."+colname))	// 2014-4-30---add check---by Yu
			index.push_back(table->getAttribute(colname).index);
		else
		{
			error_msg="The column "+ colname+" is not existed! during creating projection";
			result_flag=false;
			result_set = NULL;
			return;
			is_correct = false;
			break;
		}
		col_list = (Columns *)col_list->next;
	}
	if(result_flag==false)
		return;
	if(!is_correct)
		return;

	catalog->getTable(table_id)->createHashPartitionedProjection(index,partition_attribute_name,partition_num);

	int projection_index = catalog->getTable(table_id)->getNumberOfProjection()-1;
	for(unsigned i=0;i<catalog->getTable(table_id)->getProjectoin(projection_index)->getPartitioner()->getNumberOfPartitions();i++){

		catalog->getTable(table_id)->getProjectoin(projection_index)->getPartitioner()->RegisterPartition(i,0);
	}

	catalog->saveCatalog();
	//			catalog->restoreCatalog();// commented by li to solve the dirty read after insert

	result_flag=true;
	result_set = NULL;
	info = "create projection successfully";
	result_set=NULL;
	return;
}
开发者ID:wangli1426,项目名称:Claims,代码行数:78,代码来源:ExecuteLogicalQueryPlan.cpp

示例14: analyse

void Analyzer::analyse(const AttributeID &attrID) {

	Catalog *catalog = Catalog::getInstance();

	TableDescriptor* table = catalog->getTable(attrID.table_id);
	ProjectionDescriptor * projection = NULL;

	unsigned pidSize = table->getNumberOfProjection();
	const Attribute attr = table->getAttribute(attrID.offset);

	for (unsigned i = 0; i < pidSize; ++i) {
		if (table->getProjectoin(i)->hasAttribute(attr)) {
			projection = table->getProjectoin(i);
			break;
		}
	}

	std::vector<Attribute> group_by_attributes;
	std::vector<Attribute> aggregation_attributes;

	group_by_attributes.push_back(attr);
	aggregation_attributes.push_back(attr);

	std::vector<BlockStreamAggregationIterator::State::aggregation> aggregation_function;
	aggregation_function.push_back(
			BlockStreamAggregationIterator::State::count);

	LogicalOperator* sb_payload_scan = new LogicalScan(projection);

	LogicalOperator* aggregation = new Aggregation(group_by_attributes,
			aggregation_attributes, aggregation_function, sb_payload_scan);
	const NodeID collector_node_id = 0;

	LogicalOperator* root = new LogicalQueryPlanRoot(collector_node_id,
			aggregation, LogicalQueryPlanRoot::RESULTCOLLECTOR);

	BlockStreamIteratorBase* collector = root->getIteratorTree(
			1024 * 64 - sizeof(unsigned));

	collector->open();
	collector->next(0);
	collector->close();
	ResultSet* resultset = collector->getResultSet();
	ResultSet::Iterator it = resultset->createIterator();

	BlockStreamBase* block;
	void* tuple;
	BlockStreamBase::BlockStreamTraverseIterator *block_it;

	unsigned long valueCount = resultset->getNumberOftuples();
	unsigned long tupleCount = 0;
	TuplePtr *list = new TuplePtr[valueCount];
	unsigned long i = 0;
	while (block = (BlockStreamBase*) it.atomicNextBlock()) {
		block_it = block->createIterator();
		while (tuple = block_it->nextTuple()) {

			list[i++] = tuple;
			tupleCount += getFrequency(tuple, attr.attrType);
		}
	}

	int magicNumber = 100;

	StatisticOnTable *stat = new StatisticOnTable(magicNumber);

	stat->setValueCount(valueCount);
	stat->setTupleCount(tupleCount);

	qsort_r(list, valueCount, sizeof(void *), compare,
			(void *) (attr.attrType->operate));

	mcvAnalyse(list, valueCount, attr, (Histogram *) stat);
	equiDepthAnalyse(list, valueCount, attr, (Histogram *) stat);

//	StatManager::getInstance()->addStat(attrID, stat);
	StatManager::getInstance()->getTableStatistic(attrID.table_id);
	delete list;
	resultset->destory();
}
开发者ID:egraldlo,项目名称:CLAIMS,代码行数:80,代码来源:Analyzer.cpp

示例15: table_name

/**
 * @brief insert data
 * @detail check whether the table we have created or not. forbid to insert data
 * into an nonexistent table.
 *  There are two different cases when we insert data:
 *    1. insert all columns
 *    2. insert part of all columns
 *  To case 1, we just insert all rows values and make sure the value count and
 * type match each column.
 *  To case 2, make sure each value correspond to its column and its type.
 *  If no exceptions and errors, data will be stored into tables and hdfs proper
 * time.
 * @return a result code cooperate with the client.
 */
RetCode InsertExec::Execute(ExecutedResult *exec_result) {
  int ret = rSuccess;
  string table_name(insert_ast_->table_name_);
  TableDescriptor *table =
      Environment::getInstance()->getCatalog()->getTable(table_name);
  if (table == NULL) {
    ret = rTableNotExisted;
    exec_result->SetError("The table " + table_name + " does not exist!");
    ELOG(ret, "table name: " << table_name);
    return ret;
  }

  unsigned col_count = 0;
  AstColumn *col = dynamic_cast<AstColumn *>(insert_ast_->col_list_);
  if (NULL == col) {
    is_all_col_ = true;  // insert all columns
  } else {               // get insert column count
    ++col_count;
    while ((col = dynamic_cast<AstColumn *>(col->next_))) ++col_count;
  }

  AstInsertValList *insert_value_list =
      dynamic_cast<AstInsertValList *>(insert_ast_->insert_val_list_);
  if (NULL == insert_value_list) {
    LOG(ERROR) << "No value!" << endl;
    exec_result->SetError("No value!");
    ret = common::rStmtHandlerInsertNoValue;
  } else {
    std::ostringstream ostr;
    int changed_row_num = 0;

    // get data in one row like (...), (...), (...) by while loop.
    while (insert_value_list) {
      // make sure: the insert column count = insert value count = used column
      // count = used value count
      AstInsertVals *insert_value =
          dynamic_cast<AstInsertVals *>(insert_value_list->insert_vals_);
      col = dynamic_cast<AstColumn *>(insert_ast_->col_list_);

      if (is_all_col_) {
        // by scdong: Claims adds a default row_id attribute for all tables
        // which is attribute(0),
        // when inserting tuples we should begin to construct the string_tuple
        // from the second attribute.
        for (unsigned int position = 1;
             position < table_desc_->getNumberOfAttribute(); position++) {
          // check value count
          if (insert_value == NULL) {
            LOG(ERROR) << "Value count is too few. Expected value count is "
                       << table_desc_->getNumberOfAttribute() << endl;
            exec_result->SetError("Value count is too few");
            return claims::common::rFailure;
          }

          // insert value to ostringstream and if has warning return 1;   look
          // out the order!
          ret = InsertValueToStream(insert_value, table_desc_, position, ostr);

          // move to next
          insert_value = dynamic_cast<AstInsertVals *>(insert_value->next_);
          ostr << "|";
        }

        if (rSuccess != ret) break;
        // check insert value count
        if (NULL != insert_value) {
          LOG(ERROR) << "Value count is too many";
          exec_result->SetError("Value count is too many");
          return claims::common::rFailure;
        }
      } else {  // insert part of columns
        // get insert value count and check whether it match column count
        unsigned insert_value_count = 0;
        while (insert_value) {
          ++insert_value_count;
          insert_value = dynamic_cast<AstInsertVals *>(insert_value->next_);
        }
        if (insert_value_count != col_count) {
          LOG(ERROR) << "Column count doesn't match value count. "
                        "insert_value_count is " << insert_value_count
                     << ", col_count is: " << col_count << endl;
          exec_result->SetError("Column count doesn't match value count");
          return claims::common::rFailure;
        }
        unsigned int used_col_count = 0;
        // by scdong: Claims adds a default row_id attribute for all tables
//.........这里部分代码省略.........
开发者ID:cs-wang,项目名称:CLAIMS,代码行数:101,代码来源:insert_exec.cpp


注:本文中的TableDescriptor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。