Search in sources :

Example 11 with ProcedureParameter

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

the class LanguageBridgeFactory method translate.

/* Execute */
Call translate(StoredProcedure sp) {
    Procedure proc = null;
    if (sp.getProcedureID() != null) {
        try {
            proc = this.metadataFactory.getProcedure(sp.getGroup().getName());
        } catch (TranslatorException e) {
            throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30486, e);
        }
    }
    Class<?> returnType = null;
    List<Argument> translatedParameters = new ArrayList<Argument>();
    for (SPParameter param : sp.getParameters()) {
        Direction direction = Direction.IN;
        switch(param.getParameterType()) {
            case ParameterInfo.IN:
                direction = Direction.IN;
                break;
            case ParameterInfo.INOUT:
                direction = Direction.INOUT;
                break;
            case ParameterInfo.OUT:
                direction = Direction.OUT;
                break;
            case ParameterInfo.RESULT_SET:
                // already part of the metadata
                continue;
            case ParameterInfo.RETURN_VALUE:
                returnType = param.getClassType();
                continue;
        }
        if (param.isUsingDefault() && BaseColumn.OMIT_DEFAULT.equalsIgnoreCase(metadataFactory.getMetadata().getExtensionProperty(param.getMetadataID(), BaseColumn.DEFAULT_HANDLING, false))) {
            continue;
        }
        ProcedureParameter metadataParam = metadataFactory.getParameter(param);
        // we can assume for now that all arguments will be literals, which may be multivalued
        org.teiid.language.Expression value = null;
        if (direction != Direction.OUT) {
            if (param.isVarArg()) {
                ArrayImpl av = (ArrayImpl) ((Constant) param.getExpression()).getValue();
                if (av != null) {
                    for (Object obj : av.getValues()) {
                        Argument arg = new Argument(direction, new Literal(obj, param.getClassType().getComponentType()), param.getClassType().getComponentType(), metadataParam);
                        translatedParameters.add(arg);
                    }
                }
                break;
            }
            value = translate(param.getExpression());
        }
        Argument arg = new Argument(direction, value, param.getClassType(), metadataParam);
        translatedParameters.add(arg);
    }
    Call call = new Call(removeSchemaName(sp.getProcedureName()), translatedParameters, proc);
    call.setReturnType(returnType);
    return call;
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) ArrayImpl(org.teiid.core.types.ArrayImpl) org.teiid.language(org.teiid.language) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) Direction(org.teiid.language.Argument.Direction) Procedure(org.teiid.metadata.Procedure) TranslatorException(org.teiid.translator.TranslatorException)

Example 12 with ProcedureParameter

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

the class TestProcedureProcessor method addProc.

private void addProc(TransformationMetadata metadata, String name, String query, String[] rsCols, String[] rsTypes, String[] params, String[] paramTypes) {
    // $NON-NLS-1$
    Schema pm1 = metadata.getMetadataStore().getSchema("PM1");
    pm1.getProcedures().remove(name.toUpperCase());
    ColumnSet<Procedure> rs2 = RealMetadataFactory.createResultSet("rs1", rsCols, rsTypes);
    // $NON-NLS-1$
    QueryNode sq2n1 = new QueryNode(query);
    ArrayList<ProcedureParameter> procParams = new ArrayList<ProcedureParameter>(params.length);
    for (int i = 0; i < params.length; i++) {
        procParams.add(RealMetadataFactory.createParameter(params[i], SPParameter.IN, paramTypes[i]));
    }
    // $NON-NLS-1$
    Procedure sq1 = RealMetadataFactory.createVirtualProcedure(name, pm1, procParams, sq2n1);
    sq1.setResultSet(rs2);
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) QueryNode(org.teiid.query.mapping.relational.QueryNode) Schema(org.teiid.metadata.Schema) ArrayList(java.util.ArrayList) Procedure(org.teiid.metadata.Procedure)

Example 13 with ProcedureParameter

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

the class TestProcedureRelational method testIssue119.

