bool ProjectionExecutor::p_execute(const NValueArray ¶ms) { #ifndef NDEBUG ProjectionPlanNode* node = dynamic_cast<ProjectionPlanNode*>(m_abstractNode); #endif assert (node); assert (!node->isInline()); // inline projection's execute() should not be // called assert (m_outputTable == dynamic_cast<AbstractTempTable*>(node->getOutputTable())); assert (m_outputTable); Table* input_table = m_abstractNode->getInputTable(); assert (input_table); VOLT_TRACE("INPUT TABLE: %s\n", input_table->debug().c_str()); assert (m_columnCount == (int)node->getOutputColumnNames().size()); if (m_allTupleArray == NULL && m_allParamArray == NULL) { for (int ctr = m_columnCount - 1; ctr >= 0; --ctr) { assert(expression_array[ctr]); VOLT_TRACE("predicate[%d]: %s", ctr, expression_array[ctr]->debug(true).c_str()); } } // // Now loop through all the tuples and push them through our output // expression This will generate new tuple values that we will insert into // our output table // TableIterator iterator = input_table->iteratorDeletingAsWeGo(); assert (m_tuple.columnCount() == input_table->columnCount()); while (iterator.next(m_tuple)) { // // Project (or replace) values from input tuple // TableTuple &temp_tuple = m_outputTable->tempTuple(); if (m_allTupleArray != NULL) { VOLT_TRACE("sweet, all tuples"); for (int ctr = m_columnCount - 1; ctr >= 0; --ctr) { temp_tuple.setNValue(ctr, m_tuple.getNValue(m_allTupleArray[ctr])); } } else if (m_allParamArray != NULL) { VOLT_TRACE("sweet, all params"); for (int ctr = m_columnCount - 1; ctr >= 0; --ctr) { temp_tuple.setNValue(ctr, params[m_allParamArray[ctr]]); } } else { for (int ctr = m_columnCount - 1; ctr >= 0; --ctr) { temp_tuple.setNValue(ctr, expression_array[ctr]->eval(&m_tuple, NULL)); } } m_outputTable->insertTempTuple(temp_tuple); VOLT_TRACE("OUTPUT TABLE: %s\n", m_outputTable->debug().c_str()); } return true; }
bool ProjectionExecutor::p_init(AbstractPlanNode *abstractNode, TempTableLimits* limits) { VOLT_TRACE("init Projection Executor"); assert(limits); ProjectionPlanNode* node = dynamic_cast<ProjectionPlanNode*>(abstractNode); assert(node); // // Construct the output table // TupleSchema* schema = node->generateTupleSchema(true); m_columnCount = static_cast<int>(node->getOutputSchema().size()); std::string* column_names = new std::string[m_columnCount]; for (int ctr = 0; ctr < m_columnCount; ctr++) { column_names[ctr] = node->getOutputSchema()[ctr]->getColumnName(); } node->setOutputTable(TableFactory::getTempTable(node->databaseId(), "temp", schema, column_names, limits)); delete[] column_names; // initialize local variables all_tuple_array_ptr = ExpressionUtil::convertIfAllTupleValues(node->getOutputColumnExpressions()); all_tuple_array = all_tuple_array_ptr.get(); all_param_array_ptr = ExpressionUtil::convertIfAllParameterValues(node->getOutputColumnExpressions()); all_param_array = all_param_array_ptr.get(); needs_substitute_ptr = boost::shared_array<bool>(new bool[m_columnCount]); needs_substitute = needs_substitute_ptr.get(); typedef AbstractExpression* ExpRawPtr; expression_array_ptr = boost::shared_array<ExpRawPtr>(new ExpRawPtr[m_columnCount]); expression_array = expression_array_ptr.get(); for (int ctr = 0; ctr < m_columnCount; ctr++) { assert (node->getOutputColumnExpressions()[ctr] != NULL); expression_array_ptr[ctr] = node->getOutputColumnExpressions()[ctr]; needs_substitute_ptr[ctr] = node->getOutputColumnExpressions()[ctr]->hasParameter(); } output_table = dynamic_cast<TempTable*>(node->getOutputTable()); //output table should be temptable if (!node->isInline()) { input_table = node->getInputTables()[0]; tuple = TableTuple(input_table->schema()); } return true; }
bool ProjectionExecutor::p_init(AbstractPlanNode *abstractNode, TempTableLimits* limits) { VOLT_TRACE("init Projection Executor"); assert(limits); ProjectionPlanNode* node = dynamic_cast<ProjectionPlanNode*>(abstractNode); assert(node); // Create output table based on output schema from the plan setTempOutputTable(limits); m_columnCount = static_cast<int>(node->getOutputSchema().size()); // initialize local variables all_tuple_array_ptr = ExpressionUtil::convertIfAllTupleValues(node->getOutputColumnExpressions()); all_tuple_array = all_tuple_array_ptr.get(); all_param_array_ptr = ExpressionUtil::convertIfAllParameterValues(node->getOutputColumnExpressions()); all_param_array = all_param_array_ptr.get(); needs_substitute_ptr = boost::shared_array<bool>(new bool[m_columnCount]); needs_substitute = needs_substitute_ptr.get(); typedef AbstractExpression* ExpRawPtr; expression_array_ptr = boost::shared_array<ExpRawPtr>(new ExpRawPtr[m_columnCount]); expression_array = expression_array_ptr.get(); for (int ctr = 0; ctr < m_columnCount; ctr++) { assert (node->getOutputColumnExpressions()[ctr] != NULL); VOLT_TRACE("OutputColumnExpressions [%d]: %s", ctr, node->getOutputColumnExpressions()[ctr]->debug(true).c_str()); expression_array_ptr[ctr] = node->getOutputColumnExpressions()[ctr]; needs_substitute_ptr[ctr] = node->getOutputColumnExpressions()[ctr]->hasParameter(); } output_table = dynamic_cast<TempTable*>(node->getOutputTable()); //output table should be temptable if (!node->isInline()) { Table* input_table = node->getInputTable(); tuple = TableTuple(input_table->schema()); } return true; }
bool ProjectionExecutor::p_execute(const NValueArray ¶ms) { #ifndef NDEBUG ProjectionPlanNode* node = dynamic_cast<ProjectionPlanNode*>(m_abstractNode); #endif assert (node); assert (!node->isInline()); // inline projection's execute() should not be // called assert (output_table == dynamic_cast<TempTable*>(node->getOutputTable())); assert (output_table); assert (input_table == node->getInputTables()[0]); assert (input_table); VOLT_TRACE("INPUT TABLE: %s\n", input_table->debug().c_str()); // // Since we have the input params, we need to call substitute to change any // nodes in our expression tree to be ready for the projection operations in // execute // assert (m_columnCount == (int)node->getOutputColumnNames().size()); if (all_tuple_array == NULL && all_param_array == NULL) { for (int ctr = m_columnCount - 1; ctr >= 0; --ctr) { assert(expression_array[ctr]); expression_array[ctr]->substitute(params); VOLT_TRACE("predicate[%d]: %s", ctr, expression_array[ctr]->debug(true).c_str()); } } // // Now loop through all the tuples and push them through our output // expression This will generate new tuple values that we will insert into // our output table // TableIterator iterator = input_table->iterator(); assert (tuple.sizeInValues() == input_table->columnCount()); while (iterator.next(tuple)) { // // Project (or replace) values from input tuple // TableTuple &temp_tuple = output_table->tempTuple(); if (all_tuple_array != NULL) { VOLT_TRACE("sweet, all tuples"); for (int ctr = m_columnCount - 1; ctr >= 0; --ctr) { temp_tuple.setNValue(ctr, tuple.getNValue(all_tuple_array[ctr])); } } else if (all_param_array != NULL) { VOLT_TRACE("sweet, all params"); for (int ctr = m_columnCount - 1; ctr >= 0; --ctr) { temp_tuple.setNValue(ctr, params[all_param_array[ctr]]); } } else { for (int ctr = m_columnCount - 1; ctr >= 0; --ctr) { temp_tuple.setNValue(ctr, expression_array[ctr]->eval(&tuple, NULL)); } } output_table->insertTupleNonVirtual(temp_tuple); /*if (!output_table->insertTupleNonVirtual(temp_tuple)) { // TODO: DEBUG VOLT_ERROR("Failed to insert projection tuple from input table '%s' into output table '%s'", input_table->name().c_str(), output_table->name().c_str()); return (false); }*/ } //VOLT_TRACE("PROJECTED TABLE: %s\n", output_table->debug().c_str()); return (true); }