Search in sources :

Example 1 with DynamicCommand

use of org.teiid.query.sql.lang.DynamicCommand 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 DynamicCommand

use of org.teiid.query.sql.lang.DynamicCommand in project teiid by teiid.

the class TestDynamicCommand method testClone1.

public void testClone1() {
    List symbols = new ArrayList();
    // $NON-NLS-1$
    ElementSymbol a1 = new ElementSymbol("a1");
    a1.setType(DataTypeManager.DefaultDataClasses.STRING);
    symbols.add(a1);
    DynamicCommand sqlCmd = new DynamicCommand();
    // $NON-NLS-1$
    Expression sql = new Constant("SELECT a1 FROM g WHERE a2 = 5");
    sqlCmd.setSql(sql);
    sqlCmd.setAsColumns(symbols);
    sqlCmd.setAsClauseSet(true);
    // $NON-NLS-1$
    sqlCmd.setIntoGroup(new GroupSymbol("#g"));
    UnitTestUtil.helpTestEquivalence(0, sqlCmd, sqlCmd.clone());
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) DynamicCommand(org.teiid.query.sql.lang.DynamicCommand) Expression(org.teiid.query.sql.symbol.Expression) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) List(java.util.List) SetClauseList(org.teiid.query.sql.lang.SetClauseList) ArrayList(java.util.ArrayList)

Example 3 with DynamicCommand

use of org.teiid.query.sql.lang.DynamicCommand in project teiid by teiid.

the class TestDynamicCommand method testUpdatingModelCount.

public void testUpdatingModelCount() {
    DynamicCommand sqlCmd = new DynamicCommand();
    sqlCmd.setUpdatingModelCount(1);
    assertEquals(1, sqlCmd.getUpdatingModelCount());
    sqlCmd.setUpdatingModelCount(3);
    assertEquals(2, sqlCmd.getUpdatingModelCount());
    sqlCmd.setUpdatingModelCount(-1);
    assertEquals(0, sqlCmd.getUpdatingModelCount());
}
Also used : DynamicCommand(org.teiid.query.sql.lang.DynamicCommand)

Example 4 with DynamicCommand

use of org.teiid.query.sql.lang.DynamicCommand in project teiid by teiid.

the class TestDynamicCommand method testClone2.

public void testClone2() {
    List symbols = new ArrayList();
    // $NON-NLS-1$
    ElementSymbol a1 = new ElementSymbol("a1");
    a1.setType(DataTypeManager.DefaultDataClasses.STRING);
    symbols.add(a1);
    // $NON-NLS-1$
    Expression sql = new Constant("SELECT * FROM g");
    SetClauseList using = new SetClauseList();
    using.addClause(a1, a1);
    // $NON-NLS-1$
    DynamicCommand sqlCmd = new DynamicCommand(sql, symbols, new GroupSymbol("#g"), using);
    UnitTestUtil.helpTestEquivalence(0, sqlCmd, sqlCmd.clone());
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) DynamicCommand(org.teiid.query.sql.lang.DynamicCommand) Expression(org.teiid.query.sql.symbol.Expression) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) List(java.util.List) SetClauseList(org.teiid.query.sql.lang.SetClauseList) ArrayList(java.util.ArrayList) SetClauseList(org.teiid.query.sql.lang.SetClauseList)

Example 5 with DynamicCommand

use of org.teiid.query.sql.lang.DynamicCommand in project teiid by teiid.

the class ProcedurePlanner method optimize.

/**
 * <p>Produce a ProcessorPlan for the CreateUpdateProcedureCommand on the current node
 * of the CommandTreeNode, the procedure plan construction involves using the child
 * processor plans.</p>
 * @param metadata source of metadata
 * @param debug whether or not to generate verbose debug output during planning
 * @return ProcessorPlan This processorPlan is a <code>ProcedurePlan</code>
 * @throws QueryPlannerException indicating a problem in planning
 * @throws QueryMetadataException indicating an exception in accessing the metadata
 * @throws TeiidComponentException indicating an unexpected exception
 */
public ProcessorPlan optimize(Command procCommand, IDGenerator idGenerator, QueryMetadataInterface metadata, CapabilitiesFinder capFinder, AnalysisRecord analysisRecord, CommandContext context) throws QueryPlannerException, QueryMetadataException, TeiidComponentException {
    boolean debug = analysisRecord.recordDebug();
    if (debug) {
        // $NON-NLS-1$
        analysisRecord.println("\n####################################################");
        // $NON-NLS-1$
        analysisRecord.println("PROCEDURE COMMAND: " + procCommand);
    }
    // $NON-NLS-1$
    CreateProcedureCommand cupc = Assertion.isInstanceOf(procCommand, CreateProcedureCommand.class, "Wrong command type");
    if (debug) {
        // $NON-NLS-1$
        analysisRecord.println("OPTIMIZING SUB-COMMANDS: ");
    }
    for (Command command : CommandCollectorVisitor.getCommands(procCommand)) {
        if (!(command instanceof DynamicCommand)) {
            command.setProcessorPlan(QueryOptimizer.optimizePlan(command, metadata, idGenerator, capFinder, analysisRecord, context));
        }
    }
    Block block = cupc.getBlock();
    Program programBlock = planBlock(cupc, block, metadata, debug, idGenerator, capFinder, analysisRecord, context);
    if (debug) {
        // $NON-NLS-1$
        analysisRecord.println("\n####################################################");
    }
    // create plan from program and initialized environment
    ProcedurePlan plan = new ProcedurePlan(programBlock);
    plan.setMetadata(metadata);
    plan.setOutputElements(cupc.getProjectedSymbols());
    if (debug) {
        // $NON-NLS-1$
        analysisRecord.println("####################################################");
        // $NON-NLS-1$
        analysisRecord.println("PROCEDURE PLAN :" + plan);
        // $NON-NLS-1$
        analysisRecord.println("####################################################");
    }
    return plan;
}
Also used : DynamicCommand(org.teiid.query.sql.lang.DynamicCommand) DynamicCommand(org.teiid.query.sql.lang.DynamicCommand) Command(org.teiid.query.sql.lang.Command)

Aggregations

DynamicCommand (org.teiid.query.sql.lang.DynamicCommand)8 List (java.util.List)5 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)5 Expression (org.teiid.query.sql.symbol.Expression)5 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)5 Constant (org.teiid.query.sql.symbol.Constant)4 ArrayList (java.util.ArrayList)3 Command (org.teiid.query.sql.lang.Command)3 SetClauseList (org.teiid.query.sql.lang.SetClauseList)3 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)2 TempMetadataStore (org.teiid.query.metadata.TempMetadataStore)2 StoredProcedure (org.teiid.query.sql.lang.StoredProcedure)2 Clob (java.sql.Clob)1 SQLException (java.sql.SQLException)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 Set (java.util.Set)1 QueryProcessingException (org.teiid.api.exception.query.QueryProcessingException)1 BlockedException (org.teiid.common.buffer.BlockedException)1