/*
     * The following are tests that were removed from the validator.  We are no longer trying to validate a priori whether 
     * procedure input criteria is valid.  This can be addressed later more generally when we do up front validation of
     * access patterns and access patterns have a wider range of semantics.
     * 
    @Test public void testProcInVirtualGroupDefect14609_1() throws Exception{
        helpValidate("select ve3 from vm1.vgvp1 where ve1=1.1 and ve2='a'", new String[] {"ve1 = 1.1"}, RealMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$
    }
   
    @Test public void testProcInVirtualGroupDefect14609_2() throws Exception{
        helpValidate("select ve3 from vm1.vgvp1 where convert(ve1, integer)=1 and ve2='a'", new String[] {"convert(ve1, integer) = 1" }, RealMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$
    }
    
    @Test public void testProcInVirtualGroupDefect14609_3() throws Exception{
        helpValidate("select ve3 from vm1.vgvp1 where 1.1=ve1 and ve2='a'", new String[] {"1.1 = ve1" }, RealMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$
    }
    
    @Test public void testProcInVirtualGroupDefect14609_4() throws Exception{
        helpValidate("select ve3 from vm1.vgvp1 where 1=convert(ve1, integer) and ve2='a'", new String[] {"1 = convert(ve1, integer)" }, RealMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$
    }    

    @Test public void testDefect15861() throws Exception{
        helpValidate("select ve3 from vm1.vgvp1 where (ve1=1 or ve1=2) and ve2='a'", new String[] {"(ve1 = 1) OR (ve1 = 2)", "ve1 = 2"}, RealMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    }

    @Test public void testProcInVirtualGroup1_Defect20164() {
        helpFailProcedure("select ve3 from vm1.vgvp2 where (ve1=1 and ve2='a') or ve3='c'", RealMetadataFactory.example1Cached()); //$NON-NLS-1$
    }

    @Test public void testProcInVirtualGroup2_Defect20164() {
        helpFailProcedure("select ve3 from vm1.vgvp2 where ve1=1 or ve2='a'", RealMetadataFactory.example1Cached()); //$NON-NLS-1$
    }

    @Test public void testProcInVirtualGroup3_Defect20164() {
        helpFailProcedure("select ve3 from vm1.vgvp2, pm1.g1 where ve1=pm1.g1.e2 and ve2='a'", RealMetadataFactory.example1Cached()); //$NON-NLS-1$
    }

    @Test public void testProcInVirtualGroup4_Defect20164() {
        helpValidate("select ve3 from vm1.vgvp2 where (ve1=1 and ve2='a') and (ve3='a' OR ve3='c')", new String[0], RealMetadataFactory.example1Cached()); //$NON-NLS-1$
    }

    @Test public void testProcInVirtualGroup5_Defect20164() {
        helpFailProcedure("select ve3 from vm1.vgvp2 where ve1=1 and NOT(ve2='a')", RealMetadataFactory.example1Cached()); //$NON-NLS-1$
    }

    @Test public void testProcInVirtualGroup6_Defect20164() {
        helpValidate("select ve3 from vm1.vgvp2 where ve1=1 and ve2 is null", new String[0], RealMetadataFactory.example1Cached()); //$NON-NLS-1$
    }

    @Test public void testProcInVirtualGroup7_Defect20164() {
        helpFailProcedure("select ve3 from vm1.vgvp2 where ve1=1 and ve2 is not null", RealMetadataFactory.example1Cached()); //$NON-NLS-1$
    }*/
/**
 * Ensures that dependent procedures are processed 1 at a time so that projected input values
 * are set correctly.
 */
