ArrayDesc inferSchema(std::vector<ArrayDesc> schemas, boost::shared_ptr<Query> query)
    {
        assert(schemas.size() == 1);

        ArrayDesc const& desc = schemas[0];
        size_t nDims = desc.getDimensions().size();
        vector<WindowBoundaries> window(nDims);
        size_t windowSize = 1;
        for (size_t i = 0, size = nDims * 2, boundaryNo = 0; i < size; i+=2, ++boundaryNo)
        {
            window[boundaryNo] = WindowBoundaries(
                evaluate(((boost::shared_ptr<OperatorParamLogicalExpression>&)_parameters[i])
                    ->getExpression(), query, TID_INT64).getInt64(),
                evaluate(((boost::shared_ptr<OperatorParamLogicalExpression>&)_parameters[i+1])
                    ->getExpression(), query, TID_INT64).getInt64()
                );
            windowSize *= window[boundaryNo]._boundaries.second + window[boundaryNo]._boundaries.first + 1;
            if (window[boundaryNo]._boundaries.first < 0)
                throw USER_QUERY_EXCEPTION(SCIDB_SE_INFER_SCHEMA, SCIDB_LE_OP_WINDOW_ERROR3,
                    _parameters[i]->getParsingContext());
            if (window[boundaryNo]._boundaries.second < 0)
                throw USER_QUERY_EXCEPTION(SCIDB_SE_INFER_SCHEMA, SCIDB_LE_OP_WINDOW_ERROR3,
                    _parameters[i + 1]->getParsingContext());
        }
        if (windowSize <= 1)
            throw USER_QUERY_EXCEPTION(SCIDB_SE_INFER_SCHEMA, SCIDB_LE_OP_WINDOW_ERROR4,
                _parameters[0]->getParsingContext());
        return createWindowDesc(desc);
    }
    ArrayDesc inferSchema(std::vector<ArrayDesc> schemas, boost::shared_ptr<Query> query)
	{
		assert(schemas.size() == 1);
        ArrayDesc const& schema = schemas[0];
        Dimensions const& dims = schema.getDimensions();
        size_t nDims = dims.size();
        size_t nParams = _parameters.size();
        assert((nParams & 1) == 0 || nParams >= nDims*2);
        Dimensions newDims(nDims - nParams/2);
        if (newDims.size() <= 0)
            throw USER_EXCEPTION(SCIDB_SE_INFER_SCHEMA, SCIDB_LE_OP_SLICE_ERROR1);
        std::vector<std::string> sliceDimName(nParams/2);
        for (size_t i = 0; i < nParams; i+=2) { 
            sliceDimName[i >> 1]  = ((boost::shared_ptr<OperatorParamReference>&)_parameters[i])->getObjectName();
        }
        size_t j = 0;
        for (size_t i = 0; i < nDims; i++) { 
            const std::string dimName = dims[i].getBaseName();
            int k = sliceDimName.size();
            while (--k >= 0
                   && sliceDimName[k] != dimName 
                   && !(sliceDimName[k][0] == '_' && (size_t)atoi(sliceDimName[k].c_str()+1) == i+1));
            if (k < 0)
            {
                if (j >= newDims.size())
                    throw USER_QUERY_EXCEPTION(SCIDB_SE_INFER_SCHEMA, SCIDB_LE_DUPLICATE_DIMENSION_NAME,
                                               _parameters[i]->getParsingContext()) << dimName;
                newDims[j++] = dims[i];
            }
        }        
        return ArrayDesc(schema.getName(), schema.getAttributes(), newDims);
	}
Beispiel #3
0
    ArrayDesc inferSchema(std::vector<ArrayDesc> schemas, std::shared_ptr<Query> query)
    {
        assert(schemas.size() == 0);
        assert(_parameters.size() == 2);
        assert(((std::shared_ptr<OperatorParam>&)_parameters[0])->getParamType() == PARAM_ARRAY_REF);
        assert(((std::shared_ptr<OperatorParam>&)_parameters[1])->getParamType() == PARAM_ARRAY_REF);

        std::string oldArrayName;
        std::string oldNamespaceName;
        std::string newArrayName;
        std::string newNamespaceName;

        const string &oldArrayNameOrg =
            ((std::shared_ptr<OperatorParamReference>&)_parameters[0])->getObjectName();
        query->getNamespaceArrayNames(oldArrayNameOrg, oldNamespaceName, oldArrayName);

        const string &newArrayNameOrg =
            ((std::shared_ptr<OperatorParamReference>&)_parameters[1])->getObjectName();
        query->getNamespaceArrayNames(newArrayNameOrg, newNamespaceName, newArrayName);

        if(newNamespaceName != oldNamespaceName)
        {
            throw USER_QUERY_EXCEPTION(
                SCIDB_SE_INFER_SCHEMA, SCIDB_LE_CANNOT_RENAME_ACROSS_NAMESPACES,
                _parameters[1]->getParsingContext())
                << ArrayDesc::makeQualifiedArrayName(oldNamespaceName, oldArrayName)
                << ArrayDesc::makeQualifiedArrayName(newNamespaceName, newArrayName);
        }

        if (scidb::namespaces::Communicator::containsArray(newNamespaceName, newArrayName))
        {
            throw USER_QUERY_EXCEPTION(SCIDB_SE_INFER_SCHEMA, SCIDB_LE_ARRAY_ALREADY_EXIST,
                _parameters[1]->getParsingContext()) << newArrayName;
        }
        ArrayDesc arrDesc;
        arrDesc.setDistribution(defaultPartitioning());
        arrDesc.setResidency(query->getDefaultArrayResidency());
        return arrDesc;
    }
