Search in sources :

Example 26 with ProcedureParameter

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

the class TestSwaggerMetadataProcessor method testTypes.

@Test
public void testTypes() throws TranslatorException {
    SwaggerExecutionFactory translator = new SwaggerExecutionFactory();
    translator.start();
    MetadataFactory mf = swaggerMetadata(translator);
    Procedure p = mf.getSchema().getProcedure("testReturnTypes");
    assertNotNull(p);
    assertEquals("GET", p.getProperty(RestMetadataExtension.METHOD, false).toUpperCase());
    assertEquals("http://localhost:8080/test/testReturnTypes", p.getProperty(RestMetadataExtension.URI, false));
    assertNotNull(p.getResultSet());
    ColumnSet<Procedure> results = p.getResultSet();
    assertEquals("byte", results.getColumnByName("a").getRuntimeType());
    assertEquals("integer", results.getColumnByName("b").getRuntimeType());
    assertEquals("integer", results.getColumnByName("c").getRuntimeType());
    assertEquals("long", results.getColumnByName("d").getRuntimeType());
    assertEquals("float", results.getColumnByName("e").getRuntimeType());
    assertEquals("double", results.getColumnByName("f").getRuntimeType());
    assertEquals("boolean", results.getColumnByName("g").getRuntimeType());
    assertEquals("string", results.getColumnByName("h").getRuntimeType());
    assertEquals("byte[]", results.getColumnByName("i").getRuntimeType());
    assertEquals("timestamp", results.getColumnByName("l").getRuntimeType());
    p = mf.getSchema().getProcedure("testTimeTypes");
    assertNotNull(p);
    assertEquals("GET", p.getProperty(RestMetadataExtension.METHOD, false).toUpperCase());
    assertEquals("http://localhost:8080/test/testTimeTypes", p.getProperty(RestMetadataExtension.URI, false));
    assertNotNull(p.getResultSet());
    results = p.getResultSet();
    assertEquals("timestamp", results.getColumnByName("date").getRuntimeType());
    assertEquals("timestamp", results.getColumnByName("sqlDate").getRuntimeType());
    // test types in parameters
    p = mf.getSchema().getProcedure("testTypes");
    assertNotNull(p);
    assertEquals("GET", p.getProperty(RestMetadataExtension.METHOD, false).toUpperCase());
    assertEquals("http://localhost:8080/test/testTypes", p.getProperty(RestMetadataExtension.URI, false));
    assertNotNull(p.getResultSet());
    List<ProcedureParameter> pp = p.getParameters();
    assertEquals("integer", pp.get(0).getRuntimeType());
    assertEquals("long", pp.get(1).getRuntimeType());
    assertEquals("float", pp.get(2).getRuntimeType());
    assertEquals("double", pp.get(3).getRuntimeType());
    assertEquals("string", pp.get(4).getRuntimeType());
    assertEquals("byte", pp.get(5).getRuntimeType());
    assertEquals("string[]", pp.get(6).getRuntimeType());
    assertEquals("boolean", pp.get(7).getRuntimeType());
    assertEquals("timestamp", pp.get(8).getRuntimeType());
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) Procedure(org.teiid.metadata.Procedure) Test(org.junit.Test)

Example 27 with ProcedureParameter

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

the class TestVisitors method exampleSalesforce.

