use of org.teiid.api.exception.query.QueryResolverException in project teiid by teiid.
the class QueryResolver method resolveView.
public static QueryNode resolveView(GroupSymbol virtualGroup, QueryNode qnode, String cacheString, QueryMetadataInterface qmi, boolean logValidation) throws TeiidComponentException, QueryMetadataException, QueryResolverException, QueryValidatorException {
qmi = qmi.getDesignTimeMetadata();
// $NON-NLS-1$
cacheString = "transformation/" + cacheString;
QueryNode cachedNode = (QueryNode) qmi.getFromMetadataCache(virtualGroup.getMetadataID(), cacheString);
if (cachedNode == null) {
Command result = qnode.getCommand();
List<String> bindings = null;
if (result == null) {
try {
result = QueryParser.getQueryParser().parseCommand(qnode.getQuery());
} catch (QueryParserException e) {
throw new QueryResolverException(QueryPlugin.Event.TEIID30065, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30065, virtualGroup));
}
bindings = qnode.getBindings();
} else {
result = (Command) result.clone();
}
if (bindings != null && !bindings.isEmpty()) {
QueryResolver.resolveWithBindingMetadata(result, qmi, qnode, true);
} else {
QueryResolver.resolveCommand(result, qmi, false);
}
Request.validateWithVisitor(new ValidationVisitor(), qmi, result);
validateProjectedSymbols(virtualGroup, qmi, result);
cachedNode = new QueryNode(qnode.getQuery());
cachedNode.setCommand(result);
if (isView(virtualGroup, qmi)) {
String updatePlan = qmi.getUpdatePlan(virtualGroup.getMetadataID());
String deletePlan = qmi.getDeletePlan(virtualGroup.getMetadataID());
String insertPlan = qmi.getInsertPlan(virtualGroup.getMetadataID());
// the elements must be against the view and not the alias
if (virtualGroup.getDefinition() != null) {
GroupSymbol group = new GroupSymbol(virtualGroup.getNonCorrelationName());
group.setMetadataID(virtualGroup.getMetadataID());
virtualGroup = group;
}
List<ElementSymbol> elements = ResolverUtil.resolveElementsInGroup(virtualGroup, qmi);
UpdateValidator validator = new UpdateValidator(qmi, determineType(insertPlan), determineType(updatePlan), determineType(deletePlan));
validator.validate(result, elements);
UpdateInfo info = validator.getUpdateInfo();
if (logValidation && qmi.groupSupports(virtualGroup.getMetadataID(), SupportConstants.Group.UPDATE)) {
if (info.isInherentInsert() && validator.getInsertReport().hasItems()) {
LogManager.logDetail(LogConstants.CTX_QUERY_RESOLVER, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31173, validator.getInsertReport().getFailureMessage(), SQLConstants.Reserved.INSERT, qmi.getFullName(virtualGroup.getMetadataID())));
}
if (info.isInherentUpdate() && validator.getUpdateReport().hasItems()) {
LogManager.logDetail(LogConstants.CTX_QUERY_RESOLVER, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31173, validator.getUpdateReport().getFailureMessage(), SQLConstants.Reserved.UPDATE, qmi.getFullName(virtualGroup.getMetadataID())));
}
if (info.isInherentDelete() && validator.getDeleteReport().hasItems()) {
LogManager.logDetail(LogConstants.CTX_QUERY_RESOLVER, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31173, validator.getDeleteReport().getFailureMessage(), SQLConstants.Reserved.DELETE, qmi.getFullName(virtualGroup.getMetadataID())));
}
}
cachedNode.setUpdateInfo(info);
}
qmi.addToMetadataCache(virtualGroup.getMetadataID(), cacheString, cachedNode);
}
return cachedNode;
}
use of org.teiid.api.exception.query.QueryResolverException in project teiid by teiid.
the class TestValidator method testDefect9917.
@Test
public void testDefect9917() throws Exception {
QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
// $NON-NLS-1$
String sql = "SELECT lookup('pm1.g1', 'e1a', 'e2', e2) AS x, lookup('pm1.g1', 'e4', 'e3', e3) AS y FROM pm1.g1";
Command command = new QueryParser().parseCommand(sql);
try {
QueryResolver.resolveCommand(command, metadata);
// $NON-NLS-1$
fail("Did not get exception");
} catch (QueryResolverException e) {
// expected
}
// $NON-NLS-1$
sql = "SELECT lookup('pm1.g1a', 'e1', 'e2', e2) AS x, lookup('pm1.g1', 'e4', 'e3', e3) AS y FROM pm1.g1";
command = new QueryParser().parseCommand(sql);
try {
QueryResolver.resolveCommand(command, metadata);
// $NON-NLS-1$
fail("Did not get exception");
} catch (QueryResolverException e) {
// expected
}
}
use of org.teiid.api.exception.query.QueryResolverException in project teiid by teiid.
the class TestResolver method testLookupFunctionFailBadKeyElement.
@Test
public void testLookupFunctionFailBadKeyElement() throws Exception {
// $NON-NLS-1$
String sql = "SELECT lookup('pm1.g1', 'e1', 'x', e2) AS x, lookup('pm1.g1', 'e4', 'e3', e3) AS y FROM pm1.g1";
Command command = QueryParser.getQueryParser().parseCommand(sql);
try {
QueryResolver.resolveCommand(command, metadata);
// $NON-NLS-1$
fail("exception expected");
} catch (QueryResolverException e) {
}
}
use of org.teiid.api.exception.query.QueryResolverException in project teiid by teiid.
the class TestFunctionResolving method testAmbiguousUDF.
@Test
public void testAmbiguousUDF() throws Exception {
TransformationMetadata tm = RealMetadataFactory.fromDDL("x", new DDLHolder("y", "create foreign function f () returns string"), new DDLHolder("z", "create foreign function f () returns string"));
String sql = "f()";
Function func = (Function) QueryParser.getQueryParser().parseExpression(sql);
try {
ResolverVisitor.resolveLanguageObject(func, tm);
fail();
} catch (QueryResolverException e) {
}
sql = "z.f()";
func = (Function) QueryParser.getQueryParser().parseExpression(sql);
ResolverVisitor.resolveLanguageObject(func, tm);
}
use of org.teiid.api.exception.query.QueryResolverException in project teiid by teiid.
the class TestResolver method testStoredQueryTransformationWithVariable4.
@Test
public void testStoredQueryTransformationWithVariable4() throws Exception {
// $NON-NLS-1$
Command command = QueryParser.getQueryParser().parseCommand("EXEC pm1.sq2(pm1.sq2.in)");
// resolve
try {
// Construct command metadata
// $NON-NLS-1$
GroupSymbol sqGroup = new GroupSymbol("pm1.sq5");
ArrayList sqParams = new ArrayList();
// $NON-NLS-1$
ElementSymbol in = new ElementSymbol("pm1.sq5.in1");
in.setType(DataTypeManager.DefaultDataClasses.STRING);
sqParams.add(in);
Map externalMetadata = new HashMap();
externalMetadata.put(sqGroup, sqParams);
QueryResolver.resolveCommand(command, metadata);
// $NON-NLS-1$
fail("Expected exception on invalid variable pm1.sq2.in");
} catch (QueryResolverException e) {
// $NON-NLS-1$
assertEquals("TEIID31119 Symbol pm1.sq2.\"in\" is specified with an unknown group context", e.getMessage());
}
}
Aggregations