Search in sources :

Example 16 with MetadataValidator

use of org.teiid.query.metadata.MetadataValidator in project teiid by teiid.

the class TestSwaggerMetadataProcessor method getTransformationMetadata.

public static TransformationMetadata getTransformationMetadata(MetadataFactory mf, SwaggerExecutionFactory ef) throws Exception {
    TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "swagger", new FunctionTree("foo", new UDFSource(ef.getPushDownFunctions())));
    ValidatorReport report = new MetadataValidator().validate(metadata.getVdbMetaData(), metadata.getMetadataStore());
    if (report.hasItems()) {
        throw new RuntimeException(report.getFailureMessage());
    }
    return metadata;
}
Also used : UDFSource(org.teiid.query.function.UDFSource) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) FunctionTree(org.teiid.query.function.FunctionTree) MetadataValidator(org.teiid.query.metadata.MetadataValidator) ValidatorReport(org.teiid.query.validator.ValidatorReport)

Example 17 with MetadataValidator

use of org.teiid.query.metadata.MetadataValidator in project teiid by teiid.

the class TestVisitors method exampleSalesforce.

public static QueryMetadataInterface exampleSalesforce() {
    try {
        ModelMetaData mmd = new ModelMetaData();
        mmd.setName("SalesforceModel");
        MetadataFactory mf = new MetadataFactory("sf", 1, SystemMetadata.getInstance().getRuntimeTypeMap(), mmd);
        mf.setParser(new QueryParser());
        // load the metadata as captured from 8.9 on 9/3/2014
        mf.parse(new FileReader(UnitTestUtil.getTestDataFile("sf.ddl")));
        SalesForceExecutionFactory factory = new SalesForceExecutionFactory();
        factory.start();
        for (FunctionMethod func : factory.getPushDownFunctions()) {
            mf.addFunction(func);
        }
        SalesForceMetadataProcessor.addProcedrues(mf);
        // Create Contacts group - which has different name in sources
        // $NON-NLS-1$
        Table contactTable = RealMetadataFactory.createPhysicalGroup("Contacts", mf.getSchema());
        // $NON-NLS-1$
        contactTable.setNameInSource("Contact");
        // $NON-NLS-1$
        contactTable.setProperty("Supports Query", Boolean.TRUE.toString());
        // Create Contact Columns
        String[] elemNames = new String[] { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "ContactID", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "Name", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "AccountId", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "InitialContact", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "LastTime" };
        String[] elemTypes = new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.TIMESTAMP, DataTypeManager.DefaultDataTypes.TIME };
        List<Column> contactCols = RealMetadataFactory.createElements(contactTable, elemNames, elemTypes);
        // Set name in source on each column
        String[] contactNameInSource = new String[] { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "id", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "ContactName", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "accountid", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "InitialContact", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "LastTime" };
        for (int i = 0; i < 2; i++) {
            Column obj = contactCols.get(i);
            obj.setNameInSource(contactNameInSource[i]);
        }
        // add a procedure with a native query property
        List<ProcedureParameter> params = new LinkedList<ProcedureParameter>();
        params.add(RealMetadataFactory.createParameter("x", SPParameter.IN, TypeFacility.RUNTIME_NAMES.STRING));
        Procedure nativeProc = RealMetadataFactory.createStoredProcedure("foo", mf.getSchema(), params);
        nativeProc.setProperty(SQLStringVisitor.TEIID_NATIVE_QUERY, "search;select accountname from account where accountid = $1");
        nativeProc.setResultSet(RealMetadataFactory.createResultSet("rs", new String[] { "accountname" }, new String[] { TypeFacility.RUNTIME_NAMES.STRING }));
        TransformationMetadata tm = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "x");
        ValidatorReport report = new MetadataValidator().validate(tm.getVdbMetaData(), tm.getMetadataStore());
        if (report.hasItems()) {
            throw new RuntimeException(report.getFailureMessage());
        }
        return tm;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Table(org.teiid.metadata.Table) SalesForceExecutionFactory(org.teiid.translator.salesforce.SalesForceExecutionFactory) LinkedList(java.util.LinkedList) ValidatorReport(org.teiid.query.validator.ValidatorReport) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) QueryParser(org.teiid.query.parser.QueryParser) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) Column(org.teiid.metadata.Column) FunctionMethod(org.teiid.metadata.FunctionMethod) Procedure(org.teiid.metadata.Procedure) FileReader(java.io.FileReader) MetadataValidator(org.teiid.query.metadata.MetadataValidator)