Beispiel #4
0
    ArrayDesc inferSchema(std::vector<ArrayDesc> schemas, boost::shared_ptr<Query> query)
    {
        assert(schemas.size() == 0);
        assert(_parameters.size() == 2);
        assert(((boost::shared_ptr<OperatorParam>&)_parameters[1])->getParamType() == PARAM_ARRAY_REF);

        const string &newArrayName = ((boost::shared_ptr<OperatorParamReference>&)_parameters[1])->getObjectName();

        if (SystemCatalog::getInstance()->containsArray(newArrayName))
        {
            throw USER_QUERY_EXCEPTION(SCIDB_SE_INFER_SCHEMA, SCIDB_LE_ARRAY_ALREADY_EXIST,
                _parameters[1]->getParsingContext()) << newArrayName;
        }

        return ArrayDesc();
	}
    ArrayDesc inferSchema(std::vector<ArrayDesc> schemas, boost::shared_ptr<Query> query)
    {
        assert(schemas.size() == 1);

        ArrayDesc const& desc = schemas[0];
        size_t nDims = desc.getDimensions().size();
        vector<size_t> window(nDims);
        for (size_t i = 0; i < nDims; i++)
        {
           window[i] = evaluate(((boost::shared_ptr<OperatorParamLogicalExpression>&)_parameters[i])->getExpression(),
                                query, TID_INT64).getInt64();
           if ((ssize_t)window[i] <= 0)
               throw USER_QUERY_EXCEPTION(SCIDB_SE_INFER_SCHEMA, SCIDB_LE_OP_WINDOW_ERROR1,
                                          _parameters[i]->getParsingContext());
        }

        return createWindowDesc(desc, window);
        }
Beispiel #6
0
    ArrayDesc inferSchema(std::vector<ArrayDesc> schemas, std::shared_ptr<Query> query)
    {
        assert(schemas.size() == 1);

        ArrayDesc const& inputDesc = schemas[0];
        size_t nDims = inputDesc.getDimensions().size();
        Dimensions outDims(nDims);

        // How many parameters are of each type.
        size_t numAggregateCalls = 0;
        size_t numChunkSizes = 0;
        for (size_t i = nDims, n = _parameters.size(); i < n; ++i)
        {
            if (_parameters[i]->getParamType() == PARAM_AGGREGATE_CALL)
            {
                ++numAggregateCalls;
            }
            else // chunk size
            {
                ++numChunkSizes;
            }
        }
        if (numChunkSizes && numChunkSizes != nDims) {
            throw USER_EXCEPTION(SCIDB_SE_INFER_SCHEMA, SCIDB_LE_NUM_CHUNKSIZES_NOT_MATCH_NUM_DIMS) << "regrid()";
        }

        // Generate the output dims.
        for (size_t i = 0; i < nDims; i++)
        {
            int64_t blockSize = evaluate(((std::shared_ptr<OperatorParamLogicalExpression>&)_parameters[i])->getExpression(),
                                        query, TID_INT64).getInt64();
            if (blockSize <= 0) {
                throw USER_QUERY_EXCEPTION(SCIDB_SE_INFER_SCHEMA, SCIDB_LE_OP_REGRID_ERROR1,
                                           _parameters[i]->getParsingContext());
            }
            DimensionDesc const& srcDim = inputDesc.getDimensions()[i];
            int64_t chunkSize = srcDim.getRawChunkInterval();
            if (numChunkSizes) {
                size_t index = i + nDims + numAggregateCalls;
                chunkSize = evaluate(((std::shared_ptr<OperatorParamLogicalExpression>&)_parameters[index])->getExpression(),
                        query, TID_INT64).getInt64();
                if (chunkSize<=0) {
                    throw USER_EXCEPTION(SCIDB_SE_INFER_SCHEMA, SCIDB_LE_CHUNK_SIZE_MUST_BE_POSITIVE);
                }
            }
            outDims[i] = DimensionDesc( srcDim.getBaseName(),
                                        srcDim.getNamesAndAliases(),
                                        srcDim.getStartMin(),
                                        srcDim.getStartMin(),
                                        srcDim.getEndMax() == CoordinateBounds::getMax()
                                            ? CoordinateBounds::getMax()
                                            : srcDim.getStartMin() + (srcDim.getLength() + blockSize - 1)/blockSize - 1,
                                        srcDim.getEndMax() == CoordinateBounds::getMax()
                                            ? CoordinateBounds::getMax()
                                            : srcDim.getStartMin() + (srcDim.getLength() + blockSize - 1)/blockSize - 1,
                                        chunkSize,
                                        0  );
        }

        // Input and output dimensions are 1-to-1, so...
        _fixer.takeAllDimensions(inputDesc.getDimensions());

        ArrayDesc outSchema(inputDesc.getName(), Attributes(), outDims,
                            defaultPartitioning(),
                            query->getDefaultArrayResidency() );

        for (size_t i = nDims, j=nDims+numAggregateCalls; i<j; i++)
        {
            bool isInOrderAggregation = false;
            addAggregatedAttribute( (std::shared_ptr <OperatorParamAggregateCall> &) _parameters[i], inputDesc, outSchema,
                    isInOrderAggregation);
        }

        AttributeDesc et ((AttributeID) outSchema.getAttributes().size(), DEFAULT_EMPTY_TAG_ATTRIBUTE_NAME,  TID_INDICATOR, AttributeDesc::IS_EMPTY_INDICATOR, 0);
        outSchema.addAttribute(et);

        return outSchema;
    }