Search in sources :

Example 66 with Procedure

use of org.teiid.metadata.Procedure 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)

Example 67 with Procedure

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

the class S3ExecutionFactory method deleteFile.

private void deleteFile(MetadataFactory metadataFactory) {
    Procedure p = metadataFactory.addProcedure(DELETEFILE);
    // $NON-NLS-1$
    p.setAnnotation("Delete the given file from bucket.");
    // $NON-NLS-1$
    ProcedureParameter param = metadataFactory.addProcedureParameter("name", TypeFacility.RUNTIME_NAMES.STRING, Type.In, p);
    // $NON-NLS-1$
    param.setAnnotation("Name of the file");
    addCommonParameters(metadataFactory, p);
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) Procedure(org.teiid.metadata.Procedure)

Example 68 with Procedure

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

the class FileExecutionFactory method getMetadata.

@Override
public void getMetadata(MetadataFactory metadataFactory, Connection connection) throws TranslatorException {
    Procedure p = metadataFactory.addProcedure(GETTEXTFILES);
    // $NON-NLS-1$
    p.setAnnotation("Returns text files that match the given path and pattern as CLOBs");
    // $NON-NLS-1$
    ProcedureParameter param = metadataFactory.addProcedureParameter("pathAndPattern", TypeFacility.RUNTIME_NAMES.STRING, Type.In, p);
    // $NON-NLS-1$
    param.setAnnotation("The path and pattern of what files to return.  Currently the only pattern supported is *.<ext>, which returns only the files matching the given extension at the given path.");
    // $NON-NLS-1$
    metadataFactory.addProcedureResultSetColumn("file", TypeFacility.RUNTIME_NAMES.CLOB, p);
    // $NON-NLS-1$
    metadataFactory.addProcedureResultSetColumn("filePath", TypeFacility.RUNTIME_NAMES.STRING, p);
    // $NON-NLS-1$
    metadataFactory.addProcedureResultSetColumn("lastModified", TypeFacility.RUNTIME_NAMES.TIMESTAMP, p);
    // $NON-NLS-1$
    metadataFactory.addProcedureResultSetColumn("created", TypeFacility.RUNTIME_NAMES.TIMESTAMP, p);
    // $NON-NLS-1$
    metadataFactory.addProcedureResultSetColumn("size", TypeFacility.RUNTIME_NAMES.LONG, p);
    Procedure p1 = metadataFactory.addProcedure(GETFILES);
    // $NON-NLS-1$
    p1.setAnnotation("Returns files that match the given path and pattern as BLOBs");
    // $NON-NLS-1$
    param = metadataFactory.addProcedureParameter("pathAndPattern", TypeFacility.RUNTIME_NAMES.STRING, Type.In, p1);
    // $NON-NLS-1$
    param.setAnnotation("The path and pattern of what files to return.  Currently the only pattern supported is *.<ext>, which returns only the files matching the given extension at the given path.");
    // $NON-NLS-1$
    metadataFactory.addProcedureResultSetColumn("file", TypeFacility.RUNTIME_NAMES.BLOB, p1);
    // $NON-NLS-1$
    metadataFactory.addProcedureResultSetColumn("filePath", TypeFacility.RUNTIME_NAMES.STRING, p1);
    // $NON-NLS-1$
    metadataFactory.addProcedureResultSetColumn("lastModified", TypeFacility.RUNTIME_NAMES.TIMESTAMP, p1);
    // $NON-NLS-1$
    metadataFactory.addProcedureResultSetColumn("created", TypeFacility.RUNTIME_NAMES.TIMESTAMP, p1);
    // $NON-NLS-1$
    metadataFactory.addProcedureResultSetColumn("size", TypeFacility.RUNTIME_NAMES.LONG, p1);
    Procedure p2 = metadataFactory.addProcedure(SAVEFILE);
    // $NON-NLS-1$
    p2.setAnnotation("Saves the given value to the given path.  Any existing file will be overriden.");
    // $NON-NLS-1$
    metadataFactory.addProcedureParameter("filePath", TypeFacility.RUNTIME_NAMES.STRING, Type.In, p2);
    // $NON-NLS-1$
    param = metadataFactory.addProcedureParameter("file", TypeFacility.RUNTIME_NAMES.OBJECT, Type.In, p2);
    // $NON-NLS-1$
    param.setAnnotation("The contents to save.  Can be one of CLOB, BLOB, or XML");
    Procedure p3 = metadataFactory.addProcedure(DELETEFILE);
    // $NON-NLS-1$
    p3.setAnnotation("Delete the given file path. ");
    // $NON-NLS-1$
    metadataFactory.addProcedureParameter("filePath", TypeFacility.RUNTIME_NAMES.STRING, Type.In, p3);
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) Procedure(org.teiid.metadata.Procedure)

Example 69 with Procedure

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

the class TestFileExecutionFactory method testGetTextFiles.

