use of org.teiid.query.sql.lang.SetQuery in project teiid by teiid.
the class InsertResolver method resolveProceduralCommand.
/**
* Resolve an INSERT. Need to resolve elements, constants, types, etc.
* @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 {
// Cast to known type
Insert insert = (Insert) command;
if (insert.getValues() != null) {
QueryResolver.resolveSubqueries(command, metadata, null);
// variables and values must be resolved separately to account for implicitly defined temp groups
resolveList(insert.getValues(), metadata, insert.getExternalGroupContexts(), null);
}
boolean usingQuery = insert.getQueryExpression() != null;
// resolve subquery if there
if (usingQuery) {
QueryResolver.setChildMetadata(insert.getQueryExpression(), command);
QueryResolver.resolveCommand(insert.getQueryExpression(), metadata.getMetadata(), false);
}
Set<GroupSymbol> groups = new HashSet<GroupSymbol>();
groups.add(insert.getGroup());
// resolve any functions in the values
List values = insert.getValues();
if (usingQuery) {
values = insert.getQueryExpression().getProjectedSymbols();
}
if (insert.getVariables().isEmpty()) {
if (insert.getGroup().isResolved()) {
List<ElementSymbol> variables = ResolverUtil.resolveElementsInGroup(insert.getGroup(), metadata);
for (Iterator<ElementSymbol> i = variables.iterator(); i.hasNext(); ) {
insert.addVariable(i.next().clone());
}
} else {
for (int i = 0; i < values.size(); i++) {
if (usingQuery) {
Expression ses = (Expression) values.get(i);
ElementSymbol es = new ElementSymbol(Symbol.getShortName(ses));
es.setType(ses.getType());
insert.addVariable(es);
} else {
// $NON-NLS-1$
insert.addVariable(new ElementSymbol("expr" + i));
}
}
}
} else if (insert.getGroup().isResolved()) {
resolveVariables(metadata, insert, groups);
}
resolveTypes(insert, metadata, values, usingQuery);
if (usingQuery && insert.getQueryExpression() instanceof SetQuery) {
// now that the first branch is set, we need to make sure that all branches conform
QueryResolver.resolveCommand(insert.getQueryExpression(), metadata.getMetadata(), false);
resolveTypes(insert, metadata, values, usingQuery);
}
if (!insert.getGroup().isResolved()) {
// define the implicit temp group
ResolverUtil.resolveImplicitTempGroup(metadata, insert.getGroup(), insert.getVariables());
resolveVariables(metadata, insert, groups);
// ensure that the types match
resolveTypes(insert, metadata, values, usingQuery);
}
}
use of org.teiid.query.sql.lang.SetQuery 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.query.sql.lang.SetQuery in project teiid by teiid.
the class RelationalPlan method toString.
public String toString() {
StringBuilder sb = new StringBuilder();
if (this.with != null) {
sb.append(SQLConstants.Reserved.WITH);
for (WithQueryCommand withCommand : this.with) {
// $NON-NLS-1$
sb.append("\n");
sb.append(withCommand.getGroupSymbol());
if (withCommand.isRecursive()) {
// $NON-NLS-1$
sb.append(" anchor\n").append(((SetQuery) withCommand.getCommand()).getLeftQuery().getProcessorPlan());
// $NON-NLS-1$
sb.append("recursive\n").append(((SetQuery) withCommand.getCommand()).getRightQuery().getProcessorPlan());
} else {
// $NON-NLS-1$
sb.append("\n");
sb.append(withCommand.getCommand().getProcessorPlan());
}
}
// $NON-NLS-1$
sb.append("body\n");
}
sb.append(this.root.toString());
return sb.toString();
}
use of org.teiid.query.sql.lang.SetQuery in project teiid by teiid.
the class RelationalPlan method requiresTransaction.
@Override
public Boolean requiresTransaction(boolean transactionalReads) {
if (this.with != null) {
for (WithQueryCommand withCommand : this.with) {
if (withCommand.isRecursive()) {
SetQuery setQuery = (SetQuery) withCommand.getCommand();
Boolean leftRequires = setQuery.getLeftQuery().getProcessorPlan().requiresTransaction(transactionalReads);
Boolean rightRequires = setQuery.getLeftQuery().getProcessorPlan().requiresTransaction(transactionalReads);
if (!Boolean.FALSE.equals(leftRequires) || !Boolean.FALSE.equals(rightRequires)) {
return true;
}
} else {
Boolean requires = withCommand.getCommand().getProcessorPlan().requiresTransaction(transactionalReads);
if (!Boolean.FALSE.equals(requires)) {
return true;
}
}
}
}
return requiresTransaction(transactionalReads, root);
}
use of org.teiid.query.sql.lang.SetQuery in project teiid by teiid.
the class LanguageBridgeFactory method translate.
public org.teiid.language.Command translate(Command command) {
try {
if (command == null) {
return null;
}
if (command instanceof Query) {
Select result = translate((Query) command);
result.setDependentValues(this.dependentSets);
setProjected(result);
return result;
} else if (command instanceof SetQuery) {
org.teiid.language.SetQuery result = translate((SetQuery) command);
setProjected(result);
return result;
} else if (command instanceof Insert) {
return translate((Insert) command);
} else if (command instanceof Update) {
return translate((Update) command);
} else if (command instanceof Delete) {
return translate((Delete) command);
} else if (command instanceof StoredProcedure) {
return translate((StoredProcedure) command);
} else if (command instanceof BatchedUpdateCommand) {
return translate((BatchedUpdateCommand) command);
}
// $NON-NLS-1$
throw new AssertionError(command.getClass().getName() + " " + command);
} finally {
this.allValues.clear();
this.dependentSets = null;
this.valueIndex = 0;
}
}
Aggregations