Search in sources :

Example 1 with QueryMetadataInterface

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

the class TestPreparedStatement method testFunctionWithReferencePushDown.

@Test
public void testFunctionWithReferencePushDown() throws Exception {
    // Create query
    // $NON-NLS-1$
    String preparedSql = "SELECT pm1.g1.e1 FROM pm1.g1, pm1.g2 WHERE pm1.g1.e1 = pm1.g2.e1 and pm1.g1.e2+2=?";
    // Create plan
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = new BasicSourceCapabilities();
    caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
    caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_ORDERED, true);
    caps.setCapabilitySupport(Capability.CRITERIA_NOT, true);
    caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
    caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
    caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, true);
    caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER_FULL, true);
    caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
    caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
    caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
    // $NON-NLS-1$
    caps.setFunctionSupport("+", false);
    // $NON-NLS-1$
    caps.setFunctionSupport("convert", true);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm1", caps);
    QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
    List<?> values = Arrays.asList(0);
    PreparedStatementRequest plan = helpGetProcessorPlan(preparedSql, values, capFinder, metadata, new SessionAwareCache<PreparedPlan>("preparedplan", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.PREPAREDPLAN, 0), SESSION_ID, false, false, RealMetadataFactory.example1VDB());
    TestOptimizer.checkNodeTypes(plan.processPlan, TestOptimizer.FULL_PUSHDOWN);
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 2 with QueryMetadataInterface

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

the class TestPreparedStatement method testInherentlyUpdatableViewCompensation.

@Test
public void testInherentlyUpdatableViewCompensation() throws Exception {
    // $NON-NLS-1$
    String preparedSql = "SELECT pm1.g1.e1 FROM pm1.g1 WHERE pm1.g1.e2 IN /*+ no_unnest */ (SELECT pm1.g2.e2 FROM pm1.g2 WHERE pm1.g2.e1 = ?)";
    List<?>[] expected = new List<?>[] { Arrays.asList("a") };
    // $NON-NLS-1$
    List<?> values = Arrays.asList("a");
    QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
    HardcodedDataManager dataManager = new HardcodedDataManager(metadata);
    dataManager.addData("SELECT g_0.e1 FROM g1 AS g_0 WHERE g_0.e2 IN (SELECT g_1.e2 FROM g2 AS g_1 WHERE g_1.e1 = 'a')", new List<?>[] { Arrays.asList("a") });
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
    caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
    helpTestProcessing(preparedSql, values, expected, dataManager, new DefaultCapabilitiesFinder(caps), metadata, null, false, false, false, RealMetadataFactory.example1VDB());
}
Also used : HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) ArrayList(java.util.ArrayList) List(java.util.List) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 3 with QueryMetadataInterface

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

the class TestPreparedStatement method testWithSubqueryPushdown.

@Test
public void testWithSubqueryPushdown() throws Exception {
    // $NON-NLS-1$
    String preparedSql = "SELECT pm1.g1.e1 FROM pm1.g1 WHERE pm1.g1.e2 IN /*+ no_unnest */ (SELECT pm1.g2.e2 FROM pm1.g2 WHERE pm1.g2.e1 = ?)";
    List<?>[] expected = new List<?>[] { Arrays.asList("a") };
    // $NON-NLS-1$
    List<?> values = Arrays.asList("a");
    QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
    HardcodedDataManager dataManager = new HardcodedDataManager(metadata);
    dataManager.addData("SELECT g_0.e1 FROM g1 AS g_0 WHERE g_0.e2 IN (SELECT g_1.e2 FROM g2 AS g_1 WHERE g_1.e1 = 'a')", new List<?>[] { Arrays.asList("a") });
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
    caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
    helpTestProcessing(preparedSql, values, expected, dataManager, new DefaultCapabilitiesFinder(caps), metadata, null, false, false, false, RealMetadataFactory.example1VDB());
}
Also used : HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) ArrayList(java.util.ArrayList) List(java.util.List) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 4 with QueryMetadataInterface

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

the class TestPreparedStatementBatchedUpdate method testBatchedMerge.

