void AbstractScanPlanNode::loadFromJSONObject(PlannerDomValue obj) { m_target_table_name = obj.valueForKey("TARGET_TABLE_NAME").asStr(); m_isEmptyScan = obj.hasNonNullKey("PREDICATE_FALSE"); // Set the predicate (if any) only if it's not a trivial FALSE expression if (!m_isEmptyScan) { m_predicate.reset(loadExpressionFromJSONObject("PREDICATE", obj)); } m_tcd = NULL; m_cteStmtId = -1; if (obj.hasKey("IS_CTE_SCAN") && obj.valueForKey("IS_CTE_SCAN").asBool()) { m_scanType = CTE_SCAN; m_cteStmtId = obj.valueForKey("CTE_STMT_ID").asInt(); } else if (obj.hasNonNullKey("SUBQUERY_INDICATOR")) { m_scanType = SUBQUERY_SCAN; } else { m_scanType = PERSISTENT_TABLE_SCAN; VoltDBEngine* engine = ExecutorContext::getEngine(); m_tcd = engine->getTableDelegate(m_target_table_name); if ( ! m_tcd) { VOLT_ERROR("Failed to retrieve target table from execution engine for PlanNode '%s'", debug().c_str()); //TODO: throw something } } }
/** * Parse and save predicates. */ void ElasticContext::updatePredicates(const std::vector<std::string> &predicateStrings) { //If there is already a predicate and thus presumably an index, make sure the request is a subset of what exists //That should always be the case, but wrong answers will follow if we are wrong if (m_predicates.size() > 0 && dynamic_cast<HashRangeExpression*>(&m_predicates[0]) != NULL && predicateStrings.size() > 0) { PlannerDomRoot domRoot(predicateStrings[0].c_str()); if (!domRoot.isNull()) { PlannerDomValue predicateObject = domRoot.rootObject(); HashRangeExpression *expression = dynamic_cast<HashRangeExpression*>(&m_predicates[0]); if (predicateObject.hasKey("predicateExpression")) { PlannerDomValue predicateExpression = predicateObject.valueForKey("predicateExpression"); PlannerDomValue rangesArray = predicateExpression.valueForKey("RANGES"); for (int ii = 0; ii < rangesArray.arrayLen(); ii++) { PlannerDomValue arrayObject = rangesArray.valueAtIndex(ii); PlannerDomValue rangeStartValue = arrayObject.valueForKey("RANGE_START"); PlannerDomValue rangeEndValue = arrayObject.valueForKey("RANGE_END"); if (!expression->binarySearch(rangeStartValue.asInt()).isTrue()) { throwFatalException("ElasticContext activate failed because a context already existed with conflicting ranges, conflicting range start is %d", rangeStartValue.asInt()); } if (!expression->binarySearch(rangeEndValue.asInt()).isTrue()) { throwFatalException("ElasticContext activate failed because a context already existed with conflicting ranges, conflicting range end is %d", rangeStartValue.asInt()); } } } } } m_predicateStrings = predicateStrings; // retain for possible clone after TRUNCATE TABLE TableStreamerContext::updatePredicates(predicateStrings); }
/* * Produce a list of StreamPredicateHashRange objects by parsing predicate range strings. * Add error messages to errmsg. * Return true on success. */ bool StreamPredicateList::parseStrings( const std::vector<std::string> &predicateStrings, std::ostringstream& errmsg, std::vector<bool> &predicateDeletes) { bool failed = false; for (std::vector<std::string>::const_iterator iter = predicateStrings.begin(); iter != predicateStrings.end(); ++iter) { bool predFailed = false; std::string predicateString = *iter; if (!predicateString.empty()) { try { PlannerDomRoot domRoot((*iter).c_str()); if (!domRoot.isNull()) { PlannerDomValue predicateObject = domRoot.rootObject(); predicateDeletes.push_back(predicateObject.valueForKey("triggersDelete").asBool()); AbstractExpression *expr = NULL; if (predicateObject.hasKey("predicateExpression")) { expr = AbstractExpression::buildExpressionTree( predicateObject.valueForKey("predicateExpression")); if (expr != NULL) { // Got ourselves a predicate expression tree! push_back(expr); } else { errmsg << "Predicate JSON generated a NULL expression tree"; predFailed = true; } } else { // NULL represents an empty predicate object that should not be evaluated. push_back(NULL); } } else { errmsg << "Stream predicate JSON document is NULL"; predFailed = true; } } catch(std::exception &exc) { errmsg << "Exception occurred while parsing stream predicate: " << exc.what(); predFailed = true; } if (predFailed) { errmsg << std::endl << (*iter) << std::endl; failed = true; } } else { // NULL predicates are okay. push_back(NULL); } } return !failed; }
void PlanNodeFragment::loadParamsFromJSONObject(PlanNodeFragment *pnf, PlannerDomValue obj) { if (obj.hasKey("PARAMETERS")) { PlannerDomValue parametersArray = obj.valueForKey("PARAMETERS"); for (int i = 0; i < parametersArray.arrayLen(); i++) { PlannerDomValue parameterArray = parametersArray.valueAtIndex(i); int index = parameterArray.valueAtIndex(0).asInt(); std::string typeString = parameterArray.valueAtIndex(1).asStr(); pnf->m_parameters.push_back(std::pair< int, voltdb::ValueType>(index, stringToValue(typeString))); } } }
void PlanNodeFragment::loadFromJSONObject(PlannerDomValue obj) { PlannerDomValue executeListArray = obj.valueForKey("EXECUTE_LIST"); for (int i = 0; i < executeListArray.arrayLen(); i++) { m_executionList.push_back(m_idToNodeMap[executeListArray.valueAtIndex(i).asInt()]); } if (obj.hasKey("PARAMETERS")) { PlannerDomValue parametersArray = obj.valueForKey("PARAMETERS"); for (int i = 0; i < parametersArray.arrayLen(); i++) { PlannerDomValue parameterArray = parametersArray.valueAtIndex(i); int index = parameterArray.valueAtIndex(0).asInt(); std::string typeString = parameterArray.valueAtIndex(1).asStr(); parameters.push_back(std::pair< int, voltdb::ValueType>(index, stringToValue(typeString))); } } }