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);
}
}
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());
}
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;
}
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);
}
}
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);
}
}
Aggregations