Search in sources :

Example 31 with FakeDataManager

use of org.teiid.query.processor.FakeDataManager in project teiid by teiid.

the class TestProcedureProcessor method testDeclareWithQueryAssignment.

/**
 * Test the procedure <code>DECLARE</code> statement using a query as the assignment value
 *
 * <p>The use of a query as the assignment value to a <code>DECLARE</code>
 * statement should execute without error as long as the query
 * is valid and fully resolvable.</p>
 *
 * <p>This test is related to JBEDSP-818 in which the query in the
 * <code>LOOP</code> statement would fail due to a query being used as the
 * assigned value in the <code>DECLARE</code> statement.</p>
 * @throws Exception
 */
@Test
public void testDeclareWithQueryAssignment() throws Exception {
    // procedure comes from test case IT236455 / JBEDSP-818
    // $NON-NLS-1$
    String procedure = "CREATE VIRTUAL PROCEDURE \n";
    // $NON-NLS-1$
    procedure += "BEGIN\n";
    // $NON-NLS-1$
    procedure += "   DECLARE integer VARIABLES.var1 = 0;\n";
    // $NON-NLS-1$
    procedure += "   /* the following DECLARE with ASSIGNMENT to a query should work ";
    // $NON-NLS-1$
    procedure += "      but in IT236455 it results in the assignment inside the LOOP ";
    // $NON-NLS-1$
    procedure += "      to fail */ ";
    // $NON-NLS-1$
    procedure += "   DECLARE integer VARIABLES.NLEVELS = SELECT COUNT(*) FROM (\n";
    // $NON-NLS-1$
    procedure += "                                          SELECT 'Col1' AS ACol1, 'Col2' AS ACol2, convert(3, integer) AS ACol3\n";
    // $NON-NLS-1$
    procedure += "                                       ) AS Src;\n";
    // $NON-NLS-1$
    procedure += "   LOOP ON (\n";
    // $NON-NLS-1$
    procedure += "      SELECT StaticTable.BCol1, StaticTable.BCol2, StaticTable.BCol3 FROM (\n";
    // $NON-NLS-1$
    procedure += "         SELECT 'Col 1' AS BCol1, 'Col 2' AS BCol2, convert(3, integer) AS BCol3\n";
    // $NON-NLS-1$
    procedure += "      ) AS StaticTable\n";
    // $NON-NLS-1$
    procedure += "   ) AS L1\n";
    // $NON-NLS-1$
    procedure += "   BEGIN\n";
    // $NON-NLS-1$
    procedure += "      /* In IT236455 the following would fail as the results from ";
    // $NON-NLS-1$
    procedure += "         the LOOP (L1) are not in scope when the assignment is being ";
    // $NON-NLS-1$
    procedure += "         performed due to the query earlier being part of a DECLARE  ";
    // $NON-NLS-1$
    procedure += "         statement. */  ";
    // $NON-NLS-1$
    procedure += "      VARIABLES.var1 = L1.BCol3;\n";
    // $NON-NLS-1$
    procedure += "   END\n";
    // $NON-NLS-1$
    procedure += "   SELECT cast(VARIABLES.Var1 as string) AS e1;\n";
    // $NON-NLS-1$
    procedure += "END\n";
    QueryMetadataInterface metadata = createProcedureMetadata(procedure);
    // $NON-NLS-1$
    String userQuery = "SELECT e1 FROM (EXEC pm1.sq1()) as proc";
    FakeDataManager dataMgr = exampleDataManager(metadata);
    ProcessorPlan plan = getProcedurePlan(userQuery, metadata);
    List[] expected = new List[] { Arrays.asList("3") };
    helpTestProcess(plan, expected, dataMgr, metadata);
}
Also used : FakeDataManager(org.teiid.query.processor.FakeDataManager) 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 32 with FakeDataManager

use of org.teiid.query.processor.FakeDataManager in project teiid by teiid.

the class TestProcedureProcessor method testDynamicCommandWithVariable.

@Test
public void testDynamicCommandWithVariable() throws Exception {
    TransformationMetadata metadata = RealMetadataFactory.example1();
    addProc(metadata, "sq2", // $NON-NLS-1$ //$NON-NLS-2$
    "CREATE VIRTUAL PROCEDURE BEGIN\n" + "declare string VARIABLES.x; VARIABLES.x = pm1.sq2.in; execute string 'SELECT e1, e2 FROM pm1.g1 WHERE e1=VARIABLES.x'; END", new String[] { "e1", "e2" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER }, new String[] { "in" }, new String[] { DataTypeManager.DefaultDataTypes.STRING });
    // $NON-NLS-1$
    String userUpdateStr = "EXEC pm1.sq2('First')";
    FakeDataManager dataMgr = exampleDataManager(metadata);
    ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
    // Create expected results
    List[] expected = new List[] { // $NON-NLS-1$
    Arrays.asList(new Object[] { "First", Integer.valueOf(5) }) };
    helpTestProcess(plan, expected, dataMgr, metadata);
}
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)

