Search in sources :

Example 21 with QueryValidatorException

use of org.teiid.api.exception.query.QueryValidatorException in project teiid by teiid.

the class TestProcedureProcessor method testVarArgsVirtNotNull.

@Test
public void testVarArgsVirtNotNull() throws Exception {
    String ddl = "create virtual procedure vproc (x integer, VARIADIC z integer NOT NULL) returns (y integer) as begin select array_length(z); end;";
    TransformationMetadata tm = TestProcedureResolving.createMetadata(ddl);
    // $NON-NLS-1$
    String sql = "call vproc(1, null, 3)";
    try {
        getProcedurePlan(sql, tm);
        fail();
    } catch (QueryValidatorException e) {
    }
    // $NON-NLS-1$
    sql = "call vproc(1, (select cast(null as integer)), 3)";
    ProcessorPlan plan = getProcedurePlan(sql, tm);
    HardcodedDataManager dataManager = new HardcodedDataManager();
    try {
        helpTestProcess(plan, null, dataManager, tm);
        fail();
    } catch (QueryValidatorException e) {
    }
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) QueryValidatorException(org.teiid.api.exception.query.QueryValidatorException) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Test(org.junit.Test)

Example 22 with QueryValidatorException

use of org.teiid.api.exception.query.QueryValidatorException in project teiid by teiid.

the class TestSecurityFunctions method testHasRoleWithService.

@Test
public void testHasRoleWithService() throws Exception {
    // $NON-NLS-1$
    String sql = "select pm1.g1.e2 from pm1.g1 where true = hasRole('data', pm1.g1.e1)";
    // Create expected results
    List[] expected = new List[] {};
    // Construct data manager with data
    HardcodedDataManager dataManager = new HardcodedDataManager();
    dataManager.addData("SELECT pm1.g1.e1, pm1.g1.e2 FROM pm1.g1", new List[] { // $NON-NLS-1$
    Arrays.asList(new Object[] { "fooRole", new Integer(0) }) });
    CommandContext context = new CommandContext();
    context.setAuthoriziationValidator(new AuthorizationValidator() {

        @Override
        public boolean validate(String[] originalSql, Command command, QueryMetadataInterface metadata, CommandContext commandContext, CommandType commandType) throws QueryValidatorException, TeiidComponentException {
            return false;
        }

        @Override
        public boolean hasRole(String roleName, CommandContext commandContext) {
            return false;
        }

        @Override
        public boolean isAccessible(AbstractMetadataRecord record, CommandContext commandContext) {
            return true;
        }
    });
    Command command = TestProcessor.helpParse(sql);
    ProcessorPlan plan = TestProcessor.helpGetPlan(command, RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(), context);
    // Run query
    TestProcessor.helpProcess(plan, context, dataManager, expected);
}
Also used : CommandContext(org.teiid.query.util.CommandContext) AuthorizationValidator(org.teiid.dqp.internal.process.AuthorizationValidator) AbstractMetadataRecord(org.teiid.metadata.AbstractMetadataRecord) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Command(org.teiid.query.sql.lang.Command) QueryValidatorException(org.teiid.api.exception.query.QueryValidatorException) List(java.util.List) TeiidComponentException(org.teiid.core.TeiidComponentException) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 23 with QueryValidatorException

use of org.teiid.api.exception.query.QueryValidatorException in project teiid by teiid.

the class TestValidator method validateProcedure.

private void validateProcedure(String userUpdateStr, QueryMetadataInterface metadata) throws QueryResolverException, QueryMetadataException, TeiidComponentException, QueryValidatorException {
    ProcedureContainer command = (ProcedureContainer) helpResolve(userUpdateStr, metadata);
    Command proc = QueryResolver.expandCommand(command, metadata, AnalysisRecord.createNonRecordingRecord());
    ValidatorReport report = Validator.validate(proc, metadata);
    if (report.hasItems()) {
        throw new QueryValidatorException(report.getFailureMessage());
    }
    report = Validator.validate(command, metadata);
    if (report.hasItems()) {
        throw new QueryValidatorException(report.getFailureMessage());
    }
}
Also used : Command(org.teiid.query.sql.lang.Command) QueryValidatorException(org.teiid.api.exception.query.QueryValidatorException) ProcedureContainer(org.teiid.query.sql.lang.ProcedureContainer)

Example 24 with QueryValidatorException

use of org.teiid.api.exception.query.QueryValidatorException in project teiid by teiid.

the class TestValidator method helpFailProcedure.

private void helpFailProcedure(String procedure, String userUpdateStr, Table.TriggerEvent procedureType) {
    QueryMetadataInterface metadata = RealMetadataFactory.exampleUpdateProc(procedureType, procedure);
    try {
        validateProcedure(userUpdateStr, metadata);
        fail("Expected failures for " + procedure);
    } catch (QueryValidatorException e) {
    } catch (TeiidException e) {
        throw new RuntimeException(e);
    }
}
Also used : TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) QueryValidatorException(org.teiid.api.exception.query.QueryValidatorException) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) TeiidException(org.teiid.core.TeiidException)

Aggregations

QueryValidatorException (org.teiid.api.exception.query.QueryValidatorException)24 LanguageObject (org.teiid.query.sql.LanguageObject)6 Command (org.teiid.query.sql.lang.Command)6 Test (org.junit.Test)5 TeiidComponentException (org.teiid.core.TeiidComponentException)5 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)4 RuleMergeCriteria (org.teiid.query.optimizer.relational.rules.RuleMergeCriteria)4 AnalysisRecord (org.teiid.query.analysis.AnalysisRecord)3 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)3 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)3 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)3 ValidatorReport (org.teiid.query.validator.ValidatorReport)3 List (java.util.List)2 FunctionExecutionException (org.teiid.api.exception.query.FunctionExecutionException)2 QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)2 TempMetadataID (org.teiid.query.metadata.TempMetadataID)2 QueryParser (org.teiid.query.parser.QueryParser)2 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)2 Expression (org.teiid.query.sql.symbol.Expression)2 CommandContext (org.teiid.query.util.CommandContext)2