use of org.teiid.query.sql.lang.Select in project teiid by teiid.
the class TestSetQueryParsing method testMultipleValues.
@Test
public void testMultipleValues() {
SetQuery setQuery = new SetQuery(Operation.UNION);
setQuery.setAll(true);
Select select = new Select();
// $NON-NLS-1$
select.addSymbol(new ElementSymbol("c1"));
Query query = new Query();
query.setSelect(select);
setQuery.setLeftQuery(query);
select = new Select();
// $NON-NLS-1$
select.addSymbol(new ElementSymbol("c2"));
query = new Query();
query.setSelect(select);
setQuery.setRightQuery(query);
// $NON-NLS-1$
TestParser.helpTest(// $NON-NLS-1$
"values (c1), (c2)", // $NON-NLS-1$
"SELECT c1 UNION ALL SELECT c2", setQuery);
}
use of org.teiid.query.sql.lang.Select in project teiid by teiid.
the class TestSetQueryParsing method testThreeUnions.
/**
* select c1 from g1 union select c2 from g2 union all select c3 from g3 union select c4 from g4
*/
@Test
public void testThreeUnions() {
SetQuery setQuery = new SetQuery(Operation.UNION);
setQuery.setAll(false);
// $NON-NLS-1$
GroupSymbol g = new GroupSymbol("g1");
From from = new From();
from.addGroup(g);
Select select = new Select();
// $NON-NLS-1$
select.addSymbol(new ElementSymbol("c1"));
Query query = new Query();
query.setSelect(select);
query.setFrom(from);
setQuery.setLeftQuery(query);
// $NON-NLS-1$
g = new GroupSymbol("g2");
from = new From();
from.addGroup(g);
select = new Select();
// $NON-NLS-1$
select.addSymbol(new ElementSymbol("c2"));
query = new Query();
query.setSelect(select);
query.setFrom(from);
setQuery.setRightQuery(query);
// $NON-NLS-1$
g = new GroupSymbol("g3");
from = new From();
from.addGroup(g);
select = new Select();
// $NON-NLS-1$
select.addSymbol(new ElementSymbol("c3"));
query = new Query();
query.setSelect(select);
query.setFrom(from);
setQuery = new SetQuery(SetQuery.Operation.UNION, true, setQuery, query);
// $NON-NLS-1$
g = new GroupSymbol("g4");
from = new From();
from.addGroup(g);
select = new Select();
// $NON-NLS-1$
select.addSymbol(new ElementSymbol("c4"));
query = new Query();
query.setSelect(select);
query.setFrom(from);
setQuery = new SetQuery(SetQuery.Operation.UNION, false, setQuery, query);
// $NON-NLS-1$
TestParser.helpTest(// $NON-NLS-1$
"select c1 from g1 union select c2 from g2 union all select c3 from g3 union select c4 from g4", // $NON-NLS-1$
"SELECT c1 FROM g1 UNION SELECT c2 FROM g2 UNION ALL SELECT c3 FROM g3 UNION SELECT c4 FROM g4", setQuery);
}
use of org.teiid.query.sql.lang.Select in project teiid by teiid.
the class CommandBuilder method expandAllSymbol.
/**
* Convert the "*" in "select * from..." to the list of column names for the data source.
*/
protected void expandAllSymbol(Command command) {
if (command instanceof Query) {
Query query = (Query) command;
Select select = query.getSelect();
List<Expression> originalSymbols = select.getSymbols();
List<Expression> expandedSymbols = new ArrayList<Expression>();
for (Iterator<Expression> i = originalSymbols.iterator(); i.hasNext(); ) {
Expression next = i.next();
if (next instanceof MultipleElementSymbol) {
MultipleElementSymbol allSymbol = (MultipleElementSymbol) next;
expandedSymbols.addAll(allSymbol.getElementSymbols());
} else {
expandedSymbols.add(next);
}
}
select.setSymbols(expandedSymbols);
}
}
use of org.teiid.query.sql.lang.Select in project teiid by teiid.
the class XMLQueryVisitationStrategy method produceMsg.
/**
* Produce a JDOM Element for an instance of a JDBC ResultSet object.
* <br>
* @param object for which the JDOM Element is to be produced.
* @return the JDOM element of the results object that was converted to XML.
* @exception JDOMException if there is an error producing XML.
* @exception SQLException if there is an error walking through the ResultSet object.
*/
public Element produceMsg(ResultSet object, Element resultsElement) throws JDOMException, SQLException {
// -----------------------------------
try {
ResultSetMetaData rmdata = object.getMetaData();
List identList = new ArrayList(rmdata.getColumnCount());
for (int i = 1; i <= rmdata.getColumnCount(); i++) {
identList.add(new ElementSymbol(rmdata.getColumnName(i)));
}
Select select = new Select(identList);
resultsElement = produceMsg(select, rmdata, resultsElement);
// -------------------------
// Add the Table element ...
// -------------------------
resultsElement.addContent(new Element(TagNames.Elements.TABLE));
Element tableElement = resultsElement.getChild(TagNames.Elements.TABLE);
int rowCount = 0;
int colCount = rmdata.getColumnCount();
while (object.next()) {
// -------------------------
// Add the ROW element ...
// -------------------------
Element rowElement = new Element(TagNames.Elements.TABLE_ROW);
for (int i = 1; i <= colCount; i++) {
// -------------------------
// Add the Cell element ...
// -------------------------
Element cellElement = new Element(TagNames.Elements.TABLE_CELL);
Object cellValue = object.getObject(i);
if (cellValue != null) {
cellElement = produceMsg(cellValue, cellElement);
} else {
cellElement = cellElement.addContent(TagNames.Elements.NULL);
}
rowElement.addContent(cellElement);
}
tableElement.addContent(rowElement);
rowCount++;
}
Attribute rowCountAttribute = new Attribute(TagNames.Attributes.TABLE_ROW_COUNT, Integer.toString(rowCount));
Attribute columnCountAttribute = new Attribute(TagNames.Attributes.TABLE_COLUMN_COUNT, Integer.toString(colCount));
tableElement.setAttribute(rowCountAttribute);
tableElement.setAttribute(columnCountAttribute);
} catch (SQLException e) {
// error while reading results
throw (e);
}
return resultsElement;
}
use of org.teiid.query.sql.lang.Select in project teiid by teiid.
the class RuleDecomposeJoin method buildUnion.
private PlanNode buildUnion(PlanNode unionNode, PlanNode otherSide, List<Criteria> criteria, List<int[]> matches, List<PlanNode> branches, List<PlanNode> otherBranches, JoinType joinType) {
SymbolMap symbolMap = (SymbolMap) unionNode.getParent().getProperty(Info.SYMBOL_MAP);
SymbolMap otherSymbolMap = (SymbolMap) otherSide.getProperty(Info.SYMBOL_MAP);
List<PlanNode> joins = new LinkedList<PlanNode>();
for (int i = 0; i < matches.size(); i++) {
int[] is = matches.get(i);
PlanNode branch = branches.get(is[0]);
PlanNode branchSource = createSource(unionNode.getParent().getGroups().iterator().next(), branch, symbolMap);
PlanNode otherBranch = otherBranches.get(is[1]);
PlanNode otherBranchSource = createSource(otherSide.getGroups().iterator().next(), otherBranch, otherSymbolMap);
PlanNode newJoinNode = NodeFactory.getNewNode(NodeConstants.Types.JOIN);
newJoinNode.addLastChild(branchSource);
newJoinNode.addLastChild(otherBranchSource);
newJoinNode.setProperty(Info.JOIN_STRATEGY, JoinStrategyType.NESTED_LOOP);
newJoinNode.setProperty(Info.JOIN_TYPE, joinType);
newJoinNode.setProperty(Info.JOIN_CRITERIA, LanguageObject.Util.deepClone(criteria, Criteria.class));
newJoinNode.addGroups(branchSource.getGroups());
newJoinNode.addGroups(otherBranchSource.getGroups());
PlanNode projectPlanNode = NodeFactory.getNewNode(NodeConstants.Types.PROJECT);
newJoinNode.addAsParent(projectPlanNode);
Select allSymbols = new Select(symbolMap.getKeys());
allSymbols.addSymbols(otherSymbolMap.getKeys());
if (i == 0) {
QueryRewriter.makeSelectUnique(allSymbols, false);
}
projectPlanNode.setProperty(NodeConstants.Info.PROJECT_COLS, allSymbols.getSymbols());
projectPlanNode.addGroups(newJoinNode.getGroups());
joins.add(projectPlanNode);
}
PlanNode newUnion = RulePlanUnions.buildUnionTree(unionNode, joins);
return newUnion;
}
Aggregations