@Test
public void testBatchedMerge() throws Exception {
    String ddl = "CREATE foreign table x (y string primary key, z integer) options (updatable true)";
    QueryMetadataInterface metadata = RealMetadataFactory.fromDDL(ddl, "x", "phy");
    // Create query
    // $NON-NLS-1$
    String preparedSql = "merge into x (y, z) values (?, ?)";
    // Create a testable prepared plan cache
    SessionAwareCache<PreparedPlan> prepPlanCache = new SessionAwareCache<PreparedPlan>("preparedplan", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.PREPAREDPLAN, 0);
    // Construct data manager with data
    HardcodedDataManager dataManager = new HardcodedDataManager();
    // $NON-NLS-1$
    dataManager.addData("SELECT 1 FROM phy.x AS g_0 WHERE g_0.y = 'a'", new List[] { Arrays.asList(1) });
    // $NON-NLS-1$
    dataManager.addData("UPDATE x SET z = 0 WHERE y = 'a'", new List[] { Arrays.asList(1) });
    // $NON-NLS-1$
    dataManager.addData("INSERT INTO x (y, z) VALUES (null, 1)", new List[] { Arrays.asList(1) });
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    // $NON-NLS-1$
    capFinder.addCapabilities("phy", caps);
    // batch with two commands
    ArrayList<ArrayList<Object>> values = new ArrayList<ArrayList<Object>>(2);
    // $NON-NLS-1$
    values.add(new ArrayList<Object>(Arrays.asList(new Object[] { "a", new Integer(0) })));
    values.add(new ArrayList<Object>(Arrays.asList(new Object[] { null, new Integer(1) })));
    List<?>[] expected = new List[] { Arrays.asList(1), Arrays.asList(1) };
    // Create the plan and process the query
    TestPreparedStatement.helpTestProcessing(preparedSql, values, expected, dataManager, capFinder, metadata, prepPlanCache, false, false, false, RealMetadataFactory.example1VDB());
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 5 with QueryMetadataInterface

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

the class TestRequest method testProcessRequestPreparedStatement.

/**
 * Test PreparedStatementRequest.processRequest().
 * Test processing the same query twice, and make sure that doesn't cause problems.
 * @throws Exception
 * @since 4.2
 */
@Test
public void testProcessRequestPreparedStatement() throws Exception {
    QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
    SessionAwareCache<PreparedPlan> cache = new SessionAwareCache<PreparedPlan>("preparedplan", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.PREPAREDPLAN, 0);
    // Try before plan is cached.
    // If this doesn't throw an exception, assume it was successful.
    RequestMessage message = new RequestMessage(QUERY);
    DQPWorkContext workContext = RealMetadataFactory.buildWorkContext(metadata, RealMetadataFactory.example1VDB());
    message.setStatementType(StatementType.PREPARED);
    message.setParameterValues(new ArrayList<Object>());
    helpProcessMessage(message, cache, workContext);
    // Try again, now that plan is already cached.
    // If this doesn't throw an exception, assume it was successful.
    message = new RequestMessage(QUERY);
    message.setStatementType(StatementType.PREPARED);
    message.setParameterValues(new ArrayList<Object>());
    helpProcessMessage(message, cache, workContext);
}
Also used : RequestMessage(org.teiid.client.RequestMessage) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Aggregations

QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)507 Test (org.junit.Test)464 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)210 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)189 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)177 List (java.util.List)126 Command (org.teiid.query.sql.lang.Command)90 ArrayList (java.util.ArrayList)72 FakeDataManager (org.teiid.query.processor.FakeDataManager)48 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)43 BigInteger (java.math.BigInteger)41 CommandContext (org.teiid.query.util.CommandContext)37 HardcodedDataManager (org.teiid.query.processor.HardcodedDataManager)29 AnalysisRecord (org.teiid.query.analysis.AnalysisRecord)16 MetadataStore (org.teiid.metadata.MetadataStore)12 Schema (org.teiid.metadata.Schema)11 BatchedUpdateCommand (org.teiid.query.sql.lang.BatchedUpdateCommand)11 TeiidException (org.teiid.core.TeiidException)10 TeiidProcessingException (org.teiid.core.TeiidProcessingException)10 CapabilitiesFinder (org.teiid.query.optimizer.capabilities.CapabilitiesFinder)10