Search in sources :

Example 86 with TransformationMetadata

use of org.teiid.query.metadata.TransformationMetadata in project teiid by teiid.

the class TestProcedureProcessor method testDynamicClob.

@Test
public void testDynamicClob() throws Exception {
    // $NON-NLS-1$
    String sql = "exec p1()";
    TransformationMetadata tm = RealMetadataFactory.fromDDL("create virtual procedure p1() as " + "begin create local temporary table t (x string); execute immediate cast('select * from t' as clob); end;", "x", "y");
    ProcessorPlan plan = getProcedurePlan(sql, tm);
    HardcodedDataManager dataManager = new HardcodedDataManager(tm);
    // $NON-NLS-1$
    List[] expected = new List[] {};
    helpTestProcess(plan, expected, dataManager, tm);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) List(java.util.List) ArrayList(java.util.ArrayList) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Test(org.junit.Test)

Example 87 with TransformationMetadata

use of org.teiid.query.metadata.TransformationMetadata in project teiid by teiid.

the class TestProcedureProcessor method testEvaluatableLimit1.

// should fail as the param type is incorrect
@Test(expected = QueryPlannerException.class)
public void testEvaluatableLimit1() throws Exception {
    TransformationMetadata metadata = RealMetadataFactory.example1();
    StringBuffer procedure = // $NON-NLS-1$
    new StringBuffer("CREATE VIRTUAL PROCEDURE \n").append(// $NON-NLS-1$
    "BEGIN\n").append(// $NON-NLS-1$
    "SELECT e1 from pm1.g1 limit param;\n").append(// $NON-NLS-1$
    "END");
    addProc(metadata, "sq1", procedure.toString(), new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.STRING }, new String[] { "param" }, new String[] { DataTypeManager.DefaultDataTypes.STRING });
    // $NON-NLS-1$
    String userUpdateStr = "EXEC pm1.sq1(1)";
    getProcedurePlan(userUpdateStr, metadata);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Test(org.junit.Test)

Example 88 with TransformationMetadata

use of org.teiid.query.metadata.TransformationMetadata in project teiid by teiid.

the class TestProcedureProcessor method createProcedureMetadata.

private QueryMetadataInterface createProcedureMetadata(String procedure) {
    TransformationMetadata metadata = RealMetadataFactory.example1();
    addProc(metadata, "sq1", procedure, new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.STRING }, new String[0], new String[0]);
    return metadata;
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata)

Example 89 with TransformationMetadata

use of org.teiid.query.metadata.TransformationMetadata in project teiid by teiid.

the class TestProcedureProcessor method testVarArgs.

@Test
public void testVarArgs() throws Exception {
    String ddl = "create foreign procedure proc (x integer, VARIADIC z integer); create virtual procedure vproc (x integer, VARIADIC z integer) returns integer as begin \"return\" = z[2] + array_length(z); call proc(x, z); end;";
    TransformationMetadata tm = TestProcedureResolving.createMetadata(ddl);
    // $NON-NLS-1$
    String sql = "call vproc(1, 2, 3)";
    ProcessorPlan plan = getProcedurePlan(sql, tm);
    HardcodedDataManager dataManager = new HardcodedDataManager(tm);
    dataManager.addData("EXEC proc(1, 2, 3)", new List<?>[0]);
    // Create expected results
    // $NON-NLS-1$
    List[] expected = new List[] { Arrays.asList(5) };
    helpTestProcess(plan, expected, dataManager, tm);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) List(java.util.List) ArrayList(java.util.ArrayList) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Test(org.junit.Test)

Example 90 with TransformationMetadata

use of org.teiid.query.metadata.TransformationMetadata in project teiid by teiid.

the class TestProcedureProcessor method testRemovalOfNonJoinCritWithReference.

/**
 * Test the use of a procedure variable in the criteria of a LEFT OUTER
 * JOIN which will be optimized out as non-JOIN criteria.
 * <p>
 * This test case verifies that the procedure variable will not be pushed
 * to the data manager when a federated source JOIN is performed.
 *
 * @throws Exception
 */
@Test
public void testRemovalOfNonJoinCritWithReference() throws Exception {
    // $NON-NLS-1$
    String proc = "";
    // $NON-NLS-1$
    String sql = "";
    sql += // $NON-NLS-1$
    "SELECT " + // $NON-NLS-1$
    "	pm1.g1.e1 AS pm1g1e1, " + // $NON-NLS-1$
    "	pm2.g2.e1 AS pm2g2e1, " + // $NON-NLS-1$
    "	pm1.g1.e2 AS pm1g1e2, " + // $NON-NLS-1$
    "	pm2.g2.e2 AS pm2g2e2 " + // $NON-NLS-1$
    "FROM " + // $NON-NLS-1$
    "	pm1.g1	" + // $NON-NLS-1$
    "LEFT OUTER JOIN pm2.g2 " + // $NON-NLS-1$
    "	ON pm1.g1.e1 = pm2.g2.e1 " + // $NON-NLS-1$
    "	AND pm2.g2.e2 = VARIABLES.myVar ";
    proc += // $NON-NLS-1$
    "CREATE VIRTUAL PROCEDURE " + // $NON-NLS-1$
    "BEGIN " + // $NON-NLS-1$
    "   declare integer myVar = 5;" + "   " + sql + // $NON-NLS-1$ //$NON-NLS-2$
    ";" + // $NON-NLS-1$
    "END";
    TransformationMetadata metadata = RealMetadataFactory.example1();
    addProc(metadata, "sq1", proc, new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.INTEGER }, new String[0], new String[0]);
    // $NON-NLS-1$
    String userQuery = "SELECT * FROM (EXEC pm1.sq1()) as proc";
    FakeDataManager dataMgr = exampleDataManager2(metadata);
    ProcessorPlan plan = getProcedurePlan(userQuery, metadata);
    List[] expected = new List[] { // $NON-NLS-1$ //$NON-NLS-2$
    Arrays.asList(new Object[] { "First", "First", Integer.valueOf(5), Integer.valueOf(5) }), // $NON-NLS-1$
    Arrays.asList(new Object[] { "Second", null, Integer.valueOf(15), null }), // $NON-NLS-1$
    Arrays.asList(new Object[] { "Third", null, Integer.valueOf(51), null }) };
    helpTestProcess(plan, expected, dataMgr, metadata);
    assertTrue(!plan.requiresTransaction(false));
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) FakeDataManager(org.teiid.query.processor.FakeDataManager) List(java.util.List) ArrayList(java.util.ArrayList) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Test(org.junit.Test)

Aggregations

TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)427 Test (org.junit.Test)352 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)163 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)108 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)97 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)89 List (java.util.List)83 CommandContext (org.teiid.query.util.CommandContext)64 HardcodedDataManager (org.teiid.query.processor.HardcodedDataManager)63 ArrayList (java.util.ArrayList)56 TranslationUtility (org.teiid.cdk.api.TranslationUtility)35 MetadataFactory (org.teiid.metadata.MetadataFactory)35 FakeDataManager (org.teiid.query.processor.FakeDataManager)35 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)35 Schema (org.teiid.metadata.Schema)33 Table (org.teiid.metadata.Table)27 FunctionTree (org.teiid.query.function.FunctionTree)22 Column (org.teiid.metadata.Column)21 Command (org.teiid.language.Command)20 UDFSource (org.teiid.query.function.UDFSource)20