use of org.teiid.query.validator.ValidatorReport 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.validator.ValidatorReport in project teiid by teiid.
the class MetadataValidator method validateUpdatePlan.
private void validateUpdatePlan(ModelMetaData model, ValidatorReport report, QueryMetadataInterface metadata, Table t, String plan, int type) throws QueryParserException, QueryResolverException, TeiidComponentException {
Command command = parser.parseProcedure(plan, true);
validateNoReferences(command, report, model);
QueryResolver.resolveCommand(command, new GroupSymbol(t.getFullName()), type, metadata, false);
// determineDependencies(t, command); -- these should be tracked against triggers
ValidatorReport resolverReport = Validator.validate(command, metadata);
processReport(model, t, report, resolverReport);
}
use of org.teiid.query.validator.ValidatorReport in project teiid by teiid.
the class TestBatchedUpdatePlanner method helpGetCommands.
public static List<Command> helpGetCommands(String[] sql, QueryMetadataInterface md) throws TeiidComponentException, TeiidProcessingException {
// $NON-NLS-1$
if (DEBUG)
System.out.println("\n####################################\n" + sql);
List<Command> commands = new ArrayList<Command>(sql.length);
for (int i = 0; i < sql.length; i++) {
Command command = QueryParser.getQueryParser().parseCommand(sql[i]);
QueryResolver.resolveCommand(command, md);
ValidatorReport repo = Validator.validate(command, md);
Collection<LanguageObject> failures = new ArrayList<LanguageObject>();
repo.collectInvalidObjects(failures);
if (failures.size() > 0) {
// $NON-NLS-1$
fail("Exception during validation (" + repo);
}
command = QueryRewriter.rewrite(command, md, null);
commands.add(command);
}
return commands;
}
use of org.teiid.query.validator.ValidatorReport in project teiid by teiid.
the class TestMultiSourcePlanToProcessConverter method helpTestMultiSourcePlan.
public ProcessorPlan helpTestMultiSourcePlan(QueryMetadataInterface metadata, String userSql, String multiModel, int sourceCount, ProcessorDataManager dataMgr, List<?>[] expectedResults, VDBMetaData vdb, List<?> params, Options options, SourceCapabilities bsc) throws Exception {
Map<String, String> multiSourceModels = MultiSourceMetadataWrapper.getMultiSourceModels(vdb);
for (String model : multiSourceModels.keySet()) {
char sourceID = 'a';
// by default every model has one binding associated, but for multi-source there were none assigned.
ModelMetaData m = vdb.getModel(model);
int x = m.getSourceNames().size();
for (int i = x; i < sourceCount; i++, sourceID++) {
// $NON-NLS-1$ //$NON-NLS-2$
m.addSourceMapping("" + sourceID, "translator", null);
}
}
QueryMetadataInterface wrapper = new MultiSourceMetadataWrapper(metadata, multiSourceModels);
wrapper = new TempMetadataAdapter(wrapper, new TempMetadataStore());
DQPWorkContext workContext = RealMetadataFactory.buildWorkContext(wrapper, vdb);
AnalysisRecord analysis = new AnalysisRecord(DEBUG, DEBUG);
Command command = TestResolver.helpResolve(userSql, wrapper);
ValidatorReport report = Validator.validate(command, metadata);
if (report.hasItems()) {
fail(report.toString());
}
// Plan
command = QueryRewriter.rewrite(command, wrapper, null);
DefaultCapabilitiesFinder fakeFinder = new DefaultCapabilitiesFinder(bsc);
CapabilitiesFinder finder = new TempCapabilitiesFinder(fakeFinder);
IDGenerator idGenerator = new IDGenerator();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
CommandContext context = new CommandContext("test", "user", null, vdb.getName(), vdb.getVersion(), false);
context.setDQPWorkContext(workContext);
context.setOptions(options);
ProcessorPlan plan = QueryOptimizer.optimizePlan(command, wrapper, idGenerator, finder, analysis, context);
if (DEBUG) {
System.out.println(analysis.getDebugLog());
// $NON-NLS-1$
System.out.println("\nMultiSource Plan:");
System.out.println(plan);
}
if (params != null) {
TestProcessor.setParameterValues(params, command, context);
}
TestProcessor.helpProcess(plan, context, dataMgr, expectedResults);
return plan;
}
use of org.teiid.query.validator.ValidatorReport in project teiid by teiid.
the class TestMetadataValidator method testCreateTriggerFails.
@Test
public void testCreateTriggerFails() throws Exception {
String ddl = "create view g1 options (updatable true) AS select * from pm1.g1; " + "create trigger on g1 instead of update as for each row begin if (\"new\" is distinct from pm1.g1) select 1; END; ";
buildModel("pm1", true, this.vdb, this.store, "create foreign table g1(e1 integer, e2 varchar(12));");
buildModel("vm1", false, this.vdb, this.store, ddl);
buildTransformationMetadata();
ValidatorReport report = new MetadataValidator().validate(vdb, store);
assertTrue(printError(report), report.hasItems());
}
Aggregations