Search in sources :

Example 21 with TempMetadataStore

use of org.teiid.query.metadata.TempMetadataStore in project teiid by teiid.

the class TestResolver method testInsertWithNullLiteral.

@Test
public void testInsertWithNullLiteral() {
    // $NON-NLS-1$
    String sql = "insert into #temp (x) values (null)";
    Insert insert = (Insert) helpResolve(sql);
    TempMetadataStore store = insert.getTemporaryMetadata();
    // $NON-NLS-1$
    TempMetadataID id = store.getTempElementID("#temp.x");
    assertEquals(DataTypeManager.DefaultDataClasses.STRING, id.getType());
}
Also used : TempMetadataID(org.teiid.query.metadata.TempMetadataID) TempMetadataStore(org.teiid.query.metadata.TempMetadataStore) Test(org.junit.Test)

Example 22 with TempMetadataStore

use of org.teiid.query.metadata.TempMetadataStore in project teiid by teiid.

the class QueryRewriter method createInlineViewQuery.

public static Query createInlineViewQuery(GroupSymbol inlineGroup, Command nested, QueryMetadataInterface metadata, List<? extends Expression> actualSymbols) throws QueryMetadataException, QueryResolverException, TeiidComponentException {
    Query query = new Query();
    Select select = new Select();
    query.setSelect(select);
    From from = new From();
    from.addClause(new UnaryFromClause(inlineGroup));
    TempMetadataStore store = new TempMetadataStore();
    TempMetadataAdapter tma = new TempMetadataAdapter(metadata, store);
    if (nested instanceof QueryCommand) {
        Query firstProject = ((QueryCommand) nested).getProjectedQuery();
        makeSelectUnique(firstProject.getSelect(), false);
    }
    TempMetadataID gid = store.addTempGroup(inlineGroup.getName(), nested.getProjectedSymbols());
    inlineGroup.setMetadataID(gid);
    List<Class<?>> actualTypes = new ArrayList<Class<?>>(nested.getProjectedSymbols().size());
    for (Expression ses : actualSymbols) {
        actualTypes.add(ses.getType());
    }
    List<Expression> selectSymbols = SetQuery.getTypedProjectedSymbols(ResolverUtil.resolveElementsInGroup(inlineGroup, tma), actualTypes, tma);
    Iterator<? extends Expression> iter = actualSymbols.iterator();
    for (Expression ses : selectSymbols) {
        ses = (Expression) ses.clone();
        Expression actual = iter.next();
        if (!Symbol.getShortName(ses).equals(Symbol.getShortName(actual))) {
            if (ses instanceof AliasSymbol) {
                ((AliasSymbol) ses).setShortName(Symbol.getShortName(actual));
            } else {
                ses = new AliasSymbol(Symbol.getShortName(actual), ses);
            }
        }
        select.addSymbol(ses);
    }
    query.setFrom(from);
    QueryResolver.resolveCommand(query, tma);
    query.setOption(nested.getOption() != null ? (Option) nested.getOption().clone() : null);
    from.getClauses().clear();
    SubqueryFromClause sqfc = new SubqueryFromClause(inlineGroup.getName());
    sqfc.setCommand(nested);
    sqfc.getGroupSymbol().setMetadataID(inlineGroup.getMetadataID());
    from.addClause(sqfc);
    // copy the metadata onto the new query so that temp metadata adapters will be used in later calls
    query.getTemporaryMetadata().getData().putAll(store.getData());
    return query;
}
Also used : TempMetadataAdapter(org.teiid.query.metadata.TempMetadataAdapter) TempMetadataID(org.teiid.query.metadata.TempMetadataID) TempMetadataStore(org.teiid.query.metadata.TempMetadataStore)

Example 23 with TempMetadataStore

use of org.teiid.query.metadata.TempMetadataStore in project teiid by teiid.

the class TestRulePushSelectCriteria method testPushAcrossFrameWithAccessNode.