@Test
public void testGetTextFiles() throws Exception {
    FileExecutionFactory fef = new FileExecutionFactory();
    MetadataFactory mf = new MetadataFactory("vdb", 1, "text", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
    fef.getMetadata(mf, null);
    Procedure p = mf.getSchema().getProcedure("getTextFiles");
    FileConnection fc = Mockito.mock(FileConnection.class);
    Mockito.stub(fc.getFile("*.txt")).toReturn(new File(UnitTestUtil.getTestDataPath(), "*.txt"));
    Call call = fef.getLanguageFactory().createCall("getTextFiles", Arrays.asList(new Argument(Direction.IN, new Literal("*.txt", TypeFacility.RUNTIME_TYPES.STRING), TypeFacility.RUNTIME_TYPES.STRING, null)), p);
    ProcedureExecution pe = fef.createProcedureExecution(call, null, null, fc);
    pe.execute();
    int count = 0;
    while (true) {
        List<?> val = pe.next();
        if (val == null) {
            break;
        }
        assertEquals(5, val.size());
        assertTrue(val.get(3) instanceof Timestamp);
        assertEquals(Long.valueOf(0), val.get(4));
        count++;
    }
    assertEquals(2, count);
    call = fef.getLanguageFactory().createCall("getTextFiles", Arrays.asList(new Argument(Direction.IN, new Literal("*1*", TypeFacility.RUNTIME_TYPES.STRING), TypeFacility.RUNTIME_TYPES.STRING, null)), p);
    pe = fef.createProcedureExecution(call, null, null, fc);
    Mockito.stub(fc.getFile("*1*")).toReturn(new File(UnitTestUtil.getTestDataPath(), "*1*"));
    pe.execute();
    count = 0;
    while (true) {
        if (pe.next() == null) {
            break;
        }
        count++;
    }
    assertEquals(1, count);
}
Also used : Call(org.teiid.language.Call) Argument(org.teiid.language.Argument) Properties(java.util.Properties) Timestamp(java.sql.Timestamp) MetadataFactory(org.teiid.metadata.MetadataFactory) ProcedureExecution(org.teiid.translator.ProcedureExecution) Literal(org.teiid.language.Literal) Procedure(org.teiid.metadata.Procedure) File(java.io.File) FileConnection(org.teiid.translator.FileConnection) Test(org.junit.Test)

Example 70 with Procedure

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

the class TestProcedureRelational method testParameterPassing.

/**
 *  test for defect 22376
 */
@Test
public void testParameterPassing() throws Exception {
    MetadataStore metadataStore = new MetadataStore();
    // $NON-NLS-1$
    Schema v1 = RealMetadataFactory.createVirtualModel("v1", metadataStore);
    // $NON-NLS-1$ //$NON-NLS-2$
    ColumnSet<Procedure> rs1 = RealMetadataFactory.createResultSet("v1.rs1", new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.STRING });
    // $NON-NLS-1$
    QueryNode n1 = new QueryNode("CREATE VIRTUAL PROCEDURE BEGIN declare string VARIABLES.x = '1'; SELECT e1 FROM v1.vp2 where v1.vp2.in = VARIABLES.x; END");
    // $NON-NLS-1$
    Procedure vt1 = RealMetadataFactory.createVirtualProcedure("vp1", v1, null, n1);
    vt1.setResultSet(rs1);
    // $NON-NLS-1$
    ProcedureParameter p1 = RealMetadataFactory.createParameter("in", ParameterInfo.IN, DataTypeManager.DefaultDataTypes.STRING);
    // $NON-NLS-1$
    QueryNode n2 = new QueryNode("CREATE VIRTUAL PROCEDURE BEGIN declare string VARIABLES.x; declare string VARIABLES.y; VARIABLES.x = '2'; VARIABLES.y = v1.vp2.in; select VARIABLES.y; end");
    // $NON-NLS-1$
    Procedure vt2 = RealMetadataFactory.createVirtualProcedure("vp2", v1, Arrays.asList(p1), n2);
    vt2.setResultSet(RealMetadataFactory.createResultSet("v1.rs1", new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.STRING }));
    // $NON-NLS-1$
    String sql = "select * from (exec v1.vp1()) foo";
    List<?>[] expected = new List[] { // $NON-NLS-1$
    Arrays.asList(new Object[] { "1" }) };
    QueryMetadataInterface metadata = RealMetadataFactory.createTransformationMetadata(metadataStore, "foo");
    // Construct data manager with data
    // Plan query
    ProcessorPlan plan = TestProcedureProcessor.getProcedurePlan(sql, metadata);
    // Run query
    TestProcedureProcessor.helpTestProcess(plan, expected, new FakeDataManager(), metadata);
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) ProcedureParameter(org.teiid.metadata.ProcedureParameter) QueryNode(org.teiid.query.mapping.relational.QueryNode) Schema(org.teiid.metadata.Schema) 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)

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