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()) { }
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)); }
execplan::ReturnedColumn* buildPseudoColumn(Item* item, gp_walk_info& gwi, bool& nonSupport, uint32_t pseudoType) { Item_func* ifp = (Item_func*)item; // idblocalpm is replaced by constant if (pseudoType == PSEUDO_LOCALPM) { int64_t localPm = idblocalpm(); ConstantColumn* cc; if (localPm) cc = new ConstantColumn(localPm); else cc = new ConstantColumn("", ConstantColumn::NULLDATA); cc->alias(ifp->name? ifp->name : ""); return cc; } // convert udf item to pseudocolumn item. // adjust result type // put arg col to column map string funcName = ifp->func_name(); if (ifp->arg_count != 1 || !(ifp->arguments()) || !(ifp->arguments()[0]) || ifp->arguments()[0]->type() != Item::FIELD_ITEM) return nullOnError(gwi, funcName); Item_field* field = (Item_field*)(ifp->arguments()[0]); // @todo rule out derive table if (!field->field || !field->db_name || strlen(field->db_name) == 0) return nullOnError(gwi, funcName); SimpleColumn *sc = buildSimpleColumn(field, gwi); if (!sc) return nullOnError(gwi, funcName); if ((pseudoType == PSEUDO_EXTENTMIN || pseudoType == PSEUDO_EXTENTMAX) && (sc->colType().colDataType == CalpontSystemCatalog::VARBINARY || (sc->colType().colDataType == CalpontSystemCatalog::VARCHAR && sc->colType().colWidth > 7) || (sc->colType().colDataType == CalpontSystemCatalog::CHAR && sc->colType().colWidth > 8))) return nullOnError(gwi, funcName); // put arg col to column map if (gwi.clauseType == SELECT || gwi.clauseType == GROUP_BY) // select clause { SRCP srcp(sc); gwi.columnMap.insert(CalpontSelectExecutionPlan::ColumnMap::value_type(sc->columnName(), srcp)); gwi.tableMap[make_aliastable(sc->schemaName(), sc->tableName(), sc->tableAlias(), sc->isInfiniDB())] = make_pair(1, field->cached_table); } else if (!gwi.rcWorkStack.empty()) { gwi.rcWorkStack.pop(); } if (pseudoType == PSEUDO_PARTITION) { // parms: psueducolumn dbroot, segmentdir, segment SPTP sptp; FunctionColumn *fc = new FunctionColumn(funcName); funcexp::FunctionParm parms; PseudoColumn *dbroot = new PseudoColumn(*sc, PSEUDO_DBROOT); sptp.reset(new ParseTree(dbroot)); parms.push_back(sptp); PseudoColumn *pp = new PseudoColumn(*sc, PSEUDO_SEGMENTDIR); sptp.reset(new ParseTree(pp)); parms.push_back(sptp); PseudoColumn* seg = new PseudoColumn(*sc, PSEUDO_SEGMENT); sptp.reset(new ParseTree(seg)); parms.push_back(sptp); fc->functionParms(parms); fc->expressionId(gwi.expressionId++); // string result type CalpontSystemCatalog::ColType ct; ct.colDataType = CalpontSystemCatalog::VARCHAR; ct.colWidth = 256; fc->resultType(ct); // operation type integer funcexp::Func_idbpartition* idbpartition = new funcexp::Func_idbpartition(); fc->operationType(idbpartition->operationType(parms, fc->resultType())); fc->alias(ifp->name? ifp->name : ""); return fc; } PseudoColumn *pc = new PseudoColumn(*sc, pseudoType); // @bug5892. set alias for derived table column matching. pc->alias(ifp->name? ifp->name : ""); return pc; }