Search in sources :

Example 1 with SetClause

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);
        }
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) DynamicCommand(org.teiid.query.sql.lang.DynamicCommand) Set(java.util.Set) HashSet(java.util.HashSet) Iterator(java.util.Iterator) TempMetadataID(org.teiid.query.metadata.TempMetadataID) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) List(java.util.List) QueryResolverException(org.teiid.api.exception.query.QueryResolverException) HashSet(java.util.HashSet) SetClause(org.teiid.query.sql.lang.SetClause)

Example 2 with SetClause

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);
}
Also used : GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) Update(org.teiid.query.sql.lang.Update) HashSet(java.util.HashSet) SetClause(org.teiid.query.sql.lang.SetClause)

Example 3 with SetClause

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);
        }
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) SetClause(org.teiid.query.sql.lang.SetClause)

Aggregations

SetClause (org.teiid.query.sql.lang.SetClause)3 HashSet (java.util.HashSet)2 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)2 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)2 Iterator (java.util.Iterator)1 List (java.util.List)1 Set (java.util.Set)1 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)1 TempMetadataID (org.teiid.query.metadata.TempMetadataID)1 DynamicCommand (org.teiid.query.sql.lang.DynamicCommand)1 Update (org.teiid.query.sql.lang.Update)1