Example #1
0
    /**
     * Determine the schema of the output. inferSchema is called on the coordinator instance during query planning and
     * may be called several times as the planner gets its act together. It will always be called with the same inputs
     * for the same query. This function must behave deterministically, but the shape of the output may vary based on
     * inputs and parameters.
     * @param schemas all of the schemas of the input arrays (if the operator accepts any)
     * @param query the query context
     * @return the schema of the outpt, as described above.
     */
    ArrayDesc inferSchema(vector< ArrayDesc> schemas, shared_ptr< Query> query)
    {
        /*
         * Make one string attribute: id=0, name="instance_status" of type string, no flags, no default compression.
         * The ID of the attribute is simply a number from 0 to num_attributes-1 and must equal to its position
         * in the attributes vector.
         */
        AttributeDesc outputAttribute (0, "instance_status", TID_STRING, 0, 0);
        Attributes outputAttributes(1, outputAttribute);

        /* Add the empty tag attribute. Arrays with the empty tag are "emptyable" meaning that some cells may be empty.
         * It is a good practice to add this to every constructed array. In fact, in the future it may become the
         * default for all arrays.
         */
        outputAttributes = addEmptyTagAttribute(outputAttributes);

        /* The output dimension: from 0 to "*" with a chunk size of 1. The amount of data returned is so small that the
         * chunk size is not relevant.
         */
        DimensionDesc outputDimension("instance_no", 0, MAX_COORDINATE, 1, 0);
        Dimensions outputDimensions(1, outputDimension);

        /* The first argument is the name of the returned array. */
        return ArrayDesc("hello_instances", outputAttributes, outputDimensions);
    }
Example #2
0
/* inferSchema helps the query planner decide on the shape of
 * the output array. All operators must define this function.
 */
    ArrayDesc inferSchema(vector< ArrayDesc> schemas, shared_ptr< Query> query)
    {
        ArrayDesc const& matrix = schemas[0];
        if(matrix.getAttributes(true)[0].getType() != TID_STRING)
           throw SYSTEM_EXCEPTION(SCIDB_SE_INTERNAL, SCIDB_LE_ILLEGAL_OPERATION) <<  "cu requires a single string-valued attribute";
        Attributes outputAttributes(matrix.getAttributes());
        Dimensions outputDimensions(matrix.getDimensions());
        return ArrayDesc(matrix.getName(), outputAttributes, outputDimensions);
    }