public static QueryMetadataInterface exampleSalesforce() {
    try {
        ModelMetaData mmd = new ModelMetaData();
        mmd.setName("SalesforceModel");
        MetadataFactory mf = new MetadataFactory("sf", 1, SystemMetadata.getInstance().getRuntimeTypeMap(), mmd);
        mf.setParser(new QueryParser());
        // load the metadata as captured from 8.9 on 9/3/2014
        mf.parse(new FileReader(UnitTestUtil.getTestDataFile("sf.ddl")));
        SalesForceExecutionFactory factory = new SalesForceExecutionFactory();
        factory.start();
        for (FunctionMethod func : factory.getPushDownFunctions()) {
            mf.addFunction(func);
        }
        SalesForceMetadataProcessor.addProcedrues(mf);
        // Create Contacts group - which has different name in sources
        // $NON-NLS-1$
        Table contactTable = RealMetadataFactory.createPhysicalGroup("Contacts", mf.getSchema());
        // $NON-NLS-1$
        contactTable.setNameInSource("Contact");
        // $NON-NLS-1$
        contactTable.setProperty("Supports Query", Boolean.TRUE.toString());
        // Create Contact Columns
        String[] elemNames = new String[] { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "ContactID", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "Name", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "AccountId", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "InitialContact", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "LastTime" };
        String[] elemTypes = new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.TIMESTAMP, DataTypeManager.DefaultDataTypes.TIME };
        List<Column> contactCols = RealMetadataFactory.createElements(contactTable, elemNames, elemTypes);
        // Set name in source on each column
        String[] contactNameInSource = new String[] { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "id", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "ContactName", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "accountid", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "InitialContact", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "LastTime" };
        for (int i = 0; i < 2; i++) {
            Column obj = contactCols.get(i);
            obj.setNameInSource(contactNameInSource[i]);
        }
        // add a procedure with a native query property
        List<ProcedureParameter> params = new LinkedList<ProcedureParameter>();
        params.add(RealMetadataFactory.createParameter("x", SPParameter.IN, TypeFacility.RUNTIME_NAMES.STRING));
        Procedure nativeProc = RealMetadataFactory.createStoredProcedure("foo", mf.getSchema(), params);
        nativeProc.setProperty(SQLStringVisitor.TEIID_NATIVE_QUERY, "search;select accountname from account where accountid = $1");
        nativeProc.setResultSet(RealMetadataFactory.createResultSet("rs", new String[] { "accountname" }, new String[] { TypeFacility.RUNTIME_NAMES.STRING }));
        TransformationMetadata tm = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "x");
        ValidatorReport report = new MetadataValidator().validate(tm.getVdbMetaData(), tm.getMetadataStore());
        if (report.hasItems()) {
            throw new RuntimeException(report.getFailureMessage());
        }
        return tm;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Table(org.teiid.metadata.Table) SalesForceExecutionFactory(org.teiid.translator.salesforce.SalesForceExecutionFactory) LinkedList(java.util.LinkedList) ValidatorReport(org.teiid.query.validator.ValidatorReport) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) QueryParser(org.teiid.query.parser.QueryParser) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) Column(org.teiid.metadata.Column) FunctionMethod(org.teiid.metadata.FunctionMethod) Procedure(org.teiid.metadata.Procedure) FileReader(java.io.FileReader) MetadataValidator(org.teiid.query.metadata.MetadataValidator)

Example 28 with ProcedureParameter

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

the class S3ExecutionFactory method saveFile.

private void saveFile(MetadataFactory metadataFactory) {
    Procedure p = metadataFactory.addProcedure(SAVEFILE);
    // $NON-NLS-1$
    p.setAnnotation("Saves the given value to the given bucket.  Any existing file will be overriden.");
    // $NON-NLS-1$
    ProcedureParameter param = metadataFactory.addProcedureParameter("name", TypeFacility.RUNTIME_NAMES.STRING, Type.In, p);
    // $NON-NLS-1$
    param.setAnnotation("The name of the object to save");
    addCommonParameters(metadataFactory, p);
    // $NON-NLS-1$
    param = metadataFactory.addProcedureParameter("contents", TypeFacility.RUNTIME_NAMES.OBJECT, Type.In, p);
    // $NON-NLS-1$
    param.setAnnotation("The contents to save.  Can be one of CLOB, BLOB, or XML");
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) Procedure(org.teiid.metadata.Procedure)

Example 29 with ProcedureParameter

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

the class S3ExecutionFactory method listBucket.

