void SimpleColumn::setOID() { boost::shared_ptr<CalpontSystemCatalog> csc = CalpontSystemCatalog::makeCalpontSystemCatalog(fSessionID); CalpontSystemCatalog::TableColName tcn; tcn = make_tcn(fSchemaName, fTableName, fColumnName); fOid = csc->lookupOID (tcn); if (fOid == -1) { // get colMap from CalpontSelectExecutionPlan // and try to map the schema and table name CalpontSelectExecutionPlan::ColumnMap::iterator iter; CalpontSelectExecutionPlan::ColumnMap colMap = CalpontSelectExecutionPlan::colMap(); // if this is the only column name exist in the map, return it ?? for (iter = colMap.find(fColumnName); iter != colMap.end(); ++iter) { SRCP srcp = iter->second; SimpleColumn* scp = dynamic_cast<SimpleColumn*>(srcp.get()); if (colMap.count(fColumnName) == 1 || scp->tableName().compare(fTableName) == 0) { fOid = scp->oid(); //@bug 221 fix fTableName = scp->tableName(); fSchemaName = scp->schemaName(); //@info assign tableAlias also. watch for other conflict fTableAlias = scp->tableAlias(); fResultType = scp->resultType(); return; } } } fResultType = csc->colType(fOid); }
SimpleColumn::SimpleColumn (const SimpleColumn& rhs,const uint32_t sessionID): ReturnedColumn(rhs, sessionID), fSchemaName (rhs.schemaName()), fTableName (rhs.tableName()), fColumnName (rhs.columnName()), fOid (rhs.oid()), fTableAlias (rhs.tableAlias()), fData (rhs.data()), fIndexName (rhs.indexName()), fViewName (rhs.viewName()), fIsInfiniDB (rhs.isInfiniDB()) { }
void* ing_opentbl(void* qctx, const char* sn, const char* tn) { try { if (!qctx) return 0; if (!sn) return 0; if (!tn) return 0; if (strlen(sn) == 0) return 0; if (strlen(tn) == 0) return 0; IngQCtx* ingQctx = reinterpret_cast<IngQCtx*>(qctx); cpsm_conhdl_t* cal_conn_hndl = reinterpret_cast<cpsm_conhdl_t*>(ingQctx->dhcs_ses_ctx); IngTCtx* tctx = new IngTCtx(); dhcs_tableid_t tableid = 0; //tableid = tbname2id(sn, tn, cal_conn_hndl); tableid = tbname2id("te", "f_trans", cal_conn_hndl); RequiredColOidSet requiredColOidSet; const CalpontSelectExecutionPlan::ColumnMap colMap = ingQctx->csep.columnMap(); CalpontSelectExecutionPlan::ColumnMap::const_iterator colIter = colMap.begin(); CalpontSelectExecutionPlan::ColumnMap::const_iterator colend = colMap.end(); while (colIter != colend) { SRCP srcp = colIter->second; SimpleColumn* scp = dynamic_cast<SimpleColumn*>(srcp.get()); if (scp) requiredColOidSet.insert(scp->oid()); ++colIter; } tctx->dhcs_tpl_ctx = new cpsm_tplh_t(); dhcs_tpl_open(tableid, &tctx->dhcs_tpl_ctx, ingQctx->dhcs_ses_ctx, requiredColOidSet); tctx->dhcs_tpl_scan_ctx = new cpsm_tplsch_t(); dhcs_tpl_scan_open(tableid, DHCS_TPL_FH_READ, &tctx->dhcs_tpl_scan_ctx, ingQctx->dhcs_ses_ctx); return tctx; } catch (...) { } return NULL; }
SimpleFilter* createSimpleFilter ( CalpontSystemCatalog*& csc, const CalpontSystemCatalog::TableColName& tcn, const string& opstr, ConstantColumn* cc ) { SimpleFilter* lsf = new SimpleFilter(); Operator* op = new Operator(); op->data(opstr); CalpontSystemCatalog::ColType ccct; ccct = op->resultType(); ccct.colDataType = cc->resultType().colDataType; op->operationType(ccct); SOP sop(op); lsf->op(sop); CalpontSystemCatalog::OID oid = csc->lookupOID(tcn); CalpontSystemCatalog::ColType ct = csc->colType(oid); SimpleColumn* sc = new SimpleColumn(); sc->schemaName(tcn.schema); sc->tableName(tcn.table); sc->tableAlias(tcn.table); sc->columnName(tcn.column); sc->oid(oid); sc->resultType(ct); sc->alias(tcn.toString()); lsf->lhs(sc); lsf->rhs(cc); return lsf; }
void VirtualTable::addColumn(const SRCP& column) { // As of bug3695, make sure varbinary is not used in subquery. if (column->resultType().colDataType == CalpontSystemCatalog::VARBINARY && !fVarBinOK) throw runtime_error ("VARBINARY in subquery is not supported."); AggregateColumn* agc = NULL; ArithmeticColumn* arc = NULL; ConstantColumn* cc = NULL; FunctionColumn* fc = NULL; SimpleColumn* sc = NULL; WindowFunctionColumn* wc = NULL; string columnName; ostringstream oss; UniqId colId; if ((sc = dynamic_cast<SimpleColumn*>(column.get())) != NULL) { columnName = sc->columnName(); colId = UniqId(sc); } else if ((agc = dynamic_cast<AggregateColumn*>(column.get())) != NULL) { // oss << agc->functionName() << "_" << agc->expressionId(); // oss << "Aggregate_" << agc->expressionId(); columnName = agc->data(); colId = UniqId(agc->expressionId(), "", "", ""); } else if ((wc = dynamic_cast<WindowFunctionColumn*>(column.get())) != NULL) { // oss << wc->functionName() << "_" << wc->expressionId(); // oss << "Window_" << wc->expressionId(); columnName = wc->data(); colId = UniqId(wc->expressionId(), "", "", ""); } else if ((arc = dynamic_cast<ArithmeticColumn*>(column.get())) != NULL) { // oss << "Arithmetic_" << arc->expressionId(); columnName = arc->data(); colId = UniqId(arc->expressionId(), "", "", ""); } else if ((fc = dynamic_cast<FunctionColumn*>(column.get())) != NULL) { // oss << fc->functionName() << "_" << fc->expressionId(); columnName = fc->data(); colId = UniqId(fc->expressionId(), "", "", ""); } else if ((cc = dynamic_cast<ConstantColumn*>(column.get())) != NULL) { // oss << "Constant_" << cc->expressionId(); columnName = cc->data(); colId = UniqId(cc->expressionId(), cc->alias(), "", fView); } else // new column type has added, but this code is not updated. { oss << "not supported column type: " << typeid(*(column.get())).name(); throw runtime_error(oss.str()); } if (columnName.empty()) columnName = column->alias(); SimpleColumn* vc = new SimpleColumn(); vc->tableName(fName); vc->tableAlias(fAlias); vc->columnName(columnName); vc->alias(column->alias()); vc->viewName(fView); uint32_t index = fColumns.size(); vc->colPosition(index); vc->oid(fTableOid+index+1); vc->resultType(column->resultType()); SSC ssc(vc); fColumns.push_back(ssc); fColumnTypes.push_back(column->resultType()); fColumnMap.insert(make_pair(colId, index)); }