@Test
public void testIssue119() throws Exception {
    MetadataStore metadataStore = new MetadataStore();
    // $NON-NLS-1$
    Schema v1 = RealMetadataFactory.createVirtualModel("v1", metadataStore);
    // $NON-NLS-1$
    Schema pm1 = RealMetadataFactory.createPhysicalModel("pm1", metadataStore);
    // $NON-NLS-1$
    ProcedureParameter in = RealMetadataFactory.createParameter("in1", SPParameter.IN, DataTypeManager.DefaultDataTypes.INTEGER);
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
    ColumnSet<Procedure> rs1 = RealMetadataFactory.createResultSet("v1.vp1.rs1", new String[] { "e1", "e2", "e3", "e4", "e5" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.INTEGER });
    // $NON-NLS-1$
    QueryNode n1 = new QueryNode("CREATE VIRTUAL PROCEDURE BEGIN SELECT vp1.in1 e1, x.in1 e2, x.e1 e3, y.in1 e4, y.e1 e5 FROM pm1.sp119 x, pm1.sp119 y where x.in1 = vp1.in1 and y.in1 = x.e1; END");
    // $NON-NLS-1$
    Procedure vt1 = RealMetadataFactory.createVirtualProcedure("vp1", v1, Arrays.asList(in), n1);
    vt1.setResultSet(rs1);
    // $NON-NLS-1$
    ProcedureParameter in1 = RealMetadataFactory.createParameter("in1", SPParameter.IN, DataTypeManager.DefaultDataTypes.INTEGER);
    // $NON-NLS-1$ //$NON-NLS-2$
    ColumnSet<Procedure> rs3 = RealMetadataFactory.createResultSet("pm1.sp119.rs1", new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER });
    // $NON-NLS-1$
    Procedure sp1 = RealMetadataFactory.createStoredProcedure("sp119", pm1, Arrays.asList(in1));
    sp1.setResultSet(rs3);
    // $NON-NLS-1$
    String sql = "select * from (exec v1.vp1(1)) foo order by e4, e5";
    List<?>[] expected = new List[] { Arrays.asList(1, 1, 3, 3, 5), Arrays.asList(1, 1, 3, 3, 8), Arrays.asList(1, 1, 6, 6, 8), Arrays.asList(1, 1, 6, 6, 11) };
    QueryMetadataInterface metadata = RealMetadataFactory.createTransformationMetadata(metadataStore, "foo");
    // Construct data manager with data
    // Plan query
    ProcessorPlan plan = TestProcedureProcessor.getProcedurePlan(sql, metadata);
    // Run query
    HardcodedDataManager dataManager = new HardcodedDataManager() {

        @Override
        public TupleSource registerRequest(CommandContext context, Command command, String modelName, RegisterRequestParameter parameterObject) throws TeiidComponentException {
            if (command instanceof StoredProcedure) {
                StoredProcedure proc = (StoredProcedure) command;
                List<SPParameter> params = proc.getInputParameters();
                assertEquals(1, params.size());
                int value = (Integer) ((Constant) params.get(0).getExpression()).getValue();
                return new FakeTupleSource(command.getProjectedSymbols(), new List[] { Arrays.asList(value + 2), Arrays.asList(value + 5) });
            }
            return super.registerRequest(context, command, modelName, parameterObject);
        }
    };
    TestProcedureProcessor.helpTestProcess(plan, expected, dataManager, metadata);
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) CommandContext(org.teiid.query.util.CommandContext) SPParameter(org.teiid.query.sql.lang.SPParameter) Schema(org.teiid.metadata.Schema) MetadataStore(org.teiid.metadata.MetadataStore) StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) Command(org.teiid.query.sql.lang.Command) QueryNode(org.teiid.query.mapping.relational.QueryNode) StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) Procedure(org.teiid.metadata.Procedure) List(java.util.List) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 14 with ProcedureParameter

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

the class WSDLMetadataProcessor method buildSoapOperation.

