Search in sources :

Example 51 with FakeDataManager

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

the class TestExpressionEvaluator method helpTestCommandPayload.

public void helpTestCommandPayload(Serializable payload, String property, String expectedValue) throws Exception {
    // $NON-NLS-1$
    Function func = new Function("commandpayload", new Expression[] {});
    Class[] parameterSignature = null;
    if (property == null) {
        parameterSignature = new Class[] {};
    } else {
        parameterSignature = new Class[] { String.class };
    }
    // $NON-NLS-1$
    FunctionDescriptor desc = RealMetadataFactory.SFM.getSystemFunctionLibrary().findFunction("commandpayload", parameterSignature);
    func.setFunctionDescriptor(desc);
    FakeDataManager dataMgr = new FakeDataManager();
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    CommandContext context = new CommandContext(null, "user", payload, "vdb", 1, false);
    if (property != null) {
        func.setArgs(new Expression[] { new Constant(property) });
    }
    String actual = (String) new Evaluator(Collections.emptyMap(), dataMgr, context).evaluate(func, Collections.emptyList());
    assertEquals(expectedValue, actual);
}
Also used : CommandContext(org.teiid.query.util.CommandContext) FakeDataManager(org.teiid.query.processor.FakeDataManager) FunctionDescriptor(org.teiid.query.function.FunctionDescriptor) Evaluator(org.teiid.query.eval.Evaluator)

Example 52 with FakeDataManager

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

the class TestExpressionEvaluator method testLookupFunction.

@Test
public void testLookupFunction() {
    // $NON-NLS-1$
    ElementSymbol e1 = new ElementSymbol("e1");
    e1.setType(String.class);
    // $NON-NLS-1$
    ElementSymbol e2 = new ElementSymbol("e2");
    e1.setType(Integer.class);
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    Function func = new Function("lookup", new Expression[] { new Constant("pm1.g1"), new Constant("e2"), new Constant("e1"), e1 });
    // $NON-NLS-1$
    FunctionDescriptor desc = RealMetadataFactory.SFM.getSystemFunctionLibrary().findFunction("lookup", new Class[] { String.class, String.class, String.class, String.class });
    func.setFunctionDescriptor(desc);
    Expression[] elements = new Expression[] { e1, e2 };
    Object[] values = new Object[] { // $NON-NLS-1$
    "xyz", // $NON-NLS-1$
    new Integer(5) };
    FakeDataManager dataMgr = new FakeDataManager();
    Map valueMap = new HashMap();
    // $NON-NLS-1$
    valueMap.put("xyz", new Integer(5));
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    dataMgr.defineCodeTable("pm1.g1", "e1", "e2", valueMap);
    helpTestEval(func, elements, values, dataMgr, null, new Integer(5));
}
Also used : FakeDataManager(org.teiid.query.processor.FakeDataManager) HashMap(java.util.HashMap) FunctionDescriptor(org.teiid.query.function.FunctionDescriptor) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 53 with FakeDataManager

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

the class TestAccessNode method testExecCount.

@Test
public void testExecCount() throws Exception {
    // Setup
    AccessNode node = new AccessNode(1);
    // $NON-NLS-1$
    Query query = (Query) TestResolver.helpResolve("SELECT e1, e2 FROM pm1.g1 WHERE e2 = 5", RealMetadataFactory.example1Cached());
    node.setCommand(query);
    CommandContext context = new CommandContext();
    BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
    FakeDataManager dataManager = new FakeDataManager();
    TestProcessor.sampleData1(dataManager);
    node.setElements(query.getProjectedSymbols());
    node.initialize(context, bm, dataManager);
    // Call open()
    node.open();
    // $NON-NLS-1$
    assertEquals(Arrays.asList("SELECT e1, e2 FROM pm1.g1 WHERE e2 = 5"), dataManager.getQueries());
}
Also used : Query(org.teiid.query.sql.lang.Query) CommandContext(org.teiid.query.util.CommandContext) FakeDataManager(org.teiid.query.processor.FakeDataManager) BufferManager(org.teiid.common.buffer.BufferManager) Test(org.junit.Test)

Example 54 with FakeDataManager

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

the class TestPreparedStatement method testLimitParam.

@Test
public void testLimitParam() throws Exception {
    // $NON-NLS-1$
    String preparedSql = "select e1 from pm1.g1 order by e1 desc limit ?";
    List<?> values = Arrays.asList(1);
    List<?>[] expected = new List<?>[] { // $NON-NLS-1$s
    Arrays.asList("c") };
    FakeDataManager dataManager = new FakeDataManager();
    TestProcessor.sampleData1(dataManager);
    helpTestProcessing(preparedSql, values, expected, dataManager, RealMetadataFactory.example1Cached(), false, false, RealMetadataFactory.example1VDB());
}
Also used : FakeDataManager(org.teiid.query.processor.FakeDataManager) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 55 with FakeDataManager

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

the class TestPreparedStatement method testExecParam.

@Test
public void testExecParam() throws Exception {
    // $NON-NLS-1$
    String preparedSql = "exec pm1.sq2(?)";
    // $NON-NLS-1$
    List<String> values = Arrays.asList("c");
    List<?>[] expected = new List<?>[] { Arrays.asList("c", 1) };
    FakeDataManager dataManager = new FakeDataManager();
    TestProcessor.sampleData1(dataManager);
    helpTestProcessing(preparedSql, values, expected, dataManager, RealMetadataFactory.example1Cached(), false, false, RealMetadataFactory.example1VDB());
}
Also used : FakeDataManager(org.teiid.query.processor.FakeDataManager) ArrayList(java.util.ArrayList) List(java.util.List) 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