Search in sources :

Example 1 with QueryParser

use of org.teiid.query.parser.QueryParser in project teiid by teiid.

the class TestAuthorizationValidationVisitor method helpTest.

private void helpTest(String sql, QueryMetadataInterface metadata, String[] expectedInaccesible, VDBMetaData vdb, DataPolicyMetadata... roles) throws QueryParserException, QueryResolverException, TeiidComponentException {
    QueryParser parser = QueryParser.getQueryParser();
    Command command = parser.parseCommand(sql);
    QueryResolver.resolveCommand(command, metadata);
    DataRolePolicyDecider dataRolePolicyDecider = createPolicyDecider(metadata, vdb, roles);
    // $NON-NLS-1$
    AuthorizationValidationVisitor visitor = new AuthorizationValidationVisitor(dataRolePolicyDecider, context);
    ValidatorReport report = Validator.validate(command, metadata, visitor);
    if (report.hasItems()) {
        ValidatorFailure firstFailure = report.getItems().iterator().next();
        // strings
        Set<String> expected = new HashSet<String>(Arrays.asList(expectedInaccesible));
        // elements
        Set<String> actual = new HashSet<String>();
        for (LanguageObject obj : firstFailure.getInvalidObjects()) {
            if (obj instanceof ElementSymbol) {
                actual.add(((ElementSymbol) obj).getName());
            } else {
                actual.add(obj.toString());
            }
        }
        assertEquals(expected, actual);
    } else if (expectedInaccesible.length > 0) {
        // $NON-NLS-1$
        fail("Expected inaccessible objects, but got none.");
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) QueryParser(org.teiid.query.parser.QueryParser) Command(org.teiid.query.sql.lang.Command) ValidatorFailure(org.teiid.query.validator.ValidatorFailure) ValidatorReport(org.teiid.query.validator.ValidatorReport) LanguageObject(org.teiid.query.sql.LanguageObject) HashSet(java.util.HashSet)

Example 2 with QueryParser

use of org.teiid.query.parser.QueryParser in project teiid by teiid.

the class TestProcedureImpl method example.

public static Call example() throws Exception {
    // $NON-NLS-1$
    String sql = "EXEC pm1.sq3('x', 1)";
    Command command = new QueryParser().parseCommand(sql);
    QueryResolver.resolveCommand(command, TstLanguageBridgeFactory.metadata);
    return TstLanguageBridgeFactory.factory.translate((StoredProcedure) command);
}
Also used : QueryParser(org.teiid.query.parser.QueryParser) Command(org.teiid.query.sql.lang.Command)

Example 3 with QueryParser

use of org.teiid.query.parser.QueryParser in project teiid by teiid.

the class TestValidator method testDefect9917.

@Test
public void testDefect9917() throws Exception {
    QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
    // $NON-NLS-1$
    String sql = "SELECT lookup('pm1.g1', 'e1a', 'e2', e2) AS x, lookup('pm1.g1', 'e4', 'e3', e3) AS y FROM pm1.g1";
    Command command = new QueryParser().parseCommand(sql);
    try {
        QueryResolver.resolveCommand(command, metadata);
        // $NON-NLS-1$
        fail("Did not get exception");
    } catch (QueryResolverException e) {
    // expected
    }
    // $NON-NLS-1$
    sql = "SELECT lookup('pm1.g1a', 'e1', 'e2', e2) AS x, lookup('pm1.g1', 'e4', 'e3', e3) AS y FROM pm1.g1";
    command = new QueryParser().parseCommand(sql);
    try {
        QueryResolver.resolveCommand(command, metadata);
        // $NON-NLS-1$
        fail("Did not get exception");
    } catch (QueryResolverException e) {
    // expected
    }
}
Also used : QueryParser(org.teiid.query.parser.QueryParser) Command(org.teiid.query.sql.lang.Command) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) QueryResolverException(org.teiid.api.exception.query.QueryResolverException) Test(org.junit.Test)

Example 4 with QueryParser

use of org.teiid.query.parser.QueryParser in project teiid by teiid.

the class TestQueryRewriter method testStoredProcedure_9822.

// defect 9822
@Test
public void testStoredProcedure_9822() throws Exception {
    QueryParser parser = new QueryParser();
    // $NON-NLS-1$
    Command command = parser.parseCommand("exec pm1.sp4(5)");
    // resolve
    QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
    QueryResolver.resolveCommand(command, metadata);
    // rewrite
    Command rewriteCommand = QueryRewriter.rewrite(command, metadata, null);
    Collection<SPParameter> parameters = ((StoredProcedure) rewriteCommand).getParameters();
    for (SPParameter param : parameters) {
        if (param.getParameterType() == ParameterInfo.IN || param.getParameterType() == ParameterInfo.INOUT) {
            assertTrue(param.getExpression() instanceof Constant);
        }
    }
}
Also used : QueryParser(org.teiid.query.parser.QueryParser) Constant(org.teiid.query.sql.symbol.Constant) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 5 with QueryParser

use of org.teiid.query.parser.QueryParser in project teiid by teiid.

the class Request method parseCommand.

private Command parseCommand() throws QueryParserException {
    if (requestMsg.getCommand() != null) {
        return (Command) requestMsg.getCommand();
    }
    String[] commands = requestMsg.getCommands();
    ParseInfo parseInfo = createParseInfo(this.requestMsg, this.workContext.getSession());
    QueryParser queryParser = QueryParser.getQueryParser();
    if (requestMsg.isPreparedStatement() || requestMsg.isCallableStatement() || !requestMsg.isBatchedUpdate()) {
        String commandStr = commands[0];
        if (preParser != null) {
            commandStr = preParser.preParse(commandStr, this.context);
        }
        return queryParser.parseCommand(commandStr, parseInfo);
    }
    List<Command> parsedCommands = new ArrayList<Command>(commands.length);
    for (int i = 0; i < commands.length; i++) {
        String updateCommand = commands[i];
        if (preParser != null) {
            updateCommand = preParser.preParse(updateCommand, this.context);
        }
        parsedCommands.add(queryParser.parseCommand(updateCommand, parseInfo));
    }
    return new BatchedUpdateCommand(parsedCommands);
}
Also used : QueryParser(org.teiid.query.parser.QueryParser) CreateProcedureCommand(org.teiid.query.sql.proc.CreateProcedureCommand) Command(org.teiid.query.sql.lang.Command) QueryCommand(org.teiid.query.sql.lang.QueryCommand) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) ArrayList(java.util.ArrayList) ParseInfo(org.teiid.query.parser.ParseInfo) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand)

Aggregations

QueryParser (org.teiid.query.parser.QueryParser)18 Command (org.teiid.query.sql.lang.Command)10 Test (org.junit.Test)7 MetadataFactory (org.teiid.metadata.MetadataFactory)6 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)6 ValidatorReport (org.teiid.query.validator.ValidatorReport)5 FileReader (java.io.FileReader)4 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)4 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)4 MetadataValidator (org.teiid.query.metadata.MetadataValidator)3 CreateProcedureCommand (org.teiid.query.sql.proc.CreateProcedureCommand)3 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)3 ArrayList (java.util.ArrayList)2 QueryParserException (org.teiid.api.exception.query.QueryParserException)2 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)2 QueryValidatorException (org.teiid.api.exception.query.QueryValidatorException)2 Column (org.teiid.metadata.Column)2 MetadataException (org.teiid.metadata.MetadataException)2 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)2 FileNotFoundException (java.io.FileNotFoundException)1