private void buildSoapOperation(MetadataFactory mf, BindingOperation bindingOperation) {
    Operation operation = bindingOperation.getOperation();
    // add input
    String inputXML = null;
    Input input = operation.getInput();
    if (input != null) {
        Message message = input.getMessage();
        if (message != null) {
            inputXML = message.getQName().getLocalPart();
        }
    }
    // add output
    String outXML = null;
    Output output = operation.getOutput();
    if (output != null) {
        Message message = output.getMessage();
        if (message != null) {
            outXML = message.getQName().getLocalPart();
        }
    }
    // $NON-NLS-1$
    ExtensibilityElement operationExtension = getExtensibilityElement(bindingOperation.getExtensibilityElements(), "operation");
    if (!(operationExtension instanceof SOAPOperation) && !(operationExtension instanceof SOAP12Operation)) {
        return;
    }
    if (operationExtension instanceof SOAPOperation) {
        // soap:operation
        SOAPOperation soapOperation = (SOAPOperation) operationExtension;
        String style = soapOperation.getStyle();
        if (style.equalsIgnoreCase("rpc")) {
            // $NON-NLS-1$
            LogManager.logInfo(LogConstants.CTX_CONNECTOR, WSExecutionFactory.UTIL.gs(WSExecutionFactory.Event.TEIID15004, operation.getName()));
            return;
        }
    } else if (operationExtension instanceof SOAP12Operation) {
        // soap:operation
        SOAP12Operation soapOperation = (SOAP12Operation) operationExtension;
        String style = soapOperation.getStyle();
        if (style.equalsIgnoreCase("rpc")) {
            // $NON-NLS-1$
            LogManager.logInfo(LogConstants.CTX_CONNECTOR, WSExecutionFactory.UTIL.gs(WSExecutionFactory.Event.TEIID15004, operation.getName()));
            return;
        }
    }
    Procedure procedure = mf.addProcedure(operation.getName());
    procedure.setVirtual(false);
    procedure.setNameInSource(operation.getName());
    mf.addProcedureParameter(inputXML, TypeFacility.RUNTIME_NAMES.XML, Type.In, procedure);
    // $NON-NLS-1$
    ProcedureParameter param = mf.addProcedureParameter("stream", TypeFacility.RUNTIME_NAMES.BOOLEAN, Type.In, procedure);
    // $NON-NLS-1$
    param.setAnnotation("If the result should be streamed.");
    param.setNullType(NullType.Nullable);
    // $NON-NLS-1$
    param.setDefaultValue("false");
    mf.addProcedureParameter(outXML, TypeFacility.RUNTIME_NAMES.XML, Type.ReturnValue, procedure);
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) Input(javax.wsdl.Input) SOAPOperation(javax.wsdl.extensions.soap.SOAPOperation) SOAP12Operation(javax.wsdl.extensions.soap12.SOAP12Operation) Message(javax.wsdl.Message) Output(javax.wsdl.Output) Procedure(org.teiid.metadata.Procedure) Operation(javax.wsdl.Operation) SOAPOperation(javax.wsdl.extensions.soap.SOAPOperation) SOAP12Operation(javax.wsdl.extensions.soap12.SOAP12Operation) BindingOperation(javax.wsdl.BindingOperation) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement)

Example 15 with ProcedureParameter

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

the class WSExecutionFactory method getMetadata.

