Search in sources :

Example 1 with FunctionParameter

use of org.teiid.metadata.FunctionParameter in project teiid by teiid.

the class FunctionMetadataReader method parseParameter.

private static FunctionParameter parseParameter(XMLStreamReader reader) throws XMLStreamException {
    FunctionParameter fp = new FunctionParameter();
    if (reader.getAttributeCount() > 0) {
        for (int i = 0; i < reader.getAttributeCount(); i++) {
            String attrName = reader.getAttributeLocalName(i);
            String attrValue = reader.getAttributeValue(i);
            if (Element.NAME.getLocalName().equals(attrName)) {
                fp.setName(attrValue);
            } else if (Element.DESCRIPTION.getLocalName().equals(attrName)) {
                fp.setDescription(attrValue);
            } else if (Element.TYPE.getLocalName().equals(attrName)) {
                fp.setType(attrValue);
            }
        }
    }
    while (reader.nextTag() != XMLStreamConstants.END_ELEMENT) ;
    return fp;
}
Also used : FunctionParameter(org.teiid.metadata.FunctionParameter)

Example 2 with FunctionParameter

use of org.teiid.metadata.FunctionParameter in project teiid by teiid.

the class FunctionMetadataValidator method validateFunctionMethod.

/**
 * Determine whether a FunctionMethod is valid.  The following items are validated:
 * <UL>
 * <LI>Validate method name</LI>
 * <LI>Validate description</LI>
 * <LI>Validate category</LI>
 * <LI>Validate invocation method</LI>
 * <LI>Validate all input parameters</LI>
 * <LI>Validate output parameter</LI>
 * </UL>
 * @param method The method to validate
 * @param report The report to update during validation
 */
public static final void validateFunctionMethod(FunctionMethod method, ValidatorReport report, Map<String, Datatype> runtimeTypeMap) {
    if (method == null) {
        // $NON-NLS-1$ //$NON-NLS-2$
        updateReport(report, method, QueryPlugin.Util.getString("ERR.015.001.0052", "FunctionMethod"));
        // can't validate
        return;
    }
    try {
        // Validate attributes
        validateName(method.getName());
        validateDescription(method.getDescription());
        validateCategory(method.getCategory());
        validateInvocationMethod(method.getInvocationClass(), method.getInvocationMethod(), method.getPushdown());
        // Validate input parameters
        List<FunctionParameter> params = method.getInputParameters();
        if (params != null && !params.isEmpty()) {
            for (int i = 0; i < params.size(); i++) {
                FunctionParameter param = params.get(i);
                validateFunctionParameter(param);
                param.setPosition(i + 1);
                MetadataFactory.setDataType(param.getRuntimeType(), param, runtimeTypeMap, true);
                param.getUUID();
            }
        }
        // Validate output parameters
        validateFunctionParameter(method.getOutputParameter());
        method.getOutputParameter().setPosition(0);
        MetadataFactory.setDataType(method.getOutputParameter().getRuntimeType(), method.getOutputParameter(), runtimeTypeMap, true);
    } catch (FunctionMetadataException e) {
        updateReport(report, method, e.getMessage());
    }
}
Also used : FunctionMetadataException(org.teiid.api.exception.query.FunctionMetadataException) FunctionParameter(org.teiid.metadata.FunctionParameter)

Example 3 with FunctionParameter

use of org.teiid.metadata.FunctionParameter in project teiid by teiid.

the class SystemSource method addUuidFunction.

private void addUuidFunction() {
    FunctionMethod rand = new // $NON-NLS-1$ //$NON-NLS-2$
    FunctionMethod(// $NON-NLS-1$ //$NON-NLS-2$
    SourceSystemFunctions.UUID, // $NON-NLS-1$ //$NON-NLS-2$
    QueryPlugin.Util.getString("SystemSource.uuid_desc"), // $NON-NLS-1$ //$NON-NLS-2$
    MISCELLANEOUS, // $NON-NLS-1$ //$NON-NLS-2$
    FUNCTION_CLASS, // $NON-NLS-1$ //$NON-NLS-2$
    "uuid", new FunctionParameter[] {}, // $NON-NLS-1$ //$NON-NLS-2$
    new FunctionParameter("result", DataTypeManager.DefaultDataTypes.STRING, QueryPlugin.Util.getString("SystemSource.uuid_result_desc")));
    rand.setDeterminism(Determinism.NONDETERMINISTIC);
    functions.add(rand);
}
Also used : FunctionMethod(org.teiid.metadata.FunctionMethod) FunctionParameter(org.teiid.metadata.FunctionParameter)

