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