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();
}
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;
}
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));
}
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));
}
}
}
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;
}
Aggregations