Package org.teiid.query.processor

Source Code of org.teiid.query.processor.TestWithClauseProcessing

package org.teiid.query.processor;

import static org.teiid.query.processor.TestProcessor.*;

import java.util.Arrays;
import java.util.List;

import org.junit.Test;
import org.teiid.core.TeiidException;
import org.teiid.query.optimizer.TestOptimizer;
import org.teiid.query.optimizer.TestOptimizer.ComparisonMode;
import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
import org.teiid.query.unittest.FakeMetadataFactory;

@SuppressWarnings({"nls", "unchecked"})
public class TestWithClauseProcessing {
 
  @Test public void testSingleItem() {
      String sql = "with a (x, y, z) as (select e1, e2, e3 from pm1.g1) SELECT pm1.g2.e2, a.x from pm1.g2, a where e1 = x and z = 1 order by x"; //$NON-NLS-1$
     
      List[] expected = new List[] {
          Arrays.asList(0, "a"),
          Arrays.asList(3, "a"),
          Arrays.asList(0, "a"),
          Arrays.asList(1, "c"),
      };   
 
      FakeDataManager dataManager = new FakeDataManager();
      sampleData1(dataManager);
     
      ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
     
      helpProcess(plan, dataManager, expected);
  }
 
  @Test public void testMultipleItems() {
      String sql = "with a (x, y, z) as (select e1, e2, e3 from pm1.g1), b as (SELECT * from pm1.g2, a where e1 = x and z = 1 order by e2 limit 2) SELECT a.x, b.e1 from a, b where a.x = b.e1"; //$NON-NLS-1$
     
      List[] expected = new List[] {
          Arrays.asList("a", "a"),
          Arrays.asList("a", "a"),
          Arrays.asList("a", "a"),
          Arrays.asList("a", "a"),
          Arrays.asList("a", "a"),
          Arrays.asList("a", "a"),
      };   
 
      FakeDataManager dataManager = new FakeDataManager();
      sampleData1(dataManager);
     
      ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
     
      helpProcess(plan, dataManager, expected);
  }
 
  @Test public void testWithPushdown() throws TeiidException {
     FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
         BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
         caps.setCapabilitySupport(Capability.COMMON_TABLE_EXPRESSIONS, true);
         caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_SELFJOIN, true);
         capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
       
      String sql = "with a (x, y, z) as (select e1, e2, e3 from pm1.g1) SELECT a.x from a, a z"; //$NON-NLS-1$
     
      FakeDataManager dataManager = new FakeDataManager();
      sampleData1(dataManager);
     
      TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), null, capFinder, new String[] {"WITH a (x, y, z) AS (SELECT g_0.e1, g_0.e2, g_0.e3 FROM pm1.g1 AS g_0) SELECT g_0.x FROM a AS g_0, a AS g_1"}, ComparisonMode.EXACT_COMMAND_STRING);
  }

}
TOP

Related Classes of org.teiid.query.processor.TestWithClauseProcessing

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.