Example 33 with FakeDataManager

use of org.teiid.query.processor.FakeDataManager in project teiid by teiid.

the class TestProcedureProcessor method exampleDataManager.

private FakeDataManager exampleDataManager(QueryMetadataInterface metadata) throws TeiidException {
    FakeDataManager dataMgr = new FakeDataManager();
    dataMgr.registerTuples(metadata, "pm1.g1", new List[] { // $NON-NLS-1$
    Arrays.asList(new Object[] { "First", Integer.valueOf(5), new Boolean(true), new Double(1.003) }), // $NON-NLS-1$
    Arrays.asList(new Object[] { "Second", Integer.valueOf(15), new Boolean(true), new Double(2.003) }), // $NON-NLS-1$
    Arrays.asList(new Object[] { "Third", Integer.valueOf(51), new Boolean(true), new Double(3.003) }) });
    dataMgr.registerTuples(metadata, "pm1.g2", new List[] { // $NON-NLS-1$
    Arrays.asList(new Object[] { "First", Integer.valueOf(5), new Boolean(true), new Double(1.003) }), // $NON-NLS-1$
    Arrays.asList(new Object[] { "Second", Integer.valueOf(15), new Boolean(true), new Double(2.003) }), // $NON-NLS-1$
    Arrays.asList(new Object[] { "Third", Integer.valueOf(51), new Boolean(true), new Double(3.003) }) });
    return dataMgr;
}
Also used : FakeDataManager(org.teiid.query.processor.FakeDataManager)

Example 34 with FakeDataManager

use of org.teiid.query.processor.FakeDataManager in project teiid by teiid.

the class TestProcedureProcessor method testDynamicCommandWithSingleSelect.

@Test
public void testDynamicCommandWithSingleSelect() throws Exception {
    TransformationMetadata metadata = RealMetadataFactory.example1();
    addProc(metadata, // $NON-NLS-1$ //$NON-NLS-2$
    "CREATE VIRTUAL PROCEDURE BEGIN\n" + "execute string 'SELECT 26'; END");
    // $NON-NLS-1$
    String userUpdateStr = "EXEC pm1.sq2()";
    FakeDataManager dataMgr = exampleDataManager(metadata);
    ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
    // Create expected results
    List[] expected = new List[] { // $NON-NLS-1$
    Arrays.asList(new Object[] { "26" }) };
    helpTestProcess(plan, expected, dataMgr, metadata);
}
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)

Example 35 with FakeDataManager

use of org.teiid.query.processor.FakeDataManager in project teiid by teiid.

the class TestProcedureProcessor method testSubqueryArguments.

@Test
public void testSubqueryArguments() {
    // $NON-NLS-1$
    String sql = "select * from (EXEC pm1.sq3b((select min(e1) from pm1.g1), (select max(e2) from pm1.g1))) as x";
    ProcessorPlan plan = helpGetPlan(sql, RealMetadataFactory.example1Cached());
    FakeDataManager fdm = new FakeDataManager();
    fdm.setBlockOnce();
    sampleData1(fdm);
    helpProcess(plan, fdm, new List[] { Arrays.asList("a", 0), Arrays.asList("a", 3), Arrays.asList("a", 0), Arrays.asList("a", 3) });
}
Also used : FakeDataManager(org.teiid.query.processor.FakeDataManager) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Test(org.junit.Test)

Aggregations

FakeDataManager (org.teiid.query.processor.FakeDataManager)112 Test (org.junit.Test)103 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)86 ArrayList (java.util.ArrayList)81 List (java.util.List)81 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)48 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)35 CommandContext (org.teiid.query.util.CommandContext)8 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)7 FunctionDescriptor (org.teiid.query.function.FunctionDescriptor)6 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 BufferManager (org.teiid.common.buffer.BufferManager)4 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)3 Constant (org.teiid.query.sql.symbol.Constant)3 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)3 Function (org.teiid.query.sql.symbol.Function)3 Evaluator (org.teiid.query.eval.Evaluator)2 TempMetadataStore (org.teiid.query.metadata.TempMetadataStore)2