private void listBucket(MetadataFactory metadataFactory) {
    Procedure p = metadataFactory.addProcedure(LISTBUCKET);
    // $NON-NLS-1$
    p.setAnnotation("Lists the Objects in a given bucket.");
    ProcedureParameter param;
    // $NON-NLS-1$
    param = metadataFactory.addProcedureParameter("bucket", TypeFacility.RUNTIME_NAMES.STRING, Type.In, p);
    // $NON-NLS-1$
    param.setAnnotation("The name of the bucket in Amazon S3");
    param.setNullType(NullType.Nullable);
    // $NON-NLS-1$
    param = metadataFactory.addProcedureParameter("region", TypeFacility.RUNTIME_NAMES.STRING, Type.In, p);
    // $NON-NLS-1$
    param.setAnnotation("region in which the bucket exists on Amazon S3");
    param.setNullType(NullType.Nullable);
    // $NON-NLS-1$
    param = metadataFactory.addProcedureParameter("accesskey", TypeFacility.RUNTIME_NAMES.STRING, Type.In, p);
    // $NON-NLS-1$
    param.setAnnotation("Security Access Key, if not provided will use translator configured keys.");
    param.setNullType(NullType.Nullable);
    // $NON-NLS-1$
    param = metadataFactory.addProcedureParameter("secretkey", TypeFacility.RUNTIME_NAMES.STRING, Type.In, p);
    // $NON-NLS-1$
    param.setAnnotation("Security Secret Key, if not provided will use translator configured keys.");
    param.setNullType(NullType.Nullable);
    param = // $NON-NLS-1$
    metadataFactory.addProcedureParameter(// $NON-NLS-1$
    "nexttoken", // $NON-NLS-1$
    TypeFacility.RUNTIME_NAMES.STRING, Type.In, p);
    param.setAnnotation("If the response is truncated, Amazon S3 returns this parameter with a " + "continuation token that you can specify as the continuation-token in your next request " + // $NON-NLS-1$
    "to retrieve the next set of keys");
    param.setNullType(NullType.Nullable);
    // $NON-NLS-1$
    metadataFactory.addProcedureResultSetColumn("result", TypeFacility.RUNTIME_NAMES.CLOB, p);
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) Procedure(org.teiid.metadata.Procedure)

Example 30 with ProcedureParameter

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

the class S3ExecutionFactory method addGetFileMethod.

private void addGetFileMethod(MetadataFactory metadataFactory) {
    Procedure p = metadataFactory.addProcedure(GETFILE);
    // $NON-NLS-1$
    p.setAnnotation("Returns file that match the given path as BLOB");
    // $NON-NLS-1$
    ProcedureParameter param = metadataFactory.addProcedureParameter("name", TypeFacility.RUNTIME_NAMES.STRING, Type.In, p);
    // $NON-NLS-1$
    param.setAnnotation("The name of the file to return.  Currently the patterns like *.<ext> are not supported");
    addCommonParameters(metadataFactory, p);
    // $NON-NLS-1$
    param = metadataFactory.addProcedureParameter("encryption", TypeFacility.RUNTIME_NAMES.STRING, Type.In, p);
    // $NON-NLS-1$
    param.setAnnotation("Server side encryption algorithm used");
    param.setNullType(NullType.Nullable);
    // $NON-NLS-1$
    param = metadataFactory.addProcedureParameter("encryptionkey", TypeFacility.RUNTIME_NAMES.STRING, Type.In, p);
    // $NON-NLS-1$
    param.setAnnotation("Server side encryption key to decrypt the object");
    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.addProcedureResultSetColumn("file", TypeFacility.RUNTIME_NAMES.BLOB, p);
    // $NON-NLS-1$
    metadataFactory.addProcedureResultSetColumn("endpoint", TypeFacility.RUNTIME_NAMES.STRING, p);
    // $NON-NLS-1$
    metadataFactory.addProcedureResultSetColumn("lastModified", TypeFacility.RUNTIME_NAMES.TIMESTAMP, p);
    // $NON-NLS-1$
    metadataFactory.addProcedureResultSetColumn("etag", TypeFacility.RUNTIME_NAMES.STRING, p);
    // $NON-NLS-1$
    metadataFactory.addProcedureResultSetColumn("size", TypeFacility.RUNTIME_NAMES.LONG, p);
}
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