public static final CommandStatement sample2() { QueryParser parser = new QueryParser(); try { Update update = (Update) parser.parseCommand("UPDATE x SET x = 'y'"); //$NON-NLS-1$ return new CommandStatement(update); } catch(Exception e) { return null;} }
public Expression helpTestExpression(String sql, String expected) throws QueryParserException { Expression expr = QueryParser.getQueryParser().parseExpression(sql); helpTest(expr, expected); return expr; }
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 StringBuilder encountered(ParseException pe, int offset) { StringBuilder retval = new StringBuilder("Encountered \""); //$NON-NLS-1$ Token currentToken = pe.currentToken; for (int i = 1; i < offset; i++) { //TODO: for large offsets we don't have to call findPreceeding currentToken = currentToken.next; } List<Token> preceeding = findPreceeding(currentToken, 2); if (offset > 0 && !preceeding.isEmpty()) { addTokenSequence(preceeding.size() + 1, retval, null, preceeding.get(0), false); } else { addTokenSequence(1, retval, null, currentToken, offset==0); } if (currentToken.next != null && offset>0) { addTokenSequence(3, retval, currentToken, currentToken.next, true); currentToken = currentToken.next; //move to the error token } retval.append("\" at line ").append(currentToken.beginLine).append(", column ").append(currentToken.beginColumn); //$NON-NLS-1$ //$NON-NLS-2$ retval.append(".\n"); //$NON-NLS-1$ return retval; }
Criteria resolveCriteria(String criteriaString, Map symbolMap) { if (criteriaString != null && criteriaString.length() > 0) { try { Criteria crit = QueryParser.getQueryParser().parseCriteria(criteriaString); StaticSymbolMappingVisitor.mapSymbols(crit, symbolMap); ResolverVisitor.resolveLanguageObject(crit, null, planEnv.getGlobalMetadata()); return crit; } catch (Exception e) { throw new TeiidRuntimeException(e); } } return null; }
@Test(expected=MetadataException.class) public void testWrongPrimarykey() throws Exception { QueryParser parser = new QueryParser(); String ddl = "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar, PRIMARY KEY (e3))"; MetadataStore mds = new MetadataStore(); MetadataFactory mf = new MetadataFactory("x", 1, "model", getDataTypes(), new Properties(), null); parser.parseDDL(mf, ddl); mf.mergeInto(mds); }
@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()); }
QueryParser parser = QueryParser.getQueryParser(); try { subCommand = parser.parseProcedure(plan, !(procCommand instanceof StoredProcedure)); } catch(QueryParserException e) { throw new QueryResolverException(QueryPlugin.Event.TEIID30060, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30060, group, procCommand.getClass().getSimpleName()));
public Expression parseSelectExpression(String sql) throws QueryParserException { if(sql == null) { throw new IllegalArgumentException(QueryPlugin.Util.getString("QueryParser.nullSqlExpr")); //$NON-NLS-1$ } ParseInfo dummyInfo = new ParseInfo(); Expression result = null; try{ result = getSqlParser(sql).selectExpression(dummyInfo); } catch(ParseException pe) { throw convertParserException(pe); } finally { tm.reinit(); } return result; }
if (record instanceof Procedure) { Procedure p = (Procedure)record; Command command = parser.parseProcedure(p.getQueryPlan(), false); QueryResolver.resolveCommand(command, new GroupSymbol(p.getFullName()), Command.TYPE_STORED_PROCEDURE, metadata, false); resolverReport = Validator.validate(command, metadata); QueryNode node = null; if (t.isVirtual()) { QueryCommand command = (QueryCommand)parser.parseCommand(selectTransformation); QueryResolver.resolveCommand(command, metadata); resolverReport = Validator.validate(command, metadata); Expression ex = parser.parseExpression(exprString); ResolverVisitor.resolveLanguageObject(ex, groups, metadata); if (!ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(ex).isEmpty()) {
private void validateUpdatePlan(ModelMetaData model, ValidatorReport report, QueryMetadataInterface metadata, Table t, String plan, int type) throws QueryParserException, QueryResolverException, TeiidComponentException { Command command = parser.parseProcedure(plan, true); QueryResolver.resolveCommand(command, new GroupSymbol(t.getFullName()), type, metadata, false); //determineDependencies(t, command); -- these should be tracked against triggers ValidatorReport resolverReport = Validator.validate(command, metadata); processReport(model, t, report, resolverReport); }
protected MetadataFactory createMetadataFactory(VDBMetaData vdb, MetadataStore store, ModelMetaData model, Map<String, ? extends VDBResource> vdbResources) { Map<String, Datatype> datatypes = store.getDatatypes(); MetadataFactory factory = new MetadataFactory(vdb.getName(), vdb.getVersion(), datatypes, model); factory.getSchema().setPhysical(model.isSource()); factory.setParser(new QueryParser()); //for thread safety each factory gets it's own instance. factory.setVdbResources(vdbResources); factory.setVDBClassLoader(vdb.getAttachment(ClassLoader.class)); return factory; }
private Token addTokenSequence(int maxSize, StringBuilder retval, Token last, Token tok, boolean highlight) { for (int i = 0; i < maxSize && tok != null; i++) { if (last != null && last.endColumn + 1 != tok.beginColumn && tok.kind != SQLParserConstants.EOF) { retval.append(" "); //$NON-NLS-1$ } last = tok; if (i == 0 && highlight) { retval.append("[*]"); //$NON-NLS-1$ } if (tok.image != null && !tok.image.isEmpty()) { add_escapes(tok.image, retval); if (i == 0 && highlight) { retval.append("[*]"); //$NON-NLS-1$ } } while (tok.next == null) { if (this.parser.getNextToken() == null) { break; } } tok = tok.next; } return last; }
@Test public void testRenameTable() throws Exception { QueryParser parser = new QueryParser(); String ddl = "CREATE FOREIGN TABLE G1( e1 integer auto_increment primary key, e2 varchar);" + "ALTER TABLE G1 RENAME TO G2"; MetadataStore mds = new MetadataStore(); MetadataFactory mf = new MetadataFactory("x", 1, "model", getDataTypes(), new Properties(), null); parser.parseDDL(mf, ddl); mf.mergeInto(mds); }
private Criteria parseCriteria(String critStr, QueryMetadataInterface metadata) { try { Criteria crit = QueryParser.getQueryParser().parseCriteria(critStr); // resolve against metadata QueryResolver.resolveCriteria(crit, metadata); return crit; } catch(TeiidException e) { throw new RuntimeException(e); } }
@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()); }
QueryParser parser = QueryParser.getQueryParser(); try { subCommand = parser.parseProcedure(plan, !(procCommand instanceof StoredProcedure)); } catch(QueryParserException e) { throw new QueryResolverException(QueryPlugin.Event.TEIID30060, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30060, group, procCommand.getClass().getSimpleName()));
public Expression parseSelectExpression(String sql) throws QueryParserException { if(sql == null) { throw new IllegalArgumentException(QueryPlugin.Util.getString("QueryParser.nullSqlExpr")); //$NON-NLS-1$ } ParseInfo dummyInfo = new ParseInfo(); Expression result = null; try{ result = getSqlParser(sql).selectExpression(dummyInfo); } catch(ParseException pe) { throw convertParserException(pe); } finally { tm.reinit(); } return result; }
private StringBuilder encountered(ParseException pe, int offset) { StringBuilder retval = new StringBuilder("Encountered \""); //$NON-NLS-1$ Token currentToken = pe.currentToken; for (int i = 1; i < offset; i++) { //TODO: for large offsets we don't have to call findPreceeding currentToken = currentToken.next; } List<Token> preceeding = findPreceeding(currentToken, 2); if (offset > 0 && !preceeding.isEmpty()) { addTokenSequence(preceeding.size() + 1, retval, null, preceeding.get(0), false); } else { addTokenSequence(1, retval, null, currentToken, offset==0); } if (currentToken.next != null && offset>0) { addTokenSequence(3, retval, currentToken, currentToken.next, true); currentToken = currentToken.next; //move to the error token } retval.append("\" at line ").append(currentToken.beginLine).append(", column ").append(currentToken.beginColumn); //$NON-NLS-1$ //$NON-NLS-2$ retval.append(".\n"); //$NON-NLS-1$ return retval; }
private void validateUpdatePlan(ModelMetaData model, ValidatorReport report, QueryMetadataInterface metadata, Table t, String plan, int type) throws QueryParserException, QueryResolverException, TeiidComponentException { Command command = parser.parseProcedure(plan, true); validateNoReferences(command, report, model); QueryResolver.resolveCommand(command, new GroupSymbol(t.getFullName()), type, metadata, false); //determineDependencies(t, command); -- these should be tracked against triggers ValidatorReport resolverReport = Validator.validate(command, metadata); processReport(model, t, report, resolverReport); }