Example 4 with FunctionParameter

use of org.teiid.metadata.FunctionParameter in project teiid by teiid.

the class SystemSource method addCommandPayloadFunctions.

private void addCommandPayloadFunctions() {
    functions.add(new // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    FunctionMethod(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    "commandpayload", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    QueryPlugin.Util.getString("SystemSource.CommandPayload_desc0"), // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    MISCELLANEOUS, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    PushDown.CANNOT_PUSHDOWN, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    FUNCTION_CLASS, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    "commandPayload", null, new FunctionParameter("result", DataTypeManager.DefaultDataTypes.STRING, QueryPlugin.Util.getString("SystemSource.CommandPayload_result")), true, // $NON-NLS-1$ //$NON-NLS-2$
    Determinism.COMMAND_DETERMINISTIC));
    functions.add(new // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    FunctionMethod(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    "commandpayload", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    QueryPlugin.Util.getString("SystemSource.CommandPayload_desc1"), // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    MISCELLANEOUS, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    PushDown.CANNOT_PUSHDOWN, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    FUNCTION_CLASS, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    "commandPayload", Arrays.asList(// $NON-NLS-1$ //$NON-NLS-2$
    new FunctionParameter("property", DataTypeManager.DefaultDataTypes.STRING, QueryPlugin.Util.getString("SystemSource.CommandPayload_property"))), new FunctionParameter("result", DataTypeManager.DefaultDataTypes.STRING, QueryPlugin.Util.getString("SystemSource.CommandPayload_result")), true, // $NON-NLS-1$ //$NON-NLS-2$
    Determinism.COMMAND_DETERMINISTIC));
}
Also used : FunctionParameter(org.teiid.metadata.FunctionParameter)

Example 5 with FunctionParameter

use of org.teiid.metadata.FunctionParameter in project teiid by teiid.

the class SystemSource method addAtan2Function.

private void addAtan2Function(String name, String description) {
    functions.add(new FunctionMethod(name, description, NUMERIC, FUNCTION_CLASS, name, new FunctionParameter[] { // $NON-NLS-1$ //$NON-NLS-2$
    new FunctionParameter("number1", DataTypeManager.DefaultDataTypes.DOUBLE, QueryPlugin.Util.getString("SystemSource.Atan_arg1")), // $NON-NLS-1$ //$NON-NLS-2$
    new FunctionParameter("number2", DataTypeManager.DefaultDataTypes.DOUBLE, QueryPlugin.Util.getString("SystemSource.Atan_arg2")) }, // $NON-NLS-1$
    new FunctionParameter("result", DataTypeManager.DefaultDataTypes.DOUBLE, description)));
    functions.add(new FunctionMethod(name, description, NUMERIC, FUNCTION_CLASS, name, new FunctionParameter[] { // $NON-NLS-1$ //$NON-NLS-2$
    new FunctionParameter("number1", DataTypeManager.DefaultDataTypes.BIG_DECIMAL, QueryPlugin.Util.getString("SystemSource.Atan_arg1")), // $NON-NLS-1$ //$NON-NLS-2$
    new FunctionParameter("number2", DataTypeManager.DefaultDataTypes.BIG_DECIMAL, QueryPlugin.Util.getString("SystemSource.Atan_arg2")) }, // $NON-NLS-1$
    new FunctionParameter("result", DataTypeManager.DefaultDataTypes.DOUBLE, description)));
}
Also used : FunctionMethod(org.teiid.metadata.FunctionMethod) FunctionParameter(org.teiid.metadata.FunctionParameter)

Aggregations

FunctionParameter (org.teiid.metadata.FunctionParameter)36 FunctionMethod (org.teiid.metadata.FunctionMethod)31 Test (org.junit.Test)9 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 DeployVDBParameter (org.teiid.jdbc.FakeServer.DeployVDBParameter)3 ArrayList (java.util.ArrayList)2 AggregateAttributes (org.teiid.metadata.AggregateAttributes)2 FileInputStream (java.io.FileInputStream)1 Method (java.lang.reflect.Method)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Before (org.junit.Before)1 BeforeClass (org.junit.BeforeClass)1 UserDefinedAggregate (org.teiid.UserDefinedAggregate)1 FunctionExecutionException (org.teiid.api.exception.query.FunctionExecutionException)1 FunctionMetadataException (org.teiid.api.exception.query.FunctionMetadataException)1 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)1 BinaryType (org.teiid.core.types.BinaryType)1 ReflectionHelper (org.teiid.core.util.ReflectionHelper)1