public static MetadataFactory helpParse(String ddl, String model) { MetadataFactory mf = new MetadataFactory("x", 1, model, getDataTypes(), new Properties(), null); QueryParser.getQueryParser().parseDDL(mf, ddl); return mf; }
private static Command helpGetCommand(String sql, QueryMetadataInterface metadata) throws Exception { Command command = QueryParser.getQueryParser().parseCommand(sql); QueryResolver.resolveCommand(command, metadata); return command; }
static Command helpResolve(String sql, QueryMetadataInterface metadata) { Command command = null; try { command = QueryParser.getQueryParser().parseCommand(sql); QueryResolver.resolveCommand(command, metadata); } catch(Exception e) { throw new TeiidRuntimeException(e); } return command; }
@Test public void testSourceHint() throws QueryParserException { String sql = "SELECT /*+ sh:'foo' oracle:'leading' */ a FROM x limit 1"; //$NON-NLS-1$ assertEquals("SELECT /*+sh:'foo' oracle:'leading' */ a FROM x LIMIT 1", QueryParser.getQueryParser().parseCommand(sql, ParseInfo.DEFAULT_INSTANCE).toString()); //$NON-NLS-1$ sql = "(SELECT /*+ sh:'foo' oracle:'leading' */ a FROM x limit 1) union all select 1"; //$NON-NLS-1$ assertEquals("(SELECT /*+sh:'foo' oracle:'leading' */ a FROM x LIMIT 1) UNION ALL SELECT 1", QueryParser.getQueryParser().parseCommand(sql, ParseInfo.DEFAULT_INSTANCE).toString()); sql = "(SELECT /*+ sh keep aliases:'foo' oracle keep aliases:'leading' */ a FROM x limit 1) union all select 1"; //$NON-NLS-1$ assertEquals("(SELECT /*+sh KEEP ALIASES:'foo' oracle KEEP ALIASES:'leading' */ a FROM x LIMIT 1) UNION ALL SELECT 1", QueryParser.getQueryParser().parseCommand(sql, ParseInfo.DEFAULT_INSTANCE).toString()); sql = "(SELECT /*+ sh keep aliases oracle:'leading' */ a FROM x limit 1) union all select 1"; //$NON-NLS-1$ assertEquals("(SELECT /*+sh KEEP ALIASES oracle:'leading' */ a FROM x LIMIT 1) UNION ALL SELECT 1", QueryParser.getQueryParser().parseCommand(sql, ParseInfo.DEFAULT_INSTANCE).toString()); }
@Test public void testScalarSubqueryFails() throws Exception{ ScalarSubquery expr = new ScalarSubquery((QueryCommand) QueryParser.getQueryParser().parseCommand("select x from y")); ArrayList values = new ArrayList(2); values.add("a"); //$NON-NLS-1$ values.add("b"); //$NON-NLS-1$ try { helpTestWithValueIterator(expr, values, null); fail("Expected ExpressionEvaluationException but got none"); //$NON-NLS-1$ } catch (ExpressionEvaluationException e) { assertEquals("TEIID30328 Unable to evaluate (SELECT x FROM y): TEIID30345 The command of this scalar subquery returned more than one value: SELECT x FROM y", e.getMessage()); //$NON-NLS-1$ } }
@Test public void testConsecutivePeriod() throws QueryParserException { String sql = "SELECT * from \"t..able\""; //by our current naming rules this is the same - but as we don't allow . in the schema name it is not correct. assertEquals("SELECT * FROM \"t.\".able", QueryParser.getQueryParser().parseCommand(sql, ParseInfo.DEFAULT_INSTANCE).toString()); //ensures a stable parsing assertEquals("SELECT * FROM \"t.\".able", QueryParser.getQueryParser().parseCommand("SELECT * FROM \"t.\".able", ParseInfo.DEFAULT_INSTANCE).toString()); }
private static Criteria helpGetCriteria(String critString, QueryMetadataInterface metadata) throws QueryMetadataException, TeiidComponentException, TeiidProcessingException{ Criteria result = QueryParser.getQueryParser().parseCriteria(critString); QueryResolver.resolveCriteria(result, metadata); result = QueryRewriter.rewriteCriteria(result, new CommandContext(), metadata); return result; }
private void helpTestNullDependent(String expressionSQL, boolean dependent) throws QueryParserException, QueryResolverException, QueryMetadataException, TeiidComponentException { List<GroupSymbol> innerGroups = new ArrayList<GroupSymbol>(); innerGroups.add(new GroupSymbol("pm1.g1")); //$NON-NLS-1$ Expression expr = QueryParser.getQueryParser().parseExpression(expressionSQL); ResolverVisitor.resolveLanguageObject(expr, RealMetadataFactory.example1Cached()); assertEquals(dependent, JoinUtil.isNullDependent(RealMetadataFactory.example1Cached(), innerGroups, expr)); }
private ValidatorReport helpValidateInModeler(String procName, String procSql, QueryMetadataInterface metadata) throws Exception { Command command = QueryParser.getQueryParser().parseCommand(procSql); GroupSymbol group = new GroupSymbol(procName); QueryResolver.resolveCommand(command, group, Command.TYPE_STORED_PROCEDURE, metadata, true); // Validate return Validator.validate(command, metadata); }
@Test public void testTextTableSelector() throws Exception { String sql = "select x.* from (select * from pm1.g1) y, texttable(e1 || '\n' || e2 || '\n' || e3 SELECTOR 'c' COLUMNS x string) x"; Command c = QueryParser.getQueryParser().parseCommand(sql); assertEquals("SELECT x.* FROM (SELECT * FROM pm1.g1) AS y, TEXTTABLE(((((e1 || '\\u000A') || e2) || '\\u000A') || e3) SELECTOR 'c' COLUMNS x string) AS x", c.toString()); assertEquals("SELECT x.* FROM (SELECT * FROM pm1.g1) AS y, TEXTTABLE(((((e1 || '\\u000A') || e2) || '\\u000A') || e3) SELECTOR 'c' COLUMNS x string) AS x", c.clone().toString()); List<?>[] expected = new List<?>[] { Arrays.asList("c"), }; process(sql, expected); }
@Test public void testCurrentDate() throws Exception { Command command = QueryParser.getQueryParser().parseCommand("select current_date()"); //$NON-NLS-1$ QueryResolver.resolveCommand(command, RealMetadataFactory.example1Cached()); helpTest(command, "SELECT current_date()"); //$NON-NLS-1$ }
@Test public void testCurrentTimestamp() throws Exception { Command command = QueryParser.getQueryParser().parseCommand("select current_timestamp, current_timestamp(1)"); //$NON-NLS-1$ QueryResolver.resolveCommand(command, RealMetadataFactory.example1Cached()); helpTest(command, "SELECT current_timestamp, current_timestamp(1)"); //$NON-NLS-1$ }
CreateProcedureCommand helpResolveUpdateProcedure(String procedure, String userUpdateStr) throws QueryParserException, QueryResolverException, TeiidComponentException, QueryMetadataException { QueryMetadataInterface metadata = RealMetadataFactory.exampleUpdateProc(TriggerEvent.UPDATE, procedure); ProcedureContainer userCommand = (ProcedureContainer)QueryParser.getQueryParser().parseCommand(userUpdateStr); QueryResolver.resolveCommand(userCommand, metadata); return (CreateProcedureCommand)QueryResolver.expandCommand(userCommand, metadata, AnalysisRecord.createNonRecordingRecord()); }
@Test public void testValidateUpdateElements2() throws Exception { QueryMetadataInterface metadata = exampleMetadata(); Command command = QueryParser.getQueryParser().parseCommand("UPDATE test.group2 SET e1 = 'x'"); //$NON-NLS-1$ QueryResolver.resolveCommand(command, metadata); helpRunValidator(command, new String[] {}, metadata); }
private static Command getCommand(String sql) throws TeiidComponentException, TeiidProcessingException { Command command = QueryParser.getQueryParser().parseCommand(sql); QueryResolver.resolveCommand(command, RealMetadataFactory.example1Cached()); return QueryRewriter.rewrite(command, RealMetadataFactory.example1Cached(), null); }
@Test public void testNationCharString2() throws Exception { Query query = (Query) QueryParser.getQueryParser().parseCommand("SELECT DISTINCT TABLE_QUALIFIER, NULL AS TABLE_OWNER, NULL AS TABLE_NAME, NULL AS TABLE_TYPE, NULL AS REMARKS FROM ATIODBCSYSTEM.OA_TABLES WHERE TABLE_QUALIFIER LIKE N'%' ESCAPE '\\' ORDER BY TABLE_QUALIFIER "); //$NON-NLS-1$ MatchCriteria matchCrit = (MatchCriteria) query.getCriteria(); Constant c = (Constant) matchCrit.getRightExpression(); assertEquals(c, new Constant("%")); //$NON-NLS-1$ }
public static Command helpTestRewriteCommand(String original, String expected, QueryMetadataInterface metadata, CommandContext cc) throws TeiidException { Command command = QueryParser.getQueryParser().parseCommand(original); QueryResolver.resolveCommand(command, metadata); Command rewriteCommand = QueryRewriter.rewrite(command, metadata, cc); //to accomodate the logic that was moved to QueryOptimizer if (rewriteCommand instanceof Insert && ((Insert)rewriteCommand).isUpsert()) { rewriteCommand = QueryRewriter.rewriteAsUpsertProcedure((Insert)rewriteCommand, metadata, cc); } assertEquals("Rewritten command was not expected", expected, rewriteCommand.toString()); //$NON-NLS-1$ return rewriteCommand; }
@Test public void testAlterView() throws Exception { AlterView alterView = new AlterView(); alterView.setTarget(new GroupSymbol("x")); alterView.setDefinition((QueryCommand) QueryParser.getQueryParser().parseCommand("/*+ cache */ SELECT 1")); helpTest("alter view x as /*+ cache */ select 1", "ALTER VIEW x AS\n/*+ cache */ SELECT 1", alterView); }
@Test public void testAlterProc() throws Exception { AlterView alterView = new AlterView(); alterView.setTarget(new GroupSymbol("x")); alterView.setDefinition((QueryCommand) QueryParser.getQueryParser().parseCommand("/*+ cache */ SELECT 1")); helpTest("alter view x as /*+ cache */ select 1", "ALTER VIEW x AS\n/*+ cache */ SELECT 1", alterView); }
@Test public void testRewriteExec() throws Exception { Command command = QueryParser.getQueryParser().parseCommand("exec pm1.sq2(session_id())"); //$NON-NLS-1$ QueryResolver.resolveCommand(command, RealMetadataFactory.example1Cached()); CommandContext context = new CommandContext(); context.setConnectionID("1"); Command rewriteCommand = QueryRewriter.rewrite(command, RealMetadataFactory.example1Cached(), context); assertEquals("EXEC pm1.sq2('1')", rewriteCommand.toString()); //$NON-NLS-1$ }