Search in sources :

Example 6 with QueryParser

use of org.teiid.query.parser.QueryParser 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 7 with QueryParser

use of org.teiid.query.parser.QueryParser in project teiid by teiid.

the class TestValidator method testDefect21389.

@Test
public void testDefect21389() throws Exception {
    // $NON-NLS-1$
    String sql = "CREATE VIRTUAL PROCEDURE BEGIN SELECT * INTO #temptable FROM pm1.g1; INSERT INTO #temptable (e1) VALUES ('a'); END";
    TransformationMetadata metadata = RealMetadataFactory.example1();
    // $NON-NLS-1$
    Column c = metadata.getElementID("pm1.g1.e1");
    c.setUpdatable(false);
    Command command = new QueryParser().parseCommand(sql);
    QueryResolver.resolveCommand(command, metadata);
    // Validate
    ValidatorReport report = Validator.validate(command, metadata);
    // Validate
    assertEquals(0, report.getItems().size());
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) QueryParser(org.teiid.query.parser.QueryParser) Column(org.teiid.metadata.Column) Command(org.teiid.query.sql.lang.Command) Test(org.junit.Test)

Example 8 with QueryParser

use of org.teiid.query.parser.QueryParser in project teiid by teiid.

the class AbstractVDBDeployer method createMetadataFactory.

protected MetadataFactory createMetadataFactory(VDBMetaData vdb, MetadataStore store, ModelMetaData model, Map<String, ? extends VDBResource> vdbResources) {
    Map<String, Datatype> datatypes = store.getDatatypes();
    MetadataFactory factory = new MetadataFactory(vdb.getName(), vdb.getVersion(), datatypes, model);
    factory.getSchema().setPhysical(model.isSource());
    // for thread safety each factory gets it's own instance.
    factory.setParser(new QueryParser());
    factory.setVdbResources(vdbResources);
    return factory;
}
Also used : QueryParser(org.teiid.query.parser.QueryParser) MetadataFactory(org.teiid.metadata.MetadataFactory) Datatype(org.teiid.metadata.Datatype)

Example 9 with QueryParser

use of org.teiid.query.parser.QueryParser 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 10 with QueryParser

use of org.teiid.query.parser.QueryParser 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)

Aggregations

QueryParser (org.teiid.query.parser.QueryParser)18 Command (org.teiid.query.sql.lang.Command)10 Test (org.junit.Test)7 MetadataFactory (org.teiid.metadata.MetadataFactory)6 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)6 ValidatorReport (org.teiid.query.validator.ValidatorReport)5 FileReader (java.io.FileReader)4 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)4 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)4 MetadataValidator (org.teiid.query.metadata.MetadataValidator)3 CreateProcedureCommand (org.teiid.query.sql.proc.CreateProcedureCommand)3 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)3 ArrayList (java.util.ArrayList)2 QueryParserException (org.teiid.api.exception.query.QueryParserException)2 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)2 QueryValidatorException (org.teiid.api.exception.query.QueryValidatorException)2 Column (org.teiid.metadata.Column)2 MetadataException (org.teiid.metadata.MetadataException)2 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)2 FileNotFoundException (java.io.FileNotFoundException)1