Search in sources :

Example 16 with QueryValidatorException

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

the class ValidationVisitor method visit.

@Override
public void visit(AlterProcedure obj) {
    GroupSymbol gs = obj.getTarget();
    validateAlterTarget(obj);
    try {
        if (!gs.isProcedure() || !getMetadata().isVirtualModel(getMetadata().getModelID(gs.getMetadataID()))) {
            // $NON-NLS-1$
            handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.not_a_procedure", gs), gs);
            return;
        }
        Validator.validate(obj.getDefinition(), getMetadata(), this);
        StoredProcedureInfo info = getMetadata().getStoredProcedureInfoForProcedure(gs.getName());
        for (SPParameter param : info.getParameters()) {
            if (param.getParameterType() == SPParameter.RESULT_SET) {
                QueryResolver.validateProjectedSymbols(gs, param.getResultSetColumns(), obj.getDefinition().getProjectedSymbols());
                break;
            }
        }
    } catch (QueryValidatorException e) {
        handleValidationError(e.getMessage(), obj.getDefinition().getBlock());
    } catch (TeiidComponentException e) {
        handleException(e);
    }
}
Also used : StoredProcedureInfo(org.teiid.query.metadata.StoredProcedureInfo) QueryValidatorException(org.teiid.api.exception.query.QueryValidatorException) TeiidComponentException(org.teiid.core.TeiidComponentException)

Example 17 with QueryValidatorException

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

the class TestAuthorizationValidationVisitor method testPruneSelectAll.

@Test
public void testPruneSelectAll() throws Exception {
    String sql = "select * from pm1.g1";
    QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
    DataPolicyMetadata svc = new DataPolicyMetadata();
    // $NON-NLS-1$
    svc.setName("test");
    // $NON-NLS-1$
    svc.addPermission(addResource(DataPolicy.PermissionType.READ, "pm1"));
    PermissionMetaData p = addResource(DataPolicy.PermissionType.READ, "pm1.g1.e1");
    p.setAllowRead(false);
    // $NON-NLS-1$
    svc.addPermission(p);
    DataRolePolicyDecider dataRolePolicyDecider = createPolicyDecider(metadata, RealMetadataFactory.example1VDB(), svc);
    DefaultAuthorizationValidator dav = new DefaultAuthorizationValidator();
    dav.setPolicyDecider(dataRolePolicyDecider);
    this.context.setSessionVariable(DefaultAuthorizationValidator.IGNORE_UNAUTHORIZED_ASTERISK, "true");
    QueryParser parser = QueryParser.getQueryParser();
    Command command = parser.parseCommand(sql);
    QueryResolver.resolveCommand(command, metadata);
    assertEquals(4, command.getProjectedSymbols().size());
    boolean modified = dav.validate(new String[] {}, command, metadata, this.context, CommandType.USER);
    assertTrue(modified);
    assertEquals(3, command.getProjectedSymbols().size());
    p = addResource(DataPolicy.PermissionType.READ, "pm1.g1");
    p.setAllowRead(false);
    // $NON-NLS-1$
    svc.addPermission(p);
    command = parser.parseCommand(sql);
    QueryResolver.resolveCommand(command, metadata);
    assertEquals(4, command.getProjectedSymbols().size());
    try {
        dav.validate(new String[] {}, command, metadata, this.context, CommandType.USER);
        fail();
    } catch (QueryValidatorException e) {
    }
}
Also used : QueryParser(org.teiid.query.parser.QueryParser) Command(org.teiid.query.sql.lang.Command) QueryValidatorException(org.teiid.api.exception.query.QueryValidatorException) DataPolicyMetadata(org.teiid.adminapi.impl.DataPolicyMetadata) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) PermissionMetaData(org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData) Test(org.junit.Test)

Example 18 with QueryValidatorException

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

the class TestProcedurePlanner method helpPlanProcedure.

