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)); }
uint32_t getTupleKey(JobInfo& jobInfo, const SRCP& srcp, bool add) { int key = -1; if (add) { // setTupleInfo first if add is ture, ok if already set. const SimpleColumn* sc = dynamic_cast<const SimpleColumn*>(srcp.get()); if (sc != NULL) { if (sc->schemaName().empty()) { SimpleColumn tmp(*sc, jobInfo.sessionId); tmp.oid(tableOid(sc, jobInfo.csc) + 1 + sc->colPosition()); key = getTupleKey(jobInfo, &tmp); // sub-query should be there } else { erydbSystemCatalog::ColType ct = sc->colType(); string alias(extractTableAlias(sc)); erydbSystemCatalog::OID tblOid = tableOid(sc, jobInfo.csc); TupleInfo ti(setTupleInfo(ct, sc->oid(), jobInfo, tblOid, sc, alias)); key = ti.key; erydbSystemCatalog::OID dictOid = isDictCol(ct); if (dictOid > 0) { ti = setTupleInfo(ct, dictOid, jobInfo, tblOid, sc, alias); jobInfo.keyInfo->dictKeyMap[key] = ti.key; key = ti.key; } } } else { erydbSystemCatalog::ColType ct = srcp->resultType(); TupleInfo ti(setExpTupleInfo(ct, srcp->expressionId(), srcp->alias(), jobInfo)); key = ti.key; } } else { // TupleInfo is expected to be set already const SimpleColumn* sc = dynamic_cast<const SimpleColumn*>(srcp.get()); if (sc != NULL) { if (sc->schemaName().empty()) { SimpleColumn tmp(*sc, jobInfo.sessionId); tmp.oid(tableOid(sc, jobInfo.csc) + 1 + sc->colPosition()); key = getTupleKey(jobInfo, &tmp); } else { key = getTupleKey(jobInfo, sc); } // check if this is a dictionary column if (jobInfo.keyInfo->dictKeyMap.find(key) != jobInfo.keyInfo->dictKeyMap.end()) key = jobInfo.keyInfo->dictKeyMap[key]; } else { key = getExpTupleKey(jobInfo, srcp->expressionId()); } } return key; }