@Test
public void testPushAcrossFrameWithAccessNode() throws Exception {
    QueryMetadataInterface metadata = new TempMetadataAdapter(RealMetadataFactory.example1Cached(), new TempMetadataStore());
    // $NON-NLS-1$
    Command command = TestOptimizer.helpGetCommand("select * from (select * from pm1.g1 union select * from pm1.g2) x where e1 = 1", metadata, null);
    // $NON-NLS-1$
    Command subCommand = TestOptimizer.helpGetCommand("select * from pm1.g1 union select * from pm1.g2", metadata, null);
    RelationalPlanner p = new RelationalPlanner();
    CommandContext cc = new CommandContext();
    p.initialize(command, null, metadata, null, null, cc);
    PlanNode root = p.generatePlan(command);
    PlanNode child = p.generatePlan(subCommand);
    PlanNode sourceNode = NodeEditor.findNodePreOrder(root, NodeConstants.Types.SOURCE);
    sourceNode.addFirstChild(child);
    sourceNode.setProperty(NodeConstants.Info.SYMBOL_MAP, SymbolMap.createSymbolMap(sourceNode.getGroups().iterator().next(), (List<Expression>) child.getFirstChild().getProperty(Info.PROJECT_COLS), metadata));
    // add a dummy access node
    PlanNode accessNode = NodeFactory.getNewNode(NodeConstants.Types.ACCESS);
    accessNode.addGroups(child.getFirstChild().getGroups());
    child.getFirstChild().addAsParent(accessNode);
    new RulePushSelectCriteria().execute(root, metadata, new DefaultCapabilitiesFinder(), new RuleStack(), AnalysisRecord.createNonRecordingRecord(), cc);
    // the select node should still be above the access node
    accessNode = NodeEditor.findNodePreOrder(root, NodeConstants.Types.ACCESS);
    assertEquals(NodeConstants.Types.SELECT, accessNode.getParent().getType());
    assertNull(NodeEditor.findNodePreOrder(accessNode, NodeConstants.Types.SELECT));
}
Also used : TempMetadataAdapter(org.teiid.query.metadata.TempMetadataAdapter) RelationalPlanner(org.teiid.query.optimizer.relational.RelationalPlanner) PlanNode(org.teiid.query.optimizer.relational.plantree.PlanNode) CommandContext(org.teiid.query.util.CommandContext) Command(org.teiid.query.sql.lang.Command) List(java.util.List) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) RuleStack(org.teiid.query.optimizer.relational.RuleStack) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) TempMetadataStore(org.teiid.query.metadata.TempMetadataStore) Test(org.junit.Test)

Example 24 with TempMetadataStore

use of org.teiid.query.metadata.TempMetadataStore in project teiid by teiid.

the class Validator method setTempMetadata.

private static void setTempMetadata(final QueryMetadataInterface metadata, final AbstractValidationVisitor visitor, LanguageObject obj) {
    if (obj instanceof Command) {
        Command command = (Command) obj;
        visitor.currentCommand = command;
        TempMetadataStore tempMetadata = command.getTemporaryMetadata();
        if (tempMetadata != null && !tempMetadata.getData().isEmpty()) {
            visitor.setMetadata(new TempMetadataAdapter(metadata, tempMetadata));
        }
    }
}
Also used : TempMetadataAdapter(org.teiid.query.metadata.TempMetadataAdapter) Command(org.teiid.query.sql.lang.Command) TempMetadataStore(org.teiid.query.metadata.TempMetadataStore)

Example 25 with TempMetadataStore

use of org.teiid.query.metadata.TempMetadataStore in project teiid by teiid.

the class RulePushAggregates method defineNewGroup.

static List<ElementSymbol> defineNewGroup(GroupSymbol group, List<? extends Expression> virtualElements, QueryMetadataInterface metadata) throws TeiidComponentException, QueryMetadataException {
    TempMetadataStore store = new TempMetadataStore();
    TempMetadataAdapter tma = new TempMetadataAdapter(metadata, store);
    try {
        group.setMetadataID(ResolverUtil.addTempGroup(tma, group, virtualElements, false));
    } catch (QueryResolverException e) {
        throw new TeiidComponentException(QueryPlugin.Event.TEIID30265, e);
    }
    List<ElementSymbol> projectedSymbols = ResolverUtil.resolveElementsInGroup(group, metadata);
    return projectedSymbols;
}
Also used : TempMetadataAdapter(org.teiid.query.metadata.TempMetadataAdapter) TeiidComponentException(org.teiid.core.TeiidComponentException) TempMetadataStore(org.teiid.query.metadata.TempMetadataStore) QueryResolverException(org.teiid.api.exception.query.QueryResolverException)

Aggregations

TempMetadataStore (org.teiid.query.metadata.TempMetadataStore)52 TempMetadataAdapter (org.teiid.query.metadata.TempMetadataAdapter)45 Test (org.junit.Test)33 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)32 Ignore (org.junit.Ignore)21 TempMetadataID (org.teiid.query.metadata.TempMetadataID)6 CommandContext (org.teiid.query.util.CommandContext)6 List (java.util.List)5 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)5 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)5 Command (org.teiid.query.sql.lang.Command)5 GroupContext (org.teiid.query.sql.lang.GroupContext)5 Expression (org.teiid.query.sql.symbol.Expression)5 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)5 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)4 ArrayList (java.util.ArrayList)3 TeiidProcessingException (org.teiid.core.TeiidProcessingException)3 AnalysisRecord (org.teiid.query.analysis.AnalysisRecord)3 CreateProcedureCommand (org.teiid.query.sql.proc.CreateProcedureCommand)3 LinkedList (java.util.LinkedList)2