// ################ getReplacementClause tests ###################
private ProcessorPlan helpPlanProcedure(String userQuery, String procedure, TriggerEvent procedureType) throws TeiidComponentException, QueryMetadataException, TeiidProcessingException {
    QueryMetadataInterface metadata = RealMetadataFactory.exampleUpdateProc(procedureType, procedure);
    QueryParser parser = QueryParser.getQueryParser();
    Command userCommand = userQuery != null ? parser.parseCommand(userQuery) : parser.parseCommand(procedure);
    if (userCommand instanceof CreateProcedureCommand) {
        GroupSymbol gs = new GroupSymbol("proc");
        gs.setMetadataID(new TempMetadataID("proc", Collections.EMPTY_LIST));
        ((CreateProcedureCommand) userCommand).setVirtualGroup(gs);
    }
    QueryResolver.resolveCommand(userCommand, metadata);
    ValidatorReport report = Validator.validate(userCommand, metadata);
    if (report.hasItems()) {
        ValidatorFailure firstFailure = report.getItems().iterator().next();
        throw new QueryValidatorException(firstFailure.getMessage());
    }
    userCommand = QueryRewriter.rewrite(userCommand, metadata, null);
    AnalysisRecord analysisRecord = new AnalysisRecord(false, DEBUG);
    try {
        return QueryOptimizer.optimizePlan(userCommand, metadata, null, new DefaultCapabilitiesFinder(), analysisRecord, null);
    } finally {
        if (DEBUG) {
            System.out.println(analysisRecord.getDebugLog());
        }
    }
}
Also used : QueryParser(org.teiid.query.parser.QueryParser) AnalysisRecord(org.teiid.query.analysis.AnalysisRecord) CreateProcedureCommand(org.teiid.query.sql.proc.CreateProcedureCommand) CreateProcedureCommand(org.teiid.query.sql.proc.CreateProcedureCommand) Command(org.teiid.query.sql.lang.Command) ValidatorFailure(org.teiid.query.validator.ValidatorFailure) QueryValidatorException(org.teiid.api.exception.query.QueryValidatorException) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) TempMetadataID(org.teiid.query.metadata.TempMetadataID) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) ValidatorReport(org.teiid.query.validator.ValidatorReport)

Example 19 with QueryValidatorException

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

the class TestGlobalTemp method testGlobalTempUse.

@Test
public void testGlobalTempUse() throws Exception {
    TempTableTestHarness harness = new TempTableTestHarness();
    TransformationMetadata metadata = RealMetadataFactory.fromDDL("create global temporary table temp (x serial, s string) options (updatable true);" + "", "x", "y");
    HardcodedDataManager dm = new HardcodedDataManager();
    harness.setUp(metadata, dm);
    harness.execute("select * from temp", new List<?>[0]);
    harness.execute("insert into temp (s) values ('a')", new List<?>[] { Arrays.asList(1) });
    harness.execute("select * from temp", new List<?>[] { Arrays.asList(1, "a") });
    try {
        harness.execute("drop table temp", new List<?>[0]);
        fail();
    } catch (QueryValidatorException e) {
    }
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) QueryValidatorException(org.teiid.api.exception.query.QueryValidatorException) Test(org.junit.Test)

Example 20 with QueryValidatorException

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

the class TestProcedureProcessor method getProcedurePlan.

public static ProcessorPlan getProcedurePlan(String userQuery, QueryMetadataInterface metadata, CapabilitiesFinder capabilitiesFinder) throws Exception {
    Command userCommand = QueryParser.getQueryParser().parseCommand(userQuery);
    QueryResolver.resolveCommand(userCommand, metadata);
    ValidatorReport report = Validator.validate(userCommand, metadata);
    if (report.hasItems()) {
        ValidatorFailure firstFailure = report.getItems().iterator().next();
        throw new QueryValidatorException(firstFailure.getMessage());
    }
    QueryRewriter.rewrite(userCommand, metadata, new CommandContext());
    AnalysisRecord analysisRecord = new AnalysisRecord(false, DEBUG);
    try {
        if (capabilitiesFinder == null) {
            capabilitiesFinder = new DefaultCapabilitiesFinder();
        }
        ProcessorPlan plan = QueryOptimizer.optimizePlan(userCommand, metadata, null, capabilitiesFinder, analysisRecord, null);
        return plan;
    } finally {
        if (DEBUG) {
            System.out.println(analysisRecord.getDebugLog());
        }
    }
}
Also used : AnalysisRecord(org.teiid.query.analysis.AnalysisRecord) CommandContext(org.teiid.query.util.CommandContext) Command(org.teiid.query.sql.lang.Command) ValidatorFailure(org.teiid.query.validator.ValidatorFailure) QueryValidatorException(org.teiid.api.exception.query.QueryValidatorException) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) ValidatorReport(org.teiid.query.validator.ValidatorReport)

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