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());
}
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());
}
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));
}
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());
}
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;
}
Aggregations