use of org.teiid.query.sql.lang.SetClause in project teiid by teiid.
the class DynamicCommandResolver method resolveCommand.
/**
* @see org.teiid.query.resolver.CommandResolver#resolveCommand(org.teiid.query.sql.lang.Command, TempMetadataAdapter, boolean)
*/
public void resolveCommand(Command command, TempMetadataAdapter metadata, boolean resolveNullLiterals) throws QueryMetadataException, QueryResolverException, TeiidComponentException {
DynamicCommand dynamicCmd = (DynamicCommand) command;
Iterator columns = dynamicCmd.getAsColumns().iterator();
Set groups = new HashSet();
boolean resolvedColumns = false;
// if there is no into group, just create temp metadata ids
if (dynamicCmd.getIntoGroup() == null) {
while (columns.hasNext()) {
ElementSymbol column = (ElementSymbol) columns.next();
column.setMetadataID(new TempMetadataID(column.getShortName(), column.getType()));
}
} else if (dynamicCmd.getIntoGroup().isTempGroupSymbol()) {
resolvedColumns = true;
while (columns.hasNext()) {
ElementSymbol column = (ElementSymbol) columns.next();
column.setGroupSymbol(new GroupSymbol(dynamicCmd.getIntoGroup().getName()));
}
}
ResolverVisitor.resolveLanguageObject(dynamicCmd, groups, dynamicCmd.getExternalGroupContexts(), metadata);
String sqlType = DataTypeManager.getDataTypeName(dynamicCmd.getSql().getType());
String targetType = DataTypeManager.DefaultDataTypes.CLOB;
if (!targetType.equals(sqlType) && !DataTypeManager.isImplicitConversion(sqlType, targetType)) {
throw new QueryResolverException(QueryPlugin.Event.TEIID30100, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30100, sqlType));
}
dynamicCmd.setSql(ResolverUtil.convertExpression(dynamicCmd.getSql(), targetType, metadata));
if (dynamicCmd.getUsing() != null && !dynamicCmd.getUsing().isEmpty()) {
for (SetClause clause : dynamicCmd.getUsing().getClauses()) {
ElementSymbol id = clause.getSymbol();
id.setGroupSymbol(new GroupSymbol(ProcedureReservedWords.DVARS));
id.setType(clause.getValue().getType());
id.setMetadataID(new TempMetadataID(id.getName(), id.getType()));
}
}
GroupSymbol intoSymbol = dynamicCmd.getIntoGroup();
if (intoSymbol != null) {
if (!intoSymbol.isImplicitTempGroupSymbol()) {
ResolverUtil.resolveGroup(intoSymbol, metadata);
if (!resolvedColumns) {
// must be a temp table from a higher scope
for (ElementSymbol column : (List<ElementSymbol>) dynamicCmd.getAsColumns()) {
column.setGroupSymbol(dynamicCmd.getIntoGroup().clone());
}
}
} else {
List symbols = dynamicCmd.getAsColumns();
ResolverUtil.resolveImplicitTempGroup(metadata, intoSymbol, symbols);
}
}
}
use of org.teiid.query.sql.lang.SetClause in project teiid by teiid.
the class UpdateResolver 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 {
// Cast to known type
Update update = (Update) command;
// Resolve elements and functions
Set<GroupSymbol> groups = new HashSet<GroupSymbol>();
groups.add(update.getGroup());
for (SetClause clause : update.getChangeList().getClauses()) {
ResolverVisitor.resolveLanguageObject(clause.getSymbol(), groups, null, metadata);
}
QueryResolver.resolveSubqueries(command, metadata, groups);
ResolverVisitor.resolveLanguageObject(update, groups, update.getExternalGroupContexts(), metadata);
}
use of org.teiid.query.sql.lang.SetClause in project teiid by teiid.
the class ExecDynamicSqlInstruction method updateContextWithUsingValues.
/**
* @param procEnv
* @param localContext
* @throws TeiidComponentException
* @throws TeiidComponentException
* @throws TeiidProcessingException
*/
private void updateContextWithUsingValues(ProcedurePlan procEnv, VariableContext localContext) throws TeiidComponentException, TeiidProcessingException {
if (dynamicCommand.getUsing() != null && !dynamicCommand.getUsing().isEmpty()) {
for (SetClause setClause : dynamicCommand.getUsing().getClauses()) {
Object assignment = procEnv.evaluateExpression(setClause.getValue());
LogManager.logTrace(org.teiid.logging.LogConstants.CTX_DQP, new Object[] { // $NON-NLS-1$
this, // $NON-NLS-1$
" The using variable ", setClause.getSymbol(), " has value :", // $NON-NLS-1$
assignment });
localContext.setValue(setClause.getSymbol(), assignment);
ElementSymbol es = setClause.getSymbol().clone();
es.getGroupSymbol().setShortName(Reserved.USING);
localContext.setValue(es, assignment);
}
}
}
Aggregations