FunctionColumn::FunctionColumn( const FunctionColumn& rhs, const uint32_t sessionID): ReturnedColumn(rhs, sessionID), fFunctionName(rhs.functionName()), fTableAlias (rhs.tableAlias()), fData (rhs.data()), fFunctor(rhs.fFunctor) { fFunctionParms.clear(); fSimpleColumnList.clear(); fAggColumnList.clear(); fWindowFunctionColumnList.clear(); SPTP pt; for (uint32_t i = 0; i < rhs.fFunctionParms.size(); i++) { pt.reset(new ParseTree (*(rhs.fFunctionParms[i]))); fFunctionParms.push_back(pt); pt->walk(getSimpleCols, &fSimpleColumnList); pt->walk(getAggCols, &fAggColumnList); pt->walk(getWindowFunctionCols, &fWindowFunctionColumnList); } fAlias = rhs.alias(); }
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)); }
SimpleFilter::SimpleFilter(const SimpleFilter& rhs) : fOp(rhs.op()), fIndexFlag(rhs.indexFlag()), fJoinFlag(rhs.joinFlag()) { fLhs = rhs.lhs()->clone(); fRhs = rhs.rhs()->clone(); fSimpleColumnList.clear(); fAggColumnList.clear(); fWindowFunctionColumnList.clear(); SimpleColumn *lsc = dynamic_cast<SimpleColumn*>(fLhs); FunctionColumn *lfc = dynamic_cast<FunctionColumn*>(fLhs); ArithmeticColumn *lac = dynamic_cast<ArithmeticColumn*>(fLhs); WindowFunctionColumn *laf = dynamic_cast<WindowFunctionColumn*>(fLhs); AggregateColumn *lagc = dynamic_cast<AggregateColumn*>(fLhs); SimpleColumn *rsc = dynamic_cast<SimpleColumn*>(fRhs); FunctionColumn *rfc = dynamic_cast<FunctionColumn*>(fRhs); ArithmeticColumn *rac = dynamic_cast<ArithmeticColumn*>(fRhs); AggregateColumn *ragc = dynamic_cast<AggregateColumn*>(fRhs); WindowFunctionColumn *raf = dynamic_cast<WindowFunctionColumn*>(fRhs); if (lsc) { fSimpleColumnList.push_back(lsc); } else if (lagc) { fAggColumnList.push_back(lagc); } else if (lfc) { fSimpleColumnList.insert(fSimpleColumnList.end(), lfc->simpleColumnList().begin(), lfc->simpleColumnList().end()); fAggColumnList.insert(fAggColumnList.end(), lfc->aggColumnList().begin(), lfc->aggColumnList().end()); fWindowFunctionColumnList.insert (fWindowFunctionColumnList.end(), lfc->windowfunctionColumnList().begin(), lfc->windowfunctionColumnList().end()); } else if (lac) { fSimpleColumnList.insert(fSimpleColumnList.end(), lac->simpleColumnList().begin(), lac->simpleColumnList().end()); fAggColumnList.insert(fAggColumnList.end(), lac->aggColumnList().begin(), lac->aggColumnList().end()); fWindowFunctionColumnList.insert (fWindowFunctionColumnList.end(), lac->windowfunctionColumnList().begin(), lac->windowfunctionColumnList().end()); } else if (laf) { fWindowFunctionColumnList.push_back(laf); } if (rsc) { fSimpleColumnList.push_back(rsc); } else if (ragc) { fAggColumnList.push_back(ragc); } else if (rfc) { fSimpleColumnList.insert (fSimpleColumnList.end(), rfc->simpleColumnList().begin(), rfc->simpleColumnList().end()); fAggColumnList.insert (fAggColumnList.end(), rfc->aggColumnList().begin(), rfc->aggColumnList().end()); fWindowFunctionColumnList.insert (fWindowFunctionColumnList.end(), rfc->windowfunctionColumnList().begin(), rfc->windowfunctionColumnList().end()); } else if (rac) { fSimpleColumnList.insert(fSimpleColumnList.end(), rac->simpleColumnList().begin(), rac->simpleColumnList().end()); fAggColumnList.insert(fAggColumnList.end(), rac->aggColumnList().begin(), rac->aggColumnList().end()); fWindowFunctionColumnList.insert (fWindowFunctionColumnList.end(), rac->windowfunctionColumnList().begin(), rac->windowfunctionColumnList().end()); } else if (raf) { fWindowFunctionColumnList.push_back(raf); } }
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; }
void SimpleFilter::unserialize(messageqcpp::ByteStream& b) { ObjectReader::checkType(b, ObjectReader::SIMPLEFILTER); //delete fOp; delete fLhs; delete fRhs; Filter::unserialize(b); fOp.reset(dynamic_cast<Operator*>(ObjectReader::createTreeNode(b))); fLhs = dynamic_cast<ReturnedColumn*>(ObjectReader::createTreeNode(b)); fRhs = dynamic_cast<ReturnedColumn*>(ObjectReader::createTreeNode(b)); b >> reinterpret_cast<uint32_t&>(fIndexFlag); b >> reinterpret_cast<uint32_t&>(fJoinFlag); fSimpleColumnList.clear(); fAggColumnList.clear(); fWindowFunctionColumnList.clear(); SimpleColumn *lsc = dynamic_cast<SimpleColumn*>(fLhs); FunctionColumn *lfc = dynamic_cast<FunctionColumn*>(fLhs); ArithmeticColumn *lac = dynamic_cast<ArithmeticColumn*>(fLhs); WindowFunctionColumn *laf = dynamic_cast<WindowFunctionColumn*>(fLhs); AggregateColumn *lagc = dynamic_cast<AggregateColumn*>(fLhs); SimpleColumn *rsc = dynamic_cast<SimpleColumn*>(fRhs); FunctionColumn *rfc = dynamic_cast<FunctionColumn*>(fRhs); ArithmeticColumn *rac = dynamic_cast<ArithmeticColumn*>(fRhs); AggregateColumn *ragc = dynamic_cast<AggregateColumn*>(fRhs); WindowFunctionColumn *raf = dynamic_cast<WindowFunctionColumn*>(fRhs); if (lsc) { fSimpleColumnList.push_back(lsc); } else if (lagc) { fAggColumnList.push_back(lagc); } else if (lfc) { fSimpleColumnList.insert(fSimpleColumnList.end(), lfc->simpleColumnList().begin(), lfc->simpleColumnList().end()); fAggColumnList.insert(fAggColumnList.end(), lfc->aggColumnList().begin(), lfc->aggColumnList().end()); fWindowFunctionColumnList.insert (fWindowFunctionColumnList.end(), lfc->windowfunctionColumnList().begin(), lfc->windowfunctionColumnList().end()); } else if (lac) { fSimpleColumnList.insert(fSimpleColumnList.end(), lac->simpleColumnList().begin(), lac->simpleColumnList().end()); fAggColumnList.insert(fAggColumnList.end(), lac->aggColumnList().begin(), lac->aggColumnList().end()); fWindowFunctionColumnList.insert (fWindowFunctionColumnList.end(), lac->windowfunctionColumnList().begin(), lac->windowfunctionColumnList().end()); } else if (laf) { fWindowFunctionColumnList.push_back(laf); } if (rsc) { fSimpleColumnList.push_back(rsc); } else if (ragc) { fAggColumnList.push_back(ragc); } else if (rfc) { fSimpleColumnList.insert (fSimpleColumnList.end(), rfc->simpleColumnList().begin(), rfc->simpleColumnList().end()); fAggColumnList.insert (fAggColumnList.end(), rfc->aggColumnList().begin(), rfc->aggColumnList().end()); fWindowFunctionColumnList.insert (fWindowFunctionColumnList.end(), rfc->windowfunctionColumnList().begin(), rfc->windowfunctionColumnList().end()); } else if (rac) { fSimpleColumnList.insert(fSimpleColumnList.end(), rac->simpleColumnList().begin(), rac->simpleColumnList().end()); fAggColumnList.insert(fAggColumnList.end(), rac->aggColumnList().begin(), rac->aggColumnList().end()); fWindowFunctionColumnList.insert (fWindowFunctionColumnList.end(), rac->windowfunctionColumnList().begin(), rac->windowfunctionColumnList().end()); } else if (raf) { fWindowFunctionColumnList.push_back(raf); } // construct regex constant for like operator if (fOp->op() == OP_LIKE || fOp->op() == OP_NOTLIKE) { ConstantColumn *rcc = dynamic_cast<ConstantColumn*>(fRhs); if (rcc) rcc->constructRegex(); ConstantColumn *lcc = dynamic_cast<ConstantColumn*>(fLhs); if (lcc) lcc->constructRegex(); } }