Search in sources :

Example 71 with Procedure

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

the class TestProcedureProcessor method testFunctionInput.

/**
 * defect 23975
 */
@Test
public void testFunctionInput() throws Exception {
    MetadataStore metadataStore = new MetadataStore();
    // $NON-NLS-1$
    Schema v1 = RealMetadataFactory.createVirtualModel("v1", metadataStore);
    // $NON-NLS-1$
    ProcedureParameter p1 = RealMetadataFactory.createParameter("in", ParameterInfo.IN, DataTypeManager.DefaultDataTypes.STRING);
    // $NON-NLS-1$ //$NON-NLS-2$
    ColumnSet<Procedure> rs1 = RealMetadataFactory.createResultSet("v1.rs1", new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.STRING });
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode n1 = new QueryNode("CREATE VIRTUAL PROCEDURE BEGIN declare string VARIABLES.x = '1'; exec v1.vp2(concat(x, v1.vp1.in)); END");
    // $NON-NLS-1$
    Procedure vt1 = RealMetadataFactory.createVirtualProcedure("vp1", v1, Arrays.asList(p1), n1);
    vt1.setResultSet(rs1);
    // $NON-NLS-1$
    ProcedureParameter p2 = RealMetadataFactory.createParameter("in", ParameterInfo.IN, DataTypeManager.DefaultDataTypes.STRING);
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode n2 = new QueryNode("CREATE VIRTUAL PROCEDURE BEGIN select v1.vp2.in; end");
    // $NON-NLS-1$
    Procedure vt2 = RealMetadataFactory.createVirtualProcedure("vp2", v1, Arrays.asList(p2), n2);
    // $NON-NLS-1$ //$NON-NLS-2$
    vt2.setResultSet(RealMetadataFactory.createResultSet("v1.rs1", new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.STRING }));
    // $NON-NLS-1$
    String sql = "exec v1.vp1('1')";
    List[] expected = new List[] { // $NON-NLS-1$
    Arrays.asList(new Object[] { "11" }) };
    QueryMetadataInterface metadata = RealMetadataFactory.createTransformationMetadata(metadataStore, "foo");
    // Construct data manager with data
    // Plan query
    ProcessorPlan plan = getProcedurePlan(sql, metadata);
    // Run query
    helpTestProcess(plan, expected, new FakeDataManager(), metadata);
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) TempMetadataStore(org.teiid.query.metadata.TempMetadataStore) ProcedureParameter(org.teiid.metadata.ProcedureParameter) FakeDataManager(org.teiid.query.processor.FakeDataManager) QueryNode(org.teiid.query.mapping.relational.QueryNode) Schema(org.teiid.metadata.Schema) Procedure(org.teiid.metadata.Procedure) List(java.util.List) ArrayList(java.util.ArrayList) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Test(org.junit.Test)

Example 72 with Procedure

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

the class TestResolver method testExecWithDuplicateNames.

@Test
public void testExecWithDuplicateNames() {
    MetadataStore metadataStore = new MetadataStore();
    Schema pm1 = RealMetadataFactory.createPhysicalModel("pm1", metadataStore);
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    ColumnSet<Procedure> rs2 = RealMetadataFactory.createResultSet("rs2", new String[] { "in", "e2" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER });
    // $NON-NLS-1$
    ProcedureParameter rs2p2 = RealMetadataFactory.createParameter("in", ParameterInfo.IN, DataTypeManager.DefaultDataTypes.STRING);
    // $NON-NLS-1$
    Procedure sq2 = RealMetadataFactory.createStoredProcedure("sq2", pm1, Arrays.asList(rs2p2));
    sq2.setResultSet(rs2);
    QueryMetadataInterface metadata = RealMetadataFactory.createTransformationMetadata(metadataStore, "example1");
    // $NON-NLS-1$ //$NON-NLS-2$
    helpResolveException("select * from pm1.sq2", metadata, "TEIID30114 Cannot access procedure pm1.sq2 using table semantics since the parameter and result set column names are not all unique.");
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) TempMetadataStore(org.teiid.query.metadata.TempMetadataStore) ProcedureParameter(org.teiid.metadata.ProcedureParameter) Schema(org.teiid.metadata.Schema) Procedure(org.teiid.metadata.Procedure) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 73 with Procedure

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

the class ODataSchemaBuilder method buildFunction.

static void buildFunction(String schemaName, Procedure proc, ArrayList<CsdlComplexType> complexTypes, ArrayList<CsdlFunction> functions, ArrayList<CsdlFunctionImport> functionImports, CsdlSchema csdlSchema) {
    CsdlFunction edmFunction = new CsdlFunction();
    edmFunction.setName(proc.getName());
    edmFunction.setBound(false);
    ArrayList<CsdlParameter> params = new ArrayList<CsdlParameter>();
    for (ProcedureParameter pp : proc.getParameters()) {
        EdmPrimitiveTypeKind odataType = ODataTypeManager.odataType(pp.getRuntimeType());
        if (pp.getType().equals(ProcedureParameter.Type.ReturnValue)) {
            edmFunction.setReturnType(new CsdlReturnType().setType(odataType.getFullQualifiedName()).setCollection(DataTypeManager.isArrayType(pp.getRuntimeType())));
            continue;
        }
        if (pp.getType().equals(ProcedureParameter.Type.In) || pp.getType().equals(ProcedureParameter.Type.InOut)) {
            CsdlParameter parameter = buildParameter(pp, odataType);
            addOperationParameterAnnotations(pp, parameter, csdlSchema);
            params.add(parameter);
        }
    }
    edmFunction.setParameters(params);
    // add a complex type for return resultset.
    ColumnSet<Procedure> returnColumns = proc.getResultSet();
    if (returnColumns != null) {
        CsdlComplexType complexType = buildComplexType(proc, returnColumns, csdlSchema);
        complexTypes.add(complexType);
        FullQualifiedName odataType = new FullQualifiedName(schemaName, complexType.getName());
        edmFunction.setReturnType((new CsdlReturnType().setType(odataType).setCollection(true)));
    }
    CsdlFunctionImport functionImport = new CsdlFunctionImport();
    functionImport.setName(proc.getName()).setFunction(new FullQualifiedName(schemaName, proc.getName()));
    addOperationAnnotations(proc, edmFunction, csdlSchema);
    functions.add(edmFunction);
    functionImports.add(functionImport);
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) FullQualifiedName(org.apache.olingo.commons.api.edm.FullQualifiedName) ArrayList(java.util.ArrayList) Procedure(org.teiid.metadata.Procedure) EdmPrimitiveTypeKind(org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind)

