Search in sources :

Example 21 with TempMetadataAdapter

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

the class TestProcErrors method testNestedBeginAtomicException.

@Test
public void testNestedBeginAtomicException() throws Exception {
    TransformationMetadata tm = RealMetadataFactory.example1Cached();
    String query = "BEGIN atomic\n" + " declare string VARIABLES.RESULT;\n" + " begin atomic select 1/0; exception e end end";
    ProcessorPlan plan = getProcedurePlan(query, tm);
    // Create expected results
    List<?>[] expected = new List[0];
    // $NON-NLS-1$
    CommandContext context = new CommandContext("pID", null, null, null, 1);
    QueryMetadataInterface metadata = new TempMetadataAdapter(tm, new TempMetadataStore());
    context.setMetadata(metadata);
    TransactionContext tc = new TransactionContext();
    Transaction txn = Mockito.mock(Transaction.class);
    tc.setTransaction(txn);
    tc.setTransactionType(Scope.REQUEST);
    TransactionService ts = Mockito.mock(TransactionService.class);
    context.setTransactionService(ts);
    context.setTransactionContext(tc);
    TestProcessor.helpProcess(plan, context, new HardcodedDataManager(), expected);
    Mockito.verify(txn, Mockito.times(3)).setRollbackOnly();
}
Also used : TempMetadataAdapter(org.teiid.query.metadata.TempMetadataAdapter) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CommandContext(org.teiid.query.util.CommandContext) TransactionService(org.teiid.dqp.service.TransactionService) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) Transaction(javax.transaction.Transaction) TransactionContext(org.teiid.dqp.service.TransactionContext) List(java.util.List) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) TempMetadataStore(org.teiid.query.metadata.TempMetadataStore) Test(org.junit.Test)

Example 22 with TempMetadataAdapter

use of org.teiid.query.metadata.TempMetadataAdapter 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 TempMetadataAdapter

use of org.teiid.query.metadata.TempMetadataAdapter 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 TempMetadataAdapter

use of org.teiid.query.metadata.TempMetadataAdapter 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 TempMetadataAdapter

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

the class CommandContext method setNewVDBState.

public void setNewVDBState(DQPWorkContext newWorkContext) {
    this.vdbState = new VDBState();
    VDBMetaData vdb = newWorkContext.getVDB();
    GlobalTableStore actualGlobalStore = vdb.getAttachment(GlobalTableStore.class);
    this.vdbState.globalTables = actualGlobalStore;
    this.vdbState.session = newWorkContext.getSession();
    this.vdbState.classLoader = vdb.getAttachment(ClassLoader.class);
    this.vdbState.vdbName = vdb.getName();
    this.vdbState.vdbVersion = vdb.getVersion();
    this.vdbState.dqpWorkContext = newWorkContext;
    TempMetadataAdapter metadata = new TempMetadataAdapter(vdb.getAttachment(QueryMetadataInterface.class), globalState.sessionTempTableStore.getMetadataStore());
    metadata.setSession(true);
    this.vdbState.metadata = metadata;
}
Also used : TempMetadataAdapter(org.teiid.query.metadata.TempMetadataAdapter) GlobalTableStore(org.teiid.query.tempdata.GlobalTableStore) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface)

Aggregations

TempMetadataAdapter (org.teiid.query.metadata.TempMetadataAdapter)53 TempMetadataStore (org.teiid.query.metadata.TempMetadataStore)45 Test (org.junit.Test)32 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)32 Ignore (org.junit.Ignore)21 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)9 CommandContext (org.teiid.query.util.CommandContext)6 List (java.util.List)4 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)4 TempMetadataID (org.teiid.query.metadata.TempMetadataID)4 Command (org.teiid.query.sql.lang.Command)4 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)4 TeiidComponentException (org.teiid.core.TeiidComponentException)3 TeiidProcessingException (org.teiid.core.TeiidProcessingException)3 AnalysisRecord (org.teiid.query.analysis.AnalysisRecord)3 TempCapabilitiesFinder (org.teiid.query.metadata.TempCapabilitiesFinder)3 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)3 GroupContext (org.teiid.query.sql.lang.GroupContext)3 TempTableStore (org.teiid.query.tempdata.TempTableStore)3 ArrayList (java.util.ArrayList)2