Exemplo n.º 1
0
/**
 * 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);
}
Exemplo n.º 2
0
/** Parse JSON parameters to create a hash range expression */
static AbstractExpression*
hashRangeFactory(PlannerDomValue obj) {
    PlannerDomValue hashColumnValue = obj.valueForKey("HASH_COLUMN");

    PlannerDomValue rangesArray = obj.valueForKey("RANGES");

    srange_type *ranges = new srange_type[rangesArray.arrayLen()];
    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");

        ranges[ii] = srange_type(rangeStartValue.asInt(), rangeEndValue.asInt());
    }
    return new HashRangeExpression(hashColumnValue.asInt(), ranges, static_cast<int>(rangesArray.arrayLen()));
}