@Override
public void getMetadata(MetadataFactory metadataFactory, WSConnection conn) throws TranslatorException {
    Procedure p = metadataFactory.addProcedure(INVOKE);
    // $NON-NLS-1$
    p.setAnnotation("Invokes a webservice that returns an XML result");
    // $NON-NLS-1$
    metadataFactory.addProcedureParameter("result", TypeFacility.RUNTIME_NAMES.XML, Type.ReturnValue, p);
    // $NON-NLS-1$
    ProcedureParameter param = metadataFactory.addProcedureParameter("binding", TypeFacility.RUNTIME_NAMES.STRING, Type.In, p);
    // $NON-NLS-1$
    param.setAnnotation("The invocation binding (HTTP, SOAP11, SOAP12).  May be set or allowed to default to null to use the default binding.");
    param.setNullType(NullType.Nullable);
    // $NON-NLS-1$
    param = metadataFactory.addProcedureParameter("action", TypeFacility.RUNTIME_NAMES.STRING, Type.In, p);
    // $NON-NLS-1$
    param.setAnnotation("With a SOAP invocation, action sets the SOAPAction.  With HTTP it sets the HTTP Method (GET, POST - default, etc.).");
    param.setNullType(NullType.Nullable);
    // can be one of string, xml, clob
    // $NON-NLS-1$
    param = metadataFactory.addProcedureParameter("request", TypeFacility.RUNTIME_NAMES.XML, Type.In, p);
    // $NON-NLS-1$
    param.setAnnotation("The XML document or root element that represents the request.  If the ExecutionFactory is configured in with a DefaultServiceMode of MESSAGE, then the SOAP request must contain the entire SOAP message.");
    param.setNullType(NullType.Nullable);
    // $NON-NLS-1$
    param = metadataFactory.addProcedureParameter("endpoint", TypeFacility.RUNTIME_NAMES.STRING, Type.In, p);
    // $NON-NLS-1$
    param.setAnnotation("The relative or abolute endpoint to use.  May be set or allowed to default to null to use the default endpoint address.");
    param.setNullType(NullType.Nullable);
    // $NON-NLS-1$
    param = metadataFactory.addProcedureParameter("stream", TypeFacility.RUNTIME_NAMES.BOOLEAN, Type.In, p);
    // $NON-NLS-1$
    param.setAnnotation("If the result should be streamed.");
    param.setNullType(NullType.Nullable);
    // $NON-NLS-1$
    param.setDefaultValue("false");
    p = metadataFactory.addProcedure(INVOKE_HTTP);
    // $NON-NLS-1$
    p.setAnnotation("Invokes a webservice that returns an binary result");
    // $NON-NLS-1$
    metadataFactory.addProcedureParameter("result", TypeFacility.RUNTIME_NAMES.BLOB, Type.ReturnValue, p);
    // $NON-NLS-1$
    param = metadataFactory.addProcedureParameter("action", TypeFacility.RUNTIME_NAMES.STRING, Type.In, p);
    // $NON-NLS-1$
    param.setAnnotation("Sets the HTTP Method (GET, POST - default, etc.).");
    param.setNullType(NullType.Nullable);
    // can be one of string, xml, clob
    // $NON-NLS-1$
    param = metadataFactory.addProcedureParameter("request", TypeFacility.RUNTIME_NAMES.OBJECT, Type.In, p);
    // $NON-NLS-1$
    param.setAnnotation("The String, XML, BLOB, or CLOB value containing a payload (only for POST).");
    param.setNullType(NullType.Nullable);
    // $NON-NLS-1$
    param = metadataFactory.addProcedureParameter("endpoint", TypeFacility.RUNTIME_NAMES.STRING, Type.In, p);
    // $NON-NLS-1$
    param.setAnnotation("The relative or abolute endpoint to use.  May be set or allowed to default to null to use the default endpoint address.");
    param.setNullType(NullType.Nullable);
    // $NON-NLS-1$
    param = metadataFactory.addProcedureParameter("stream", TypeFacility.RUNTIME_NAMES.BOOLEAN, Type.In, p);
    // $NON-NLS-1$
    param.setAnnotation("If the result should be streamed.");
    param.setNullType(NullType.Nullable);
    // $NON-NLS-1$
    param.setDefaultValue("false");
    // $NON-NLS-1$
    metadataFactory.addProcedureParameter("contentType", TypeFacility.RUNTIME_NAMES.STRING, Type.Out, p);
    // $NON-NLS-1$
    param = metadataFactory.addProcedureParameter("headers", TypeFacility.RUNTIME_NAMES.CLOB, Type.In, p);
    // $NON-NLS-1$
    param.setAnnotation("Headers to send");
    param.setNullType(NullType.Nullable);
    WSDLMetadataProcessor metadataProcessor = new WSDLMetadataProcessor();
    // $NON-NLS-1$
    PropertiesUtils.setBeanProperties(metadataProcessor, metadataFactory.getModelProperties(), "importer");
    metadataProcessor.process(metadataFactory, conn);
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) Procedure(org.teiid.metadata.Procedure)

Aggregations

ProcedureParameter (org.teiid.metadata.ProcedureParameter)43 Procedure (org.teiid.metadata.Procedure)35 Test (org.junit.Test)12 MetadataFactory (org.teiid.metadata.MetadataFactory)9 Schema (org.teiid.metadata.Schema)8 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)8 MetadataStore (org.teiid.metadata.MetadataStore)7 Column (org.teiid.metadata.Column)6 ArrayList (java.util.ArrayList)5 QueryNode (org.teiid.query.mapping.relational.QueryNode)5 List (java.util.List)4 Table (org.teiid.metadata.Table)4 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)4 EdmPrimitiveTypeKind (org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind)2 FullQualifiedName (org.apache.olingo.commons.api.edm.FullQualifiedName)2 Argument (org.teiid.language.Argument)2 TempMetadataStore (org.teiid.query.metadata.TempMetadataStore)2 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)2 TranslatorException (org.teiid.translator.TranslatorException)2 ODataType (org.teiid.translator.odata4.ODataMetadataProcessor.ODataType)2