use of org.teiid.api.exception.query.QueryResolverException in project teiid by teiid.
the class ExecResolver method resolveProceduralCommand.
/**
* @see org.teiid.query.resolver.ProcedureContainerResolver#resolveProceduralCommand(org.teiid.query.sql.lang.Command, org.teiid.query.metadata.TempMetadataAdapter)
*/
public void resolveProceduralCommand(Command command, TempMetadataAdapter metadata) throws QueryMetadataException, QueryResolverException, TeiidComponentException {
findCommandMetadata(command, metadata.getMetadataStore(), metadata);
// Resolve expressions on input parameters
StoredProcedure storedProcedureCommand = (StoredProcedure) command;
GroupContext externalGroups = storedProcedureCommand.getExternalGroupContexts();
for (SPParameter param : storedProcedureCommand.getParameters()) {
Expression expr = param.getExpression();
if (expr == null) {
continue;
}
for (SubqueryContainer<?> container : ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(expr)) {
QueryResolver.setChildMetadata(container.getCommand(), command);
QueryResolver.resolveCommand(container.getCommand(), metadata.getMetadata());
}
try {
ResolverVisitor.resolveLanguageObject(expr, null, externalGroups, metadata);
} catch (QueryResolverException e) {
if (!checkForArray(param, expr)) {
throw e;
}
continue;
}
Class<?> paramType = param.getClassType();
ResolverUtil.setDesiredType(expr, paramType, storedProcedureCommand);
// Compare type of parameter expression against parameter type
// and add implicit conversion if necessary
Class<?> exprType = expr.getType();
if (paramType == null || exprType == null) {
throw new QueryResolverException(QueryPlugin.Event.TEIID30143, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30143, storedProcedureCommand.getProcedureName(), param.getName()));
}
String tgtType = DataTypeManager.getDataTypeName(paramType);
String srcType = DataTypeManager.getDataTypeName(exprType);
Expression result = null;
if (param.getParameterType() == SPParameter.RETURN_VALUE || param.getParameterType() == SPParameter.OUT) {
if (!ResolverUtil.canImplicitlyConvert(tgtType, srcType)) {
throw new QueryResolverException(QueryPlugin.Event.TEIID30144, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30144, param.getParameterSymbol(), tgtType, srcType));
}
} else {
try {
result = ResolverUtil.convertExpression(expr, tgtType, metadata);
} catch (QueryResolverException e) {
throw new QueryResolverException(QueryPlugin.Event.TEIID30145, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30145, new Object[] { param.getParameterSymbol(), srcType, tgtType }));
}
param.setExpression(result);
}
}
}
use of org.teiid.api.exception.query.QueryResolverException in project teiid by teiid.
the class SetQueryResolver method setProjectedTypes.
private void setProjectedTypes(SetQuery setQuery, List<Class<?>> firstProjectTypes, QueryMetadataInterface metadata) throws QueryResolverException {
for (QueryCommand subCommand : setQuery.getQueryCommands()) {
if (!(subCommand instanceof SetQuery)) {
continue;
}
SetQuery child = (SetQuery) subCommand;
List projectedSymbols = child.getProjectedSymbols();
if (child.getOrderBy() != null) {
for (int j = 0; j < projectedSymbols.size(); j++) {
Expression ses = (Expression) projectedSymbols.get(j);
Class<?> targetType = firstProjectTypes.get(j);
if (ses.getType() != targetType && orderByContainsVariable(child.getOrderBy(), ses, j)) {
String sourceTypeName = DataTypeManager.getDataTypeName(ses.getType());
String targetTypeName = DataTypeManager.getDataTypeName(targetType);
throw new QueryResolverException(// $NON-NLS-1$
QueryPlugin.Util.getString(// $NON-NLS-1$
"UnionQueryResolver.type_conversion", new Object[] { ses, sourceTypeName, targetTypeName }));
}
}
}
child.setProjectedTypes(firstProjectTypes, metadata);
setProjectedTypes(child, firstProjectTypes, metadata);
}
}
use of org.teiid.api.exception.query.QueryResolverException in project teiid by teiid.
the class SimpleQueryResolver method resolveWith.
static void resolveWith(TempMetadataAdapter metadata, QueryCommand query) throws QueryResolverException, TeiidComponentException {
if (query.getWith() == null) {
return;
}
LinkedHashSet<GroupSymbol> discoveredGroups = new LinkedHashSet<GroupSymbol>();
for (WithQueryCommand obj : query.getWith()) {
QueryCommand queryExpression = obj.getCommand();
QueryResolver.setChildMetadata(queryExpression, query);
QueryCommand recursive = null;
try {
QueryResolver.resolveCommand(queryExpression, metadata.getMetadata(), false);
} catch (QueryResolverException e) {
if (!(queryExpression instanceof SetQuery)) {
throw e;
}
SetQuery setQuery = (SetQuery) queryExpression;
// valid form must be a union with nothing above
if (setQuery.getOperation() != Operation.UNION || setQuery.getLimit() != null || setQuery.getOrderBy() != null || setQuery.getOption() != null) {
throw e;
}
QueryResolver.resolveCommand(setQuery.getLeftQuery(), metadata.getMetadata(), false);
recursive = setQuery.getRightQuery();
}
if (!discoveredGroups.add(obj.getGroupSymbol())) {
throw new QueryResolverException(QueryPlugin.Event.TEIID30101, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30101, obj.getGroupSymbol()));
}
List<? extends Expression> projectedSymbols = obj.getCommand().getProjectedSymbols();
if (obj.getColumns() != null && !obj.getColumns().isEmpty()) {
if (obj.getColumns().size() != projectedSymbols.size()) {
throw new QueryResolverException(QueryPlugin.Event.TEIID30102, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30102, obj.getGroupSymbol()));
}
Iterator<ElementSymbol> iter = obj.getColumns().iterator();
for (Expression singleElementSymbol : projectedSymbols) {
ElementSymbol es = iter.next();
es.setType(singleElementSymbol.getType());
}
projectedSymbols = obj.getColumns();
}
TempMetadataID id = ResolverUtil.addTempGroup(metadata, obj.getGroupSymbol(), projectedSymbols, true);
obj.getGroupSymbol().setMetadataID(metadata.getMetadataStore().getTempGroupID(obj.getGroupSymbol().getName()));
obj.getGroupSymbol().setIsTempTable(true);
List<GroupSymbol> groups = Collections.singletonList(obj.getGroupSymbol());
if (obj.getColumns() != null && !obj.getColumns().isEmpty()) {
for (Expression singleElementSymbol : projectedSymbols) {
ResolverVisitor.resolveLanguageObject(singleElementSymbol, groups, metadata);
}
}
if (obj.getColumns() != null && !obj.getColumns().isEmpty()) {
Iterator<ElementSymbol> iter = obj.getColumns().iterator();
for (TempMetadataID colid : id.getElements()) {
ElementSymbol es = iter.next();
es.setMetadataID(colid);
es.setGroupSymbol(obj.getGroupSymbol());
}
}
if (recursive != null) {
QueryResolver.setChildMetadata(recursive, query);
QueryResolver.resolveCommand(recursive, metadata.getMetadata(), false);
new SetQueryResolver().resolveSetQuery(metadata, false, (SetQuery) queryExpression, ((SetQuery) queryExpression).getLeftQuery(), recursive);
obj.setRecursive(true);
}
}
}
use of org.teiid.api.exception.query.QueryResolverException in project teiid by teiid.
the class TempTableResolver method resolveCommand.
/**
* @see org.teiid.query.resolver.CommandResolver#resolveCommand(org.teiid.query.sql.lang.Command, org.teiid.query.metadata.TempMetadataAdapter, boolean)
*/
public void resolveCommand(Command command, TempMetadataAdapter metadata, boolean resolveNullLiterals) throws QueryMetadataException, QueryResolverException, TeiidComponentException {
if (command.getType() == Command.TYPE_CREATE) {
Create create = (Create) command;
GroupSymbol group = create.getTable();
// assuming that all temp table creates are local, the user must use a local name
if (group.getName().indexOf(Symbol.SEPARATOR) != -1) {
throw new QueryResolverException(QueryPlugin.Event.TEIID30117, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30117, group.getName()));
}
// this will only check non-temp groups
Collection exitsingGroups = metadata.getMetadata().getGroupsForPartialName(group.getName());
if (!exitsingGroups.isEmpty()) {
throw new QueryResolverException(QueryPlugin.Event.TEIID30118, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30118, group.getName()));
}
if (metadata.getMetadata().hasProcedure(group.getName())) {
throw new QueryResolverException(QueryPlugin.Event.TEIID30118, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30118, group.getName()));
}
// now we will be more specific for temp groups
TempMetadataID id = metadata.getMetadataStore().getTempGroupID(group.getName());
if (id != null && !metadata.isTemporaryTable(id)) {
throw new QueryResolverException(QueryPlugin.Event.TEIID30118, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30118, group.getName()));
}
// if we get here then either the group does not exist or has already been defined as a temp table
// if it has been defined as a temp table, that's ok we'll use this as the new definition and throw an
// exception at runtime if the user has not dropped the previous table yet
TempMetadataID tempTable = ResolverUtil.addTempTable(metadata, group, create.getColumnSymbols());
ResolverUtil.resolveGroup(create.getTable(), metadata);
Set<GroupSymbol> groups = new HashSet<GroupSymbol>();
groups.add(create.getTable());
ResolverVisitor.resolveLanguageObject(command, groups, metadata);
addAdditionalMetadata(create, tempTable);
tempTable.setOriginalMetadataID(create.getTableMetadata());
if (create.getOn() != null) {
Object mid = null;
try {
mid = metadata.getModelID(create.getOn());
} catch (QueryMetadataException e) {
throw new QueryResolverException(QueryPlugin.Event.TEIID31134, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31134, create.getOn()));
}
if (mid != null && (metadata.isVirtualModel(mid) || !(mid instanceof Schema))) {
throw new QueryResolverException(QueryPlugin.Event.TEIID31135, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31135, create.getOn()));
}
create.getTableMetadata().setParent((Schema) mid);
tempTable.getTableData().setModel(mid);
}
} else if (command.getType() == Command.TYPE_DROP) {
ResolverUtil.resolveGroup(((Drop) command).getTable(), metadata);
}
}
use of org.teiid.api.exception.query.QueryResolverException in project teiid by teiid.
the class UpdateProcedureResolver method collectDeclareVariable.
private void collectDeclareVariable(DeclareStatement obj, GroupSymbol variables, TempMetadataAdapter metadata, GroupContext externalGroups) throws QueryResolverException, TeiidComponentException {
ElementSymbol variable = obj.getVariable();
String typeName = obj.getVariableType();
GroupSymbol gs = variable.getGroupSymbol();
if (gs == null) {
String outputName = variable.getShortName();
variable.setGroupSymbol(new GroupSymbol(ProcedureReservedWords.VARIABLES));
variable.setOutputName(outputName);
} else {
if (gs.getSchema() != null || !gs.getShortName().equalsIgnoreCase(ProcedureReservedWords.VARIABLES)) {
// $NON-NLS-1$
handleUnresolvableDeclaration(variable, QueryPlugin.Util.getString("ERR.015.010.0031", new Object[] { ProcedureReservedWords.VARIABLES, variable }));
}
}
boolean exists = false;
try {
ResolverVisitor.resolveLanguageObject(variable, null, externalGroups, metadata);
exists = true;
} catch (QueryResolverException e) {
// ignore, not already defined
}
if (exists) {
// $NON-NLS-1$
handleUnresolvableDeclaration(variable, QueryPlugin.Util.getString("ERR.015.010.0032", variable.getOutputName()));
}
boolean exception = typeName.equalsIgnoreCase(SQLConstants.NonReserved.EXCEPTION);
variable.setType(exception ? DataTypeManager.DefaultDataClasses.OBJECT : DataTypeManager.getDataTypeClass(typeName));
variable.setGroupSymbol(variables);
TempMetadataID id = new TempMetadataID(variable.getName(), exception ? Exception.class : variable.getType());
id.setUpdatable(true);
variable.setMetadataID(id);
// TODO: this will cause the variables group to loose it's cache of resolved symbols
metadata.getMetadataStore().addElementToTempGroup(ProcedureReservedWords.VARIABLES, variable.clone());
}
Aggregations