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 } } }
void AbstractPlanNode::loadSortListFromJSONObject(PlannerDomValue obj, std::vector<AbstractExpression*> *sortExprs, std::vector<SortDirectionType> *sortDirs) { PlannerDomValue sortColumnsArray = obj.valueForKey("SORT_COLUMNS"); for (int i = 0; i < sortColumnsArray.arrayLen(); i++) { PlannerDomValue sortColumn = sortColumnsArray.valueAtIndex(i); bool hasDirection = (sortDirs == NULL), hasExpression = (sortExprs == NULL); if (sortDirs && sortColumn.hasNonNullKey("SORT_DIRECTION")) { hasDirection = true; std::string sortDirectionStr = sortColumn.valueForKey("SORT_DIRECTION").asStr(); sortDirs->push_back(stringToSortDirection(sortDirectionStr)); } if (sortExprs && sortColumn.hasNonNullKey("SORT_EXPRESSION")) { hasExpression = true; PlannerDomValue exprDom = sortColumn.valueForKey("SORT_EXPRESSION"); sortExprs->push_back(AbstractExpression::buildExpressionTree(exprDom)); } if (!(hasExpression && hasDirection)) { throw SerializableEEException(VOLT_EE_EXCEPTION_TYPE_EEEXCEPTION, "OrderByPlanNode::loadFromJSONObject:" " Does not have expression and direction."); } } }
void PartitionByPlanNode::loadFromJSONObject(PlannerDomValue obj) { // Start with the base class. AggregatePlanNode::loadFromJSONObject(obj); // Read the sort expressions and directions. PlannerDomValue sortByColumnArray = obj.valueForKey("SORT_COLUMNS"); for (int idx = 0; idx < sortByColumnArray.arrayLen(); idx += 1) { PlannerDomValue sortColumnValue = sortByColumnArray.valueAtIndex(idx); if (sortColumnValue.hasNonNullKey("SORT_EXPRESSION")) { PlannerDomValue exprDom = sortColumnValue.valueForKey("SORT_EXPRESSION"); m_sortExpressions.push_back(AbstractExpression::buildExpressionTree(exprDom)); } else { throw SerializableEEException(VOLT_EE_EXCEPTION_TYPE_EEEXCEPTION, "PartitionByPlanNode::loadFromJSONObject:" " Missing sort expression."); } if (sortColumnValue.hasNonNullKey("SORT_DIRECTION")) { std::string dirStr = sortColumnValue.valueForKey("SORT_DIRECTION").asStr(); m_sortDirections.push_back(stringToSortDirection(dirStr)); } else { throw SerializableEEException(VOLT_EE_EXCEPTION_TYPE_EEEXCEPTION, "PartitionByPlanNode::loadFromJSONObject:" " Missing sort direction."); } } }
void AbstractPlanNode::loadIntArrayFromJSONObject(const char* label, PlannerDomValue obj, std::vector<int>& result) { if (obj.hasNonNullKey(label)) { PlannerDomValue intArray = obj.valueForKey(label); for (int i = 0; i < intArray.arrayLen(); i++) { result.push_back(intArray.valueAtIndex(i).asInt()); } } }
void InsertPlanNode::loadFromJSONObject(PlannerDomValue obj) { AbstractOperationPlanNode::loadFromJSONObject(obj); m_multiPartition = obj.valueForKey("MULTI_PARTITION").asBool(); if (obj.hasNonNullKey("FIELD_MAP")) { PlannerDomValue fieldMap = obj.valueForKey("FIELD_MAP"); for (int i = 0; i < fieldMap.arrayLen(); ++i) { m_fieldMap.push_back(fieldMap.valueAtIndex(i).asInt()); } } m_isUpsert = false; if (obj.hasNonNullKey("UPSERT")) { m_isUpsert = true; } m_sourceIsPartitioned = false; if (obj.hasNonNullKey("SOURCE_IS_PARTITIONED")) { m_sourceIsPartitioned = true; } }
void AggregatePlanNode::loadFromJSONObject(PlannerDomValue obj) { PlannerDomValue aggregateColumnsArray = obj.valueForKey("AGGREGATE_COLUMNS"); for (int i = 0; i < aggregateColumnsArray.arrayLen(); i++) { PlannerDomValue aggregateColumnValue = aggregateColumnsArray.valueAtIndex(i); bool containsType = false; bool containsDistinct = false; bool containsOutputColumn = false; bool containsExpression = false; if (aggregateColumnValue.hasNonNullKey("AGGREGATE_TYPE")) { containsType = true; string aggregateColumnTypeString = aggregateColumnValue.valueForKey("AGGREGATE_TYPE").asStr(); m_aggregates.push_back(stringToExpression(aggregateColumnTypeString)); } if (aggregateColumnValue.hasNonNullKey("AGGREGATE_DISTINCT")) { containsDistinct = true; bool distinct = aggregateColumnValue.valueForKey("AGGREGATE_DISTINCT").asInt() == 1; m_distinctAggregates.push_back(distinct); } if (aggregateColumnValue.hasNonNullKey("AGGREGATE_OUTPUT_COLUMN")) { containsOutputColumn = true; int column = aggregateColumnValue.valueForKey("AGGREGATE_OUTPUT_COLUMN").asInt(); m_aggregateOutputColumns.push_back(column); } if (aggregateColumnValue.hasNonNullKey("AGGREGATE_EXPRESSION")) { containsExpression = true; PlannerDomValue exprDom = aggregateColumnValue.valueForKey("AGGREGATE_EXPRESSION"); m_aggregateInputExpressions.push_back(AbstractExpression::buildExpressionTree(exprDom)); } if(!(containsType && containsDistinct && containsOutputColumn)) { throw SerializableEEException(VOLT_EE_EXCEPTION_TYPE_EEEXCEPTION, "AggregatePlanNode::loadFromJSONObject:" " Missing type, distinct, or outputcolumn."); } if ( ! containsExpression) { m_aggregateInputExpressions.push_back(NULL); } } if (obj.hasNonNullKey("GROUPBY_EXPRESSIONS")) { PlannerDomValue groupByExpressionsArray = obj.valueForKey("GROUPBY_EXPRESSIONS"); for (int i = 0; i < groupByExpressionsArray.arrayLen(); i++) { m_groupByExpressions.push_back(AbstractExpression::buildExpressionTree(groupByExpressionsArray.valueAtIndex(i))); } } if (obj.hasNonNullKey("PRE_PREDICATE")) { m_prePredicate = AbstractExpression::buildExpressionTree(obj.valueForKey("PRE_PREDICATE")); } if (obj.hasNonNullKey("POST_PREDICATE")) { m_postPredicate = AbstractExpression::buildExpressionTree(obj.valueForKey("POST_PREDICATE")); } }
// Load boolean array from JSON object. // In IndexScanPlanNode (indexscannode.h and indexscannode.cpp), // we added a boolean vector "m_compare_not_distinct" // to indicate whether null values should be skipped for each search key column. // This function is used to deseralize that boolean vector. (ENG-11096) void AbstractPlanNode::loadBooleanArrayFromJSONObject(const char* label, PlannerDomValue obj, std::vector<bool>& result) { if (obj.hasNonNullKey(label)) { PlannerDomValue stringArray = obj.valueForKey(label); int len = stringArray.arrayLen(); for (int i = 0; i < len; ++i) { result.push_back(stringArray.valueAtIndex(i).asBool()); } } }
void AbstractPlanNode::OwningExpressionVector::loadExpressionArrayFromJSONObject(const char* label, PlannerDomValue obj) { clear(); if ( ! obj.hasNonNullKey(label)) { return; } PlannerDomValue arrayObj = obj.valueForKey(label); for (int i = 0; i < arrayObj.arrayLen(); i++) { AbstractExpression *expr = AbstractExpression::buildExpressionTree(arrayObj.valueAtIndex(i)); push_back(expr); } }