Exemplo n.º 1
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.asInt64(), rangeEndValue.asInt64());
    }
    return new HashRangeExpression(hashColumnValue.asInt(), ranges, static_cast<int>(rangesArray.arrayLen()));
}
Exemplo n.º 2
0
/** convert the enumerated value type into a concrete type for
 * constant value expressions templated ctors */
static AbstractExpression*
constantValueFactory(PlannerDomValue obj,
                     ValueType vt, ExpressionType et,
                     AbstractExpression *lc, AbstractExpression *rc)
{
    // read before ctor - can then instantiate fully init'd obj.
    NValue newvalue;
    bool isNull = obj.valueForKey("ISNULL").asBool();
    if (isNull)
    {
        newvalue = NValue::getNullValue(vt);
        return new ConstantValueExpression(newvalue);
    }

    PlannerDomValue valueValue = obj.valueForKey("VALUE");

    switch (vt) {
    case VALUE_TYPE_INVALID:
        throw SerializableEEException(VOLT_EE_EXCEPTION_TYPE_EEEXCEPTION,
                                      "constantValueFactory: Value type should"
                                      " never be VALUE_TYPE_INVALID");
    case VALUE_TYPE_NULL:
        throw SerializableEEException(VOLT_EE_EXCEPTION_TYPE_EEEXCEPTION,
                                      "constantValueFactory: And they should be"
                                      " never be this either! VALUE_TYPE_NULL");
    case VALUE_TYPE_TINYINT:
        newvalue = ValueFactory::getTinyIntValue(static_cast<int8_t>(valueValue.asInt64()));
        break;
    case VALUE_TYPE_SMALLINT:
        newvalue = ValueFactory::getSmallIntValue(static_cast<int16_t>(valueValue.asInt64()));
        break;
    case VALUE_TYPE_INTEGER:
        newvalue = ValueFactory::getIntegerValue(static_cast<int32_t>(valueValue.asInt64()));
        break;
    case VALUE_TYPE_BIGINT:
        newvalue = ValueFactory::getBigIntValue(static_cast<int64_t>(valueValue.asInt64()));
        break;
    case VALUE_TYPE_DOUBLE:
        newvalue = ValueFactory::getDoubleValue(static_cast<double>(valueValue.asDouble()));
        break;
    case VALUE_TYPE_VARCHAR:
        newvalue = ValueFactory::getStringValue(valueValue.asStr());
        break;
    case VALUE_TYPE_VARBINARY:
        // uses hex encoding
        newvalue = ValueFactory::getBinaryValue(valueValue.asStr());
        break;
    case VALUE_TYPE_TIMESTAMP:
        newvalue = ValueFactory::getTimestampValue(static_cast<int64_t>(valueValue.asInt64()));
        break;
    case VALUE_TYPE_DECIMAL:
        newvalue = ValueFactory::getDecimalValueFromString(valueValue.asStr());
        break;
    case VALUE_TYPE_BOOLEAN:
        newvalue = ValueFactory::getBooleanValue(valueValue.asBool());
        break;
    default:
        throw SerializableEEException(VOLT_EE_EXCEPTION_TYPE_EEEXCEPTION,
                                      "constantValueFactory: Unrecognized value"
                                      " type");
    }

    return new ConstantValueExpression(newvalue);
}