Example 74 with Procedure

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

the class ODataSchemaBuilder method buildProcedures.

static void buildProcedures(org.teiid.metadata.Schema schema, CsdlSchema csdlSchema) {
    // procedures
    ArrayList<CsdlComplexType> complexTypes = new ArrayList<CsdlComplexType>();
    ArrayList<CsdlFunction> functions = new ArrayList<CsdlFunction>();
    ArrayList<CsdlFunctionImport> functionImports = new ArrayList<CsdlFunctionImport>();
    ArrayList<CsdlAction> actions = new ArrayList<CsdlAction>();
    ArrayList<CsdlActionImport> actionImports = new ArrayList<CsdlActionImport>();
    for (Procedure proc : schema.getProcedures().values()) {
        if (!allowedProcedure(proc)) {
            LogManager.logDetail(LogConstants.CTX_ODATA, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16032, proc.getFullName()));
            continue;
        }
        if (isFuntion(proc)) {
            buildFunction(schema.getName(), proc, complexTypes, functions, functionImports, csdlSchema);
        } else {
            buildAction(schema.getName(), proc, complexTypes, actions, actionImports, csdlSchema);
        }
    }
    csdlSchema.setComplexTypes(complexTypes);
    csdlSchema.setFunctions(functions);
    csdlSchema.setActions(actions);
    csdlSchema.getEntityContainer().setFunctionImports(functionImports);
    csdlSchema.getEntityContainer().setActionImports(actionImports);
}
Also used : ArrayList(java.util.ArrayList) Procedure(org.teiid.metadata.Procedure)

Example 75 with Procedure

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

the class ODataSchemaBuilder method buildAction.

static void buildAction(String schemaName, Procedure proc, ArrayList<CsdlComplexType> complexTypes, ArrayList<CsdlAction> actions, ArrayList<CsdlActionImport> actionImports, CsdlSchema csdlSchema) {
    CsdlAction edmAction = new CsdlAction();
    edmAction.setName(proc.getName());
    edmAction.setBound(false);
    ArrayList<CsdlParameter> params = new ArrayList<CsdlParameter>();
    for (ProcedureParameter pp : proc.getParameters()) {
        EdmPrimitiveTypeKind odatatype = ODataTypeManager.odataType(pp.getRuntimeType());
        if (pp.getType().equals(ProcedureParameter.Type.ReturnValue)) {
            edmAction.setReturnType(new CsdlReturnType().setType(odatatype.getFullQualifiedName()).setCollection(DataTypeManager.isArrayType(pp.getRuntimeType())));
            continue;
        }
        if (pp.getType().equals(ProcedureParameter.Type.In) || pp.getType().equals(ProcedureParameter.Type.InOut)) {
            CsdlParameter parameter = buildParameter(pp, odatatype);
            addOperationParameterAnnotations(pp, parameter, csdlSchema);
            params.add(parameter);
        }
    }
    edmAction.setParameters(params);
    // add a complex type for return resultset.
    ColumnSet<Procedure> returnColumns = proc.getResultSet();
    if (returnColumns != null) {
        CsdlComplexType complexType = buildComplexType(proc, returnColumns, csdlSchema);
        complexTypes.add(complexType);
        edmAction.setReturnType((new CsdlReturnType().setType(new FullQualifiedName(schemaName, complexType.getName())).setCollection(true)));
    }
    CsdlActionImport actionImport = new CsdlActionImport();
    actionImport.setName(proc.getName()).setAction(new FullQualifiedName(schemaName, proc.getName()));
    addOperationAnnotations(proc, edmAction, csdlSchema);
    actions.add(edmAction);
    actionImports.add(actionImport);
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) FullQualifiedName(org.apache.olingo.commons.api.edm.FullQualifiedName) ArrayList(java.util.ArrayList) Procedure(org.teiid.metadata.Procedure) EdmPrimitiveTypeKind(org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind)

Aggregations

Procedure (org.teiid.metadata.Procedure)82 ProcedureParameter (org.teiid.metadata.ProcedureParameter)36 Test (org.junit.Test)35 MetadataFactory (org.teiid.metadata.MetadataFactory)30 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)27 Schema (org.teiid.metadata.Schema)16 Column (org.teiid.metadata.Column)14 MetadataStore (org.teiid.metadata.MetadataStore)11 Properties (java.util.Properties)10 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)10 Table (org.teiid.metadata.Table)9 QueryNode (org.teiid.query.mapping.relational.QueryNode)8 List (java.util.List)6 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)6 TempMetadataStore (org.teiid.query.metadata.TempMetadataStore)5 TranslatorException (org.teiid.translator.TranslatorException)5 ODataType (org.teiid.translator.odata4.ODataMetadataProcessor.ODataType)5 ArrayList (java.util.ArrayList)4 Call (org.teiid.language.Call)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3