Search in sources :

Example 6 with ValidatorFailure

use of org.teiid.query.validator.ValidatorFailure 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)

Example 7 with ValidatorFailure

use of org.teiid.query.validator.ValidatorFailure in project teiid by teiid.

the class VDBRepository method finishDeployment.

public void finishDeployment(String name, String version) {
    VDBKey key = new VDBKey(name, version);
    CompositeVDB v = this.vdbRepo.get(key);
    if (v == null) {
        return;
    }
    VDBMetaData metadataAwareVDB = v.getVDB();
    if (v.getOriginalVDB().getStatus() == Status.FAILED) {
        if (v.getOriginalVDB() != metadataAwareVDB && metadataAwareVDB.getStatus() == Status.LOADING) {
            metadataAwareVDB.setStatus(Status.FAILED);
        }
        return;
    }
    synchronized (metadataAwareVDB) {
        try {
            try {
                v.metadataLoadFinished(allowEnv);
            } catch (MetadataException e) {
                // $NON-NLS-1$
                LogManager.logWarning(LogConstants.CTX_RUNTIME, e, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40073, name, version, e.getMessage()));
                if (!metadataAwareVDB.isPreview()) {
                    ValidatorReport report = new ValidatorReport();
                    report.addItem(new ValidatorFailure(e.getMessage()));
                    if (!processMetadataValidatorReport(key, report)) {
                        metadataAwareVDB.setStatus(Status.FAILED);
                        notifyFinished(name, version, v);
                        return;
                    }
                }
            }
            MetadataStore store = metadataAwareVDB.removeAttachment(MetadataStore.class);
            ValidatorReport report = new MetadataValidator(store.getDatatypes(), QueryParser.getQueryParser()).validate(metadataAwareVDB, store);
            if (report.hasItems()) {
                LogManager.logWarning(LogConstants.CTX_RUNTIME, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40073, name, version, report.getItems().iterator().next()));
                if (!metadataAwareVDB.isPreview() && !processMetadataValidatorReport(key, report)) {
                    metadataAwareVDB.setStatus(Status.FAILED);
                    notifyFinished(name, version, v);
                    return;
                }
            }
            validateDataSources(metadataAwareVDB);
            metadataAwareVDB.setStatus(Status.ACTIVE);
            // for  replication of events, temp tables and mat views
            GlobalTableStore gts = CompositeGlobalTableStore.createInstance(v, this.bufferManager, this.objectReplictor);
            metadataAwareVDB.addAttchment(GlobalTableStore.class, gts);
            if (this.databaseStore != null) {
                metadataAwareVDB.addAttchment(DatabaseStore.class, this.databaseStore);
            }
            notifyFinished(name, version, v);
        } finally {
            if (metadataAwareVDB.getStatus() != Status.ACTIVE && metadataAwareVDB.getStatus() != Status.FAILED) {
                // guard against an unexpected exception - probably bad validation logic
                metadataAwareVDB.setStatus(Status.FAILED);
                notifyFinished(name, version, v);
            }
        }
    }
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) VDBKey(org.teiid.vdb.runtime.VDBKey) ValidatorFailure(org.teiid.query.validator.ValidatorFailure) GlobalTableStore(org.teiid.query.tempdata.GlobalTableStore) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) FunctionMetadataValidator(org.teiid.query.function.metadata.FunctionMetadataValidator) MetadataValidator(org.teiid.query.metadata.MetadataValidator) MetadataException(org.teiid.metadata.MetadataException) ValidatorReport(org.teiid.query.validator.ValidatorReport)

Aggregations

ValidatorFailure (org.teiid.query.validator.ValidatorFailure)7 ValidatorReport (org.teiid.query.validator.ValidatorReport)6 Command (org.teiid.query.sql.lang.Command)3 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)3 QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)2 QueryValidatorException (org.teiid.api.exception.query.QueryValidatorException)2 TeiidException (org.teiid.core.TeiidException)2 AnalysisRecord (org.teiid.query.analysis.AnalysisRecord)2 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)2 QueryParser (org.teiid.query.parser.QueryParser)2 ValidationVisitor (org.teiid.query.validator.ValidationVisitor)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 DataPolicy (org.teiid.adminapi.DataPolicy)1 DataPolicyMetadata (org.teiid.adminapi.impl.DataPolicyMetadata)1 PermissionMetaData (org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData)1 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)1 MetadataException (org.teiid.metadata.MetadataException)1 MetadataStore (org.teiid.metadata.MetadataStore)1