Search in sources :

Example 86 with Command

use of org.teiid.query.sql.lang.Command in project teiid by teiid.

the class TestArrayProcessing method testMultiDimensionalGet.

@Test
public void testMultiDimensionalGet() throws Exception {
    // $NON-NLS-1$
    String sql = "select -((e2, e2), (e2, e2))[1][1] from pm1.g1";
    QueryResolver.resolveCommand(helpParse(sql), RealMetadataFactory.example1Cached());
    Command command = helpResolve(sql, RealMetadataFactory.example1Cached());
    assertEquals(DataTypeManager.DefaultDataClasses.INTEGER, command.getProjectedSymbols().get(0).getType());
}
Also used : Command(org.teiid.query.sql.lang.Command) Test(org.junit.Test)

Example 87 with Command

use of org.teiid.query.sql.lang.Command in project teiid by teiid.

the class TestArrayProcessing method testArrayGetTyping.

@Test
public void testArrayGetTyping() {
    // $NON-NLS-1$
    String sql = "select array_agg(e1)[1], array_agg(e2)[3] from pm1.g1";
    Command command = helpResolve(sql, RealMetadataFactory.example1Cached());
    assertEquals(DataTypeManager.DefaultDataClasses.STRING, command.getProjectedSymbols().get(0).getType());
    assertEquals(DataTypeManager.DefaultDataClasses.INTEGER, command.getProjectedSymbols().get(1).getType());
}
Also used : Command(org.teiid.query.sql.lang.Command) Test(org.junit.Test)

Example 88 with Command

use of org.teiid.query.sql.lang.Command in project teiid by teiid.

the class TestRulePushSelectCriteria method testPushAcrossFrameWithAccessNode.

@Test
public void testPushAcrossFrameWithAccessNode() throws Exception {
    QueryMetadataInterface metadata = new TempMetadataAdapter(RealMetadataFactory.example1Cached(), new TempMetadataStore());
    // $NON-NLS-1$
    Command command = TestOptimizer.helpGetCommand("select * from (select * from pm1.g1 union select * from pm1.g2) x where e1 = 1", metadata, null);
    // $NON-NLS-1$
    Command subCommand = TestOptimizer.helpGetCommand("select * from pm1.g1 union select * from pm1.g2", metadata, null);
    RelationalPlanner p = new RelationalPlanner();
    CommandContext cc = new CommandContext();
    p.initialize(command, null, metadata, null, null, cc);
    PlanNode root = p.generatePlan(command);
    PlanNode child = p.generatePlan(subCommand);
    PlanNode sourceNode = NodeEditor.findNodePreOrder(root, NodeConstants.Types.SOURCE);
    sourceNode.addFirstChild(child);
    sourceNode.setProperty(NodeConstants.Info.SYMBOL_MAP, SymbolMap.createSymbolMap(sourceNode.getGroups().iterator().next(), (List<Expression>) child.getFirstChild().getProperty(Info.PROJECT_COLS), metadata));
    // add a dummy access node
    PlanNode accessNode = NodeFactory.getNewNode(NodeConstants.Types.ACCESS);
    accessNode.addGroups(child.getFirstChild().getGroups());
    child.getFirstChild().addAsParent(accessNode);
    new RulePushSelectCriteria().execute(root, metadata, new DefaultCapabilitiesFinder(), new RuleStack(), AnalysisRecord.createNonRecordingRecord(), cc);
    // the select node should still be above the access node
    accessNode = NodeEditor.findNodePreOrder(root, NodeConstants.Types.ACCESS);
    assertEquals(NodeConstants.Types.SELECT, accessNode.getParent().getType());
    assertNull(NodeEditor.findNodePreOrder(accessNode, NodeConstants.Types.SELECT));
}
Also used : TempMetadataAdapter(org.teiid.query.metadata.TempMetadataAdapter) RelationalPlanner(org.teiid.query.optimizer.relational.RelationalPlanner) PlanNode(org.teiid.query.optimizer.relational.plantree.PlanNode) CommandContext(org.teiid.query.util.CommandContext) Command(org.teiid.query.sql.lang.Command) List(java.util.List) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) RuleStack(org.teiid.query.optimizer.relational.RuleStack) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) TempMetadataStore(org.teiid.query.metadata.TempMetadataStore) Test(org.junit.Test)

Example 89 with Command

use of org.teiid.query.sql.lang.Command in project teiid by teiid.

the class TestAliasGenerator method testStripAliases1.

@Test
public void testStripAliases1() throws Exception {
    // $NON-NLS-1$
    String sql = "select intkey as a, stringkey as b from BQT1.SmallA ORDER BY a, b";
    // $NON-NLS-1$
    String expected = "SELECT BQT1.SmallA.IntKey, BQT1.SmallA.StringKey FROM BQT1.SmallA ORDER BY BQT1.SmallA.IntKey, BQT1.SmallA.StringKey";
    Command command = helpTest(sql, expected, false, true, RealMetadataFactory.exampleBQTCached());
    LanguageBridgeFactory lbf = new LanguageBridgeFactory(RealMetadataFactory.exampleBQTCached());
    org.teiid.language.Command c = lbf.translate(command);
    assertEquals("SELECT SmallA.IntKey, SmallA.StringKey FROM SmallA ORDER BY SmallA.IntKey, SmallA.StringKey", c.toString());
}
Also used : Command(org.teiid.query.sql.lang.Command) LanguageBridgeFactory(org.teiid.dqp.internal.datamgr.LanguageBridgeFactory) Test(org.junit.Test)

Example 90 with Command

use of org.teiid.query.sql.lang.Command in project teiid by teiid.

the class TestAliasGenerator method helpTest.

private Command helpTest(String sql, String expected, QueryMetadataInterface metadata, AliasGenerator visitor) throws TeiidComponentException, TeiidProcessingException {
    Command command = TestResolver.helpResolve(sql, metadata);
    command = QueryRewriter.rewrite(command, metadata, null);
    command = (Command) command.clone();
    command.acceptVisitor(visitor);
    assertEquals(expected, command.toString());
    return command;
}
Also used : Command(org.teiid.query.sql.lang.Command)

Aggregations

Command (org.teiid.query.sql.lang.Command)232 Test (org.junit.Test)142 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)90 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)73 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)66 List (java.util.List)64 CommandContext (org.teiid.query.util.CommandContext)38 ArrayList (java.util.ArrayList)37 BatchedUpdateCommand (org.teiid.query.sql.lang.BatchedUpdateCommand)36 BigInteger (java.math.BigInteger)29 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)25 AnalysisRecord (org.teiid.query.analysis.AnalysisRecord)21 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)20 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)19 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)16 LinkedList (java.util.LinkedList)10 QueryParser (org.teiid.query.parser.QueryParser)10 RelationalPlan (org.teiid.query.processor.relational.RelationalPlan)10 QueryCommand (org.teiid.query.sql.lang.QueryCommand)10 StoredProcedure (org.teiid.query.sql.lang.StoredProcedure)10