private Command helpTest(String sql, String expected, boolean aliasGroups, boolean stripColumnAliases, QueryMetadataInterface metadata) throws TeiidComponentException, TeiidProcessingException { AliasGenerator visitor = new AliasGenerator(aliasGroups, stripColumnAliases); return helpTest(sql, expected, metadata, visitor); }
/** * For backwards compatibility we strip the alias from delete/update * @param command * @param group */ private void removeAlias(ProcedureContainer command, GroupSymbol group) { AliasGenerator ag = new AliasGenerator(true); ag.setCorrelationGroups(Arrays.asList(group.getDefinition())); command.acceptVisitor(ag); final GroupSymbol clone = group.clone(); DeepPostOrderNavigator.doVisit(command, new LanguageVisitor() { public void visit(GroupSymbol obj) { if (obj.equals(clone) && obj.getMetadataID() == group.getMetadataID()) { obj.setName(obj.getDefinition()); obj.setDefinition(null); } } }); }
/** * For backwards compatibility we strip the alias from delete/update * @param command * @param group */ private void removeAlias(ProcedureContainer command, GroupSymbol group) { AliasGenerator ag = new AliasGenerator(true); ag.setCorrelationGroups(Arrays.asList(group.getDefinition())); command.acceptVisitor(ag); final GroupSymbol clone = group.clone(); DeepPostOrderNavigator.doVisit(command, new LanguageVisitor() { public void visit(GroupSymbol obj) { if (obj.equals(clone) && obj.getMetadataID() == group.getMetadataID()) { obj.setName(obj.getDefinition()); obj.setDefinition(null); } } }); }
/** * For backwards compatibility we strip the alias from delete/update * @param command * @param group */ private void removeAlias(ProcedureContainer command, GroupSymbol group) { AliasGenerator ag = new AliasGenerator(true); ag.setCorrelationGroups(Arrays.asList(group.getDefinition())); command.acceptVisitor(ag); final GroupSymbol clone = group.clone(); DeepPostOrderNavigator.doVisit(command, new LanguageVisitor() { public void visit(GroupSymbol obj) { if (obj.equals(clone) && obj.getMetadataID() == group.getMetadataID()) { obj.setName(obj.getDefinition()); obj.setDefinition(null); } } }); }
@Test public void testKeepAliases() throws Exception { String sql = "select g.intkey as a, g.stringkey as b from BQT1.SmallA g, BQT1.SmallB ORDER BY a, b"; //$NON-NLS-1$ String expected = "SELECT g.IntKey AS c_0, g.StringKey AS c_1 FROM BQT1.SmallA AS g, BQT1.SmallB AS g_1 ORDER BY c_0, c_1"; //$NON-NLS-1$ AliasGenerator av = new AliasGenerator(true, false); Map<String, String> aliasMap = new HashMap<String, String>(); aliasMap.put("g", "g"); av.setAliasMapping(aliasMap); helpTest(sql, expected, RealMetadataFactory.exampleBQTCached(), av); }
@Test(expected=TeiidRuntimeException.class) public void testKeepAliases1() throws Exception { String sql = "select g_1.intkey as a, g_1.stringkey as b from BQT1.SmallA g_1, BQT1.SmallB ORDER BY a, b"; //$NON-NLS-1$ String expected = "SELECT g.IntKey AS c_0, g.StringKey AS c_1 FROM BQT1.SmallA AS g ORDER BY c_0, c_1"; //$NON-NLS-1$ AliasGenerator av = new AliasGenerator(true, false); Map<String, String> aliasMap = new HashMap<String, String>(); aliasMap.put("g_1", "g_1"); av.setAliasMapping(aliasMap); helpTest(sql, expected, RealMetadataFactory.exampleBQTCached(), av); }
@Test public void testNestedCommonTables() throws Exception { String sql = "WITH CTE0 (e1, e2) AS /*+ no_inline */ (SELECT e1, e2 FROM pm1.g2) SELECT g_0.e1, g_0.e2 FROM CTE0 AS g_0 WHERE g_0.e1 = (WITH CTE1 (e1) AS /*+ no_inline */ (SELECT g_0.e1 FROM pm1.g1 AS g_1) SELECT g_2.e1 FROM CTE1 AS g_2)"; String expected = "WITH CTE0 (e1, e2) AS /*+ no_inline */ (SELECT g_0.e1, g_0.e2 FROM pm1.g2 AS g_0) SELECT g_1.e1, g_1.e2 FROM CTE0 AS g_1 WHERE g_1.e1 = (WITH CTE1 (e1) AS /*+ no_inline */ (SELECT g_1.e1 FROM pm1.g1 AS g_2) SELECT g_3.e1 AS c_0 FROM CTE1 AS g_3 LIMIT 2)"; //$NON-NLS-1$ AliasGenerator av = new AliasGenerator(true, false); helpTest(sql, expected, RealMetadataFactory.example1Cached(), av); }
public static void checkAtomicQueries(String[] expectedAtomic, ProcessorPlan plan, QueryMetadataInterface md, CapabilitiesFinder capFinder) { Set<String> actualQueries = getAtomicQueries(plan); HashSet<String> expectedQueries = new HashSet<String>(); // Compare atomic queries for (int i = 0; i < expectedAtomic.length; i++) { final String sql = expectedAtomic[i]; Command command; try { command = helpGetCommand(sql, md); Collection<GroupSymbol> groups = GroupCollectorVisitor.getGroupsIgnoreInlineViews(command, false); final GroupSymbol symbol = groups.iterator().next(); Object modelId = md.getModelID(symbol.getMetadataID()); boolean supportsGroupAliases = CapabilitiesUtil.supportsGroupAliases(modelId, md, capFinder); boolean supportsProjection = CapabilitiesUtil.supports(Capability.QUERY_SELECT_EXPRESSION, modelId, md, capFinder); command.acceptVisitor(new AliasGenerator(supportsGroupAliases, !supportsProjection)); expectedQueries.add(command.toString()); } catch (Exception err) { throw new RuntimeException(err); } } assertEquals("Did not get expected atomic queries: ", expectedQueries, actualQueries); //$NON-NLS-1$ }
boolean aliasColumns = modelID != null && (CapabilitiesUtil.supports(Capability.QUERY_SELECT_EXPRESSION, modelID, metadata, capFinder) || CapabilitiesUtil.supports(Capability.QUERY_FROM_INLINE_VIEWS, modelID, metadata, capFinder)); AliasGenerator visitor = new AliasGenerator(aliasGroups, !aliasColumns); SourceHint sh = command.getSourceHint(); if (sh != null && aliasGroups) {
boolean aliasColumns = modelID != null && (CapabilitiesUtil.supports(Capability.QUERY_SELECT_EXPRESSION, modelID, metadata, capFinder) || CapabilitiesUtil.supports(Capability.QUERY_FROM_INLINE_VIEWS, modelID, metadata, capFinder)); AliasGenerator visitor = new AliasGenerator(aliasGroups, !aliasColumns); SourceHint sh = command.getSourceHint(); if (sh != null && aliasGroups) {
boolean aliasColumns = modelID != null && (CapabilitiesUtil.supports(Capability.QUERY_SELECT_EXPRESSION, modelID, metadata, capFinder) || CapabilitiesUtil.supports(Capability.QUERY_FROM_INLINE_VIEWS, modelID, metadata, capFinder)); AliasGenerator visitor = new AliasGenerator(aliasGroups, !aliasColumns); SourceHint sh = command.getSourceHint(); if (sh != null && aliasGroups) {
@Test public void testNestedViewAliasing() throws Exception { String sql = "select e1, e2 from (select y.e1, y.e2 from (select pm1.g1.e1, 1 as e2 from pm1.g1) y) z"; //$NON-NLS-1$ Query command = (Query)QueryParser.getQueryParser().parseCommand(sql); QueryResolver.resolveCommand(command, RealMetadataFactory.example1Cached()); command = (Query) command.clone(); command.acceptVisitor(new AliasGenerator(true)); assertEquals("SELECT v_1.c_0, v_1.c_1 FROM (SELECT v_0.c_0, v_0.c_1 FROM (SELECT g_0.e1 AS c_0, 1 AS c_1 FROM pm1.g1 AS g_0) AS v_0) AS v_1", command.toString()); //$NON-NLS-1$ }
/** * Ensures that views are named with v_ even without metadata */ @Test public void testViewAliasing() throws Exception { String sql = "select y.e1 from (select pm1.g1.e1 from pm1.g1) y"; //$NON-NLS-1$ Query command = (Query)QueryParser.getQueryParser().parseCommand(sql); ((ElementSymbol)command.getSelect().getSymbol(0)).setGroupSymbol(new GroupSymbol("y")); //$NON-NLS-1$ command.acceptVisitor(new AliasGenerator(true)); assertEquals("SELECT v_0.c_0 FROM (SELECT g_0.e1 AS c_0 FROM pm1.g1 AS g_0) AS v_0", command.toString()); //$NON-NLS-1$ }
if (generateAliases) { command = (Command)command.clone(); command.acceptVisitor(new AliasGenerator(supportsGroupAlias));