Search in sources :

Example 11 with MetadataValidator

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

the class TestDDLParser method testFKAccrossSchemas.

@Test
public void testFKAccrossSchemas() throws Exception {
    String ddl = "CREATE FOREIGN TABLE G1(g1e1 integer, g1e2 varchar, PRIMARY KEY(g1e1, g1e2));\n";
    String ddl2 = "CREATE FOREIGN TABLE G2( g2e1 integer, g2e2 varchar, PRIMARY KEY(g2e1, g2e2)," + "FOREIGN KEY (g2e1, g2e2) REFERENCES model.G1)";
    MetadataFactory f1 = helpParse(ddl, "model");
    MetadataFactory f2 = helpParse(ddl2, "model2");
    VDBMetaData vdb = new VDBMetaData();
    // $NON-NLS-1$
    vdb.setName("myVDB");
    ModelMetaData modelOne = new ModelMetaData();
    // $NON-NLS-1$
    modelOne.setName("model");
    vdb.addModel(modelOne);
    ModelMetaData modelTwo = new ModelMetaData();
    // $NON-NLS-1$
    modelTwo.setName("model2");
    vdb.addModel(modelTwo);
    MetadataStore s = f1.asMetadataStore();
    f2.mergeInto(s);
    ValidatorReport report = new MetadataValidator().validate(vdb, s);
    assertFalse(report.hasItems());
    Table table = s.getSchema("model2").getTable("G2");
    ForeignKey fk = table.getForeignKeys().get(0);
    assertEquals(fk.getColumns(), table.getColumns());
    assertEquals("G1", fk.getReferenceTableName());
    assertEquals(fk.getPrimaryKey().getColumns(), s.getSchema("model").getTable("G1").getColumns());
}
Also used : CompositeMetadataStore(org.teiid.query.metadata.CompositeMetadataStore) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) MetadataValidator(org.teiid.query.metadata.MetadataValidator) ValidatorReport(org.teiid.query.validator.ValidatorReport) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 12 with MetadataValidator

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

the class TestDDLParser method testOptionalFK.

@Test
public void testOptionalFK() throws Exception {
    String ddl = "CREATE FOREIGN TABLE G1(g1e1 integer, g1e2 varchar, PRIMARY KEY(g1e1, g1e2));\n" + "CREATE FOREIGN TABLE G2( g2e1 integer, g2e2 varchar, PRIMARY KEY(g2e1, g2e2)," + "FOREIGN KEY (g2e1, g2e2) REFERENCES G1)";
    MetadataFactory s = helpParse(ddl, "model");
    Map<String, Table> tableMap = s.getSchema().getTables();
    assertEquals(2, tableMap.size());
    assertTrue("Table not found", tableMap.containsKey("G1"));
    assertTrue("Table not found", tableMap.containsKey("G2"));
    Table table = tableMap.get("G2");
    ForeignKey fk = table.getForeignKeys().get(0);
    assertEquals(fk.getColumns(), table.getColumns());
    assertEquals("G1", fk.getReferenceTableName());
    VDBMetaData vdb = new VDBMetaData();
    // $NON-NLS-1$
    vdb.setName("myVDB");
    ModelMetaData modelOne = new ModelMetaData();
    // $NON-NLS-1$
    modelOne.setName("model");
    vdb.addModel(modelOne);
    ValidatorReport report = new MetadataValidator().validate(vdb, s.asMetadataStore());
    assertFalse(report.hasItems());
    assertEquals(fk.getPrimaryKey().getColumns(), tableMap.get("G1").getColumns());
}
Also used : VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) MetadataValidator(org.teiid.query.metadata.MetadataValidator) ValidatorReport(org.teiid.query.validator.ValidatorReport) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 13 with MetadataValidator

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

the class TestSQLConversionVisitor method queryMetadataInterface.

private static TransformationMetadata queryMetadataInterface() {
    try {
        ModelMetaData mmd = new ModelMetaData();
        mmd.setName("prestodbModel");
        MetadataFactory mf = new MetadataFactory("prestodb", 1, SystemMetadata.getInstance().getRuntimeTypeMap(), mmd);
        mf.setParser(new QueryParser());
        mf.parse(new FileReader(UnitTestUtil.getTestDataFile("sample.ddl")));
        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 (MetadataException | FileNotFoundException e) {
        throw new RuntimeException(e);
    }
}
Also used : QueryParser(org.teiid.query.parser.QueryParser) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) MetadataValidator(org.teiid.query.metadata.MetadataValidator) ValidatorReport(org.teiid.query.validator.ValidatorReport) MetadataException(org.teiid.metadata.MetadataException) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 14 with MetadataValidator

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

the class TestODataMetadataProcessor method getTransformationMetadata.

public static TransformationMetadata getTransformationMetadata(MetadataFactory mf, ODataExecutionFactory ef) throws Exception {
    TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "trippin", 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 15 with MetadataValidator

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

the class TestMongoDBSelectVisitor method setUp.

@Before
public void setUp() throws Exception {
    this.translator = new MongoDBExecutionFactory();
    this.translator.start();
    MetadataFactory mf = TestDDLParser.helpParse(ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("northwind.ddl")), "northwind");
    TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "sakila", new FunctionTree("mongo", new UDFSource(translator.getPushDownFunctions())));
    ValidatorReport report = new MetadataValidator().validate(metadata.getVdbMetaData(), metadata.getMetadataStore());
    if (report.hasItems()) {
        throw new RuntimeException(report.getFailureMessage());
    }
    this.utility = new TranslationUtility(metadata);
}
Also used : UDFSource(org.teiid.query.function.UDFSource) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) FunctionTree(org.teiid.query.function.FunctionTree) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) TranslationUtility(org.teiid.cdk.api.TranslationUtility) MetadataValidator(org.teiid.query.metadata.MetadataValidator) ValidatorReport(org.teiid.query.validator.ValidatorReport) Before(org.junit.Before)

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