Search in sources :

Example 31 with ValidatorReport

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

the class TestVisitor method queryMetadataInterface.

private static TransformationMetadata queryMetadataInterface() {
    try {
        ModelMetaData mmd = new ModelMetaData();
        mmd.setName("couchbase");
        CouchbaseMetadataProcessor mp = new CouchbaseMetadataProcessor();
        MetadataFactory mf = new MetadataFactory("couchbase", 1, SystemMetadata.getInstance().getRuntimeTypeMap(), mmd);
        Table customer = createTable(mf, KEYSPACE, "Customer");
        mp.scanRow(KEYSPACE, KEYSPACE_SOURCE, formCustomer(), mf, customer, customer.getName(), false, new Dimension());
        Table order = createTable(mf, KEYSPACE, "Oder");
        mp.scanRow(KEYSPACE, KEYSPACE_SOURCE, formOder(), mf, order, order.getName(), false, new Dimension());
        Table t2 = createTable(mf, "T2", "T2");
        mp.scanRow("T2", "`T2`", formDataTypeJson(), mf, t2, t2.getName(), false, new Dimension());
        Table t3 = createTable(mf, "T3", "T3");
        mp.scanRow("T3", "`T3`", nestedJson(), mf, t3, t3.getName(), false, new Dimension());
        mp.scanRow("T3", "`T3`", nestedArray(), mf, t3, t3.getName(), false, new Dimension());
        mp.addProcedures(mf, null);
        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 e) {
        throw new RuntimeException(e);
    }
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Table(org.teiid.metadata.Table) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) TestCouchbaseMetadataProcessor(org.teiid.translator.couchbase.TestCouchbaseMetadataProcessor) MetadataValidator(org.teiid.query.metadata.MetadataValidator) Dimension(org.teiid.translator.couchbase.CouchbaseMetadataProcessor.Dimension) ValidatorReport(org.teiid.query.validator.ValidatorReport) MetadataException(org.teiid.metadata.MetadataException) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 32 with ValidatorReport

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

the class TestProcessor method helpGetPlan.

public static ProcessorPlan helpGetPlan(Command command, QueryMetadataInterface metadata, CapabilitiesFinder capFinder, CommandContext context) throws TeiidException {
    // $NON-NLS-1$
    if (DEBUG)
        System.out.println("\n####################################\n" + command);
    AnalysisRecord analysisRecord = new AnalysisRecord(false, DEBUG);
    if (!(metadata instanceof TempMetadataAdapter)) {
        metadata = new TempMetadataAdapter(metadata, new TempMetadataStore());
    }
    context.setMetadata(metadata);
    try {
        QueryResolver.resolveCommand(command, metadata);
        ValidatorReport repo = Validator.validate(command, metadata);
        Collection failures = new ArrayList();
        repo.collectInvalidObjects(failures);
        if (failures.size() > 0) {
            // $NON-NLS-1$
            throw new QueryValidatorException("Exception during validation:" + repo);
        }
        command = QueryRewriter.rewrite(command, metadata, context);
        ProcessorPlan process = QueryOptimizer.optimizePlan(command, metadata, null, capFinder, analysisRecord, context);
        // $NON-NLS-1$
        if (DEBUG)
            System.out.println("\n" + process);
        // per defect 10022, clone this plan before processing, just to make sure
        // a cloned plan with correlated subquery references (or any cloned plan) can be processed
        process = process.clone();
        // $NON-NLS-1$
        assertNotNull("Output elements of process plan are null", process.getOutputElements());
        return process;
    } finally {
        if (DEBUG) {
            System.out.println(analysisRecord.getDebugLog());
        }
    }
}
Also used : TempMetadataAdapter(org.teiid.query.metadata.TempMetadataAdapter) AnalysisRecord(org.teiid.query.analysis.AnalysisRecord) QueryValidatorException(org.teiid.api.exception.query.QueryValidatorException) TempMetadataStore(org.teiid.query.metadata.TempMetadataStore) ValidatorReport(org.teiid.query.validator.ValidatorReport)

Example 33 with ValidatorReport

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

the class TestPhoenixUtil method queryMetadataInterface.

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

Example 34 with ValidatorReport

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

the class TestDDLParser method testOptionalFKFail.

@Test
public void testOptionalFKFail() throws Exception {
    String ddl = "CREATE FOREIGN TABLE G1(g1e1 integer, g1e2 varchar);\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());
    assertTrue(report.hasItems());
}
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 35 with ValidatorReport

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

Aggregations

ValidatorReport (org.teiid.query.validator.ValidatorReport)70 Test (org.junit.Test)40 MetadataValidator (org.teiid.query.metadata.MetadataValidator)20 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)16 MetadataFactory (org.teiid.metadata.MetadataFactory)13 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)12 UDFSource (org.teiid.query.function.UDFSource)11 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)10 FunctionTree (org.teiid.query.function.FunctionTree)10 Command (org.teiid.query.sql.lang.Command)8 ValidatorFailure (org.teiid.query.validator.ValidatorFailure)6 QueryParser (org.teiid.query.parser.QueryParser)5 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)5 FileReader (java.io.FileReader)4 Properties (java.util.Properties)4 EdmxFormatParser (org.odata4j.format.xml.EdmxFormatParser)4 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)4 TranslationUtility (org.teiid.cdk.api.TranslationUtility)4 MetadataException (org.teiid.metadata.MetadataException)4 Table (org.teiid.metadata.Table)4