Search in sources :

Example 6 with ProcedureParameter

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

the class TestODataMetadataProcessor method testAction.

@Test
public void testAction() throws Exception {
    CsdlReturnType returnType = new CsdlReturnType();
    returnType.setType("Edm.String");
    MetadataFactory mf = actionMetadata("invoke", returnType, null);
    Procedure p = mf.getSchema().getProcedure("invoke");
    assertNotNull(p);
    assertEquals(3, p.getParameters().size());
    assertNull(p.getResultSet());
    assertNotNull(getReturnParameter(p));
    ProcedureParameter pp = getReturnParameter(p);
    assertEquals("string", pp.getRuntimeType());
    ODataType type = ODataType.valueOf(p.getProperty(ODataMetadataProcessor.ODATA_TYPE, false));
    assertEquals(ODataType.ACTION, type);
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) ODataType(org.teiid.translator.odata4.ODataMetadataProcessor.ODataType) Procedure(org.teiid.metadata.Procedure) Test(org.junit.Test)

Example 7 with ProcedureParameter

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

the class TestODataMetadataProcessor method testFunctionReturnPrimitiveCollection.

@Test
public void testFunctionReturnPrimitiveCollection() throws Exception {
    CsdlReturnType returnType = new CsdlReturnType();
    returnType.setType("Edm.String");
    returnType.setCollection(true);
    MetadataFactory mf = functionMetadata("invoke", returnType, null);
    Procedure p = mf.getSchema().getProcedure("invoke");
    assertNotNull(p);
    assertEquals(3, p.getParameters().size());
    assertNull(p.getResultSet());
    assertNotNull(getReturnParameter(p));
    ProcedureParameter pp = getReturnParameter(p);
    assertEquals("string[]", pp.getRuntimeType());
    ODataType type = ODataType.valueOf(p.getProperty(ODataMetadataProcessor.ODATA_TYPE, false));
    assertEquals(ODataType.FUNCTION, type);
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) ODataType(org.teiid.translator.odata4.ODataMetadataProcessor.ODataType) Procedure(org.teiid.metadata.Procedure) Test(org.junit.Test)

Example 8 with ProcedureParameter

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

the class TestValidator method helpCreateCase4237VirtualProcedureMetadata.

/**
 * Create fake metadata for this case.  Need a physical stored procedure and
 * a virtual stored procedure which calls the physical one.
 * @return
 */
private TransformationMetadata helpCreateCase4237VirtualProcedureMetadata() {
    MetadataStore metadataStore = new MetadataStore();
    // $NON-NLS-1$
    Schema physicalModel = RealMetadataFactory.createPhysicalModel("pm1", metadataStore);
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    ColumnSet<Procedure> resultSet = RealMetadataFactory.createResultSet("pm1.rs", new String[] { "e1", "e2" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER });
    // $NON-NLS-1$
    ProcedureParameter inParam = RealMetadataFactory.createParameter("in", ParameterInfo.IN, DataTypeManager.DefaultDataTypes.STRING);
    // $NON-NLS-1$ //$NON-NLS-2$
    Procedure storedProcedure = RealMetadataFactory.createStoredProcedure("sp", physicalModel, Arrays.asList(inParam));
    storedProcedure.setResultSet(resultSet);
    // $NON-NLS-1$
    Schema virtualModel = RealMetadataFactory.createVirtualModel("vm1", metadataStore);
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    ColumnSet<Procedure> virtualResultSet = RealMetadataFactory.createResultSet("vm1.rs", new String[] { "e1", "e2" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER });
    // $NON-NLS-1$
    ProcedureParameter virtualInParam = RealMetadataFactory.createParameter("in1", ParameterInfo.IN, DataTypeManager.DefaultDataTypes.STRING);
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode queryNode = new QueryNode("CREATE VIRTUAL PROCEDURE BEGIN EXEC pm1.sp(vm1.sp.in1); END");
    // $NON-NLS-1$
    Procedure virtualStoredProcedure = RealMetadataFactory.createVirtualProcedure("sp", virtualModel, Arrays.asList(virtualInParam), queryNode);
    virtualStoredProcedure.setResultSet(virtualResultSet);
    return RealMetadataFactory.createTransformationMetadata(metadataStore, "case4237");
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) ProcedureParameter(org.teiid.metadata.ProcedureParameter) QueryNode(org.teiid.query.mapping.relational.QueryNode) Schema(org.teiid.metadata.Schema) Procedure(org.teiid.metadata.Procedure)

Example 9 with ProcedureParameter

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

the class TestDynamicImportedMetaData method testDDLMetadata.

@Test
public void testDDLMetadata() throws Exception {
    String ddl = "CREATE FOREIGN PROCEDURE getTextFiles(IN pathAndPattern varchar) RETURNS (file clob, filpath string) OPTIONS(UUID 'uuid')";
    MetadataFactory mf = createMetadataFactory("MarketData", new Properties());
    QueryParser.getQueryParser().parseDDL(mf, ddl);
    MetadataStore ms = mf.asMetadataStore();
    String ddl2 = "CREATE VIEW stock (symbol string, price bigdecimal) OPTIONS (UUID 'uuid')" + "AS select stock.* from (call MarketData.getTextFiles('*.txt')) f, " + "TEXTTABLE(f.file COLUMNS symbol string, price bigdecimal HEADER) stock;";
    MetadataFactory m2 = createMetadataFactory("portfolio", new Properties());
    QueryParser.getQueryParser().parseDDL(m2, ddl2);
    m2.getSchema().setPhysical(false);
    m2.mergeInto(ms);
    server.deployVDB("test", ms);
    // $NON-NLS-1$
    Connection conn = server.createConnection("jdbc:teiid:test");
    Properties props = new Properties();
    props.setProperty("importer.importProcedures", Boolean.TRUE.toString());
    MetadataStore store = getMetadata(props, conn).asMetadataStore();
    Procedure p = store.getSchema("test").getProcedure("test.MarketData.getTextFiles");
    assertNotNull(p);
    ProcedureParameter pp = p.getParameters().get(0);
    assertEquals("pathAndPattern", pp.getName());
    assertEquals("\"pathAndPattern\"", pp.getNameInSource());
    assertEquals(ProcedureParameter.Type.In, pp.getType());
    // assertEquals("string", pp.getDatatype().getName());
    Table t = store.getSchema("test").getTable("test.portfolio.stock");
    assertNotNull(t);
    List<Column> columns = t.getColumns();
    assertEquals(2, columns.size());
    assertEquals("symbol", columns.get(0).getName());
    assertEquals("price", columns.get(1).getName());
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) ProcedureParameter(org.teiid.metadata.ProcedureParameter) Table(org.teiid.metadata.Table) MetadataFactory(org.teiid.metadata.MetadataFactory) Column(org.teiid.metadata.Column) Connection(java.sql.Connection) Procedure(org.teiid.metadata.Procedure) Properties(java.util.Properties) Test(org.junit.Test)

Example 10 with ProcedureParameter

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

the class TestProcedure method checkParams.

private List<ProcedureParameter> checkParams(Procedure proc, String[] nameInSource, ProcedureParameter.Type[] direction, int[] index, Class<?>[] type) {
    List<ProcedureParameter> params = proc.getParameters();
    assertEquals(type.length, params.size());
    for (int i = 0; i < params.size(); i++) {
        ProcedureParameter param = params.get(i);
        assertEquals(nameInSource[i], param.getNameInSource());
        assertEquals(direction[i], param.getType());
        assertEquals(index[i], param.getPosition());
        assertEquals(type[i], param.getJavaType());
    }
    return params;
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter)

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