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