Example 18 with MetadataValidator

use of org.teiid.query.metadata.MetadataValidator in project teiid by teiid.

the class TestSimpleDBMetadataProcessor method getDDL.

static String getDDL(Properties props) throws TranslatorException {
    SimpleDBExecutionFactory translator = new SimpleDBExecutionFactory();
    translator.start();
    MetadataFactory mf = new MetadataFactory("vdb", 1, "people", SystemMetadata.getInstance().getRuntimeTypeMap(), props, null);
    SimpleDBConnection connection = Mockito.mock(SimpleDBConnection.class);
    Mockito.stub(connection.getDomains()).toReturn(Arrays.asList("G1", "G2"));
    HashSet<SimpleDBAttribute> cols = new HashSet<SimpleDBConnection.SimpleDBAttribute>();
    cols.add(new SimpleDBAttribute("e1", false));
    cols.add(new SimpleDBAttribute("e2", false));
    Mockito.stub(connection.getAttributeNames("G1")).toReturn(cols);
    HashSet<SimpleDBAttribute> cols2 = new HashSet<SimpleDBConnection.SimpleDBAttribute>();
    cols2.add(new SimpleDBAttribute("e1", false));
    cols2.add(new SimpleDBAttribute("e2", true));
    Mockito.stub(connection.getAttributeNames("G2")).toReturn(cols2);
    translator.getMetadata(mf, connection);
    TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "vdb", new FunctionTree("foo", new UDFSource(translator.getPushDownFunctions())));
    ValidatorReport report = new MetadataValidator().validate(metadata.getVdbMetaData(), metadata.getMetadataStore());
    if (report.hasItems()) {
        throw new RuntimeException(report.getFailureMessage());
    }
    String ddl = DDLStringVisitor.getDDLString(mf.getSchema(), null, null);
    return ddl;
}
Also used : UDFSource(org.teiid.query.function.UDFSource) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) FunctionTree(org.teiid.query.function.FunctionTree) SimpleDBAttribute(org.teiid.translator.simpledb.api.SimpleDBConnection.SimpleDBAttribute) ValidatorReport(org.teiid.query.validator.ValidatorReport) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) SimpleDBExecutionFactory(org.teiid.translator.simpledb.SimpleDBExecutionFactory) MetadataValidator(org.teiid.query.metadata.MetadataValidator) SimpleDBConnection(org.teiid.translator.simpledb.api.SimpleDBConnection) HashSet(java.util.HashSet)

Example 19 with MetadataValidator

use of org.teiid.query.metadata.MetadataValidator in project teiid by teiid.

the class TestProtobufMetadataProcessor method getTransformationMetadata.

public static TransformationMetadata getTransformationMetadata(MetadataFactory mf, InfinispanExecutionFactory ef) throws Exception {
    TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "proto", new FunctionTree("foo", new UDFSource(ef.getPushDownFunctions())));
    ValidatorReport report = new MetadataValidator().validate(metadata.getVdbMetaData(), metadata.getMetadataStore());
    if (report.hasItems()) {
        throw new RuntimeException(report.getFailureMessage());
    }
    return metadata;
}
Also used : UDFSource(org.teiid.query.function.UDFSource) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) FunctionTree(org.teiid.query.function.FunctionTree) MetadataValidator(org.teiid.query.metadata.MetadataValidator) ValidatorReport(org.teiid.query.validator.ValidatorReport)

Example 20 with MetadataValidator

use of org.teiid.query.metadata.MetadataValidator 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

MetadataValidator (org.teiid.query.metadata.MetadataValidator)20 ValidatorReport (org.teiid.query.validator.ValidatorReport)20 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)16 MetadataFactory (org.teiid.metadata.MetadataFactory)12 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)12 FunctionTree (org.teiid.query.function.FunctionTree)10 UDFSource (org.teiid.query.function.UDFSource)10 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)8 Test (org.junit.Test)5 FileReader (java.io.FileReader)4 EdmxFormatParser (org.odata4j.format.xml.EdmxFormatParser)4 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)4 TranslationUtility (org.teiid.cdk.api.TranslationUtility)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStreamReader (java.io.InputStreamReader)3 Properties (java.util.Properties)3 Before (org.junit.Before)3 MetadataException (org.teiid.metadata.MetadataException)3 Table (org.teiid.metadata.Table)3 QueryParser (org.teiid.query.parser.QueryParser)3