use of org.teiid.query.sql.lang.UnaryFromClause in project teiid by teiid.
the class TestLimitParsing method testLimitWithReferences2.
@Test
public void testLimitWithReferences2() {
Query query = new Query();
Select select = new Select(Arrays.asList(new MultipleElementSymbol()));
// $NON-NLS-1$
From from = new From(Arrays.asList(new UnaryFromClause(new GroupSymbol("a"))));
query.setSelect(select);
query.setFrom(from);
query.setLimit(new Limit(new Constant(new Integer(50)), new Reference(0)));
// $NON-NLS-1$ //$NON-NLS-2$
helpTest("Select * from a limit 50,?", "SELECT * FROM a LIMIT 50, ?", query);
}
use of org.teiid.query.sql.lang.UnaryFromClause in project teiid by teiid.
the class TestLimitParsing method testFetchFirstRow.
@Test
public void testFetchFirstRow() {
Query query = new Query();
Select select = new Select(Arrays.asList(new MultipleElementSymbol()));
// $NON-NLS-1$
From from = new From(Arrays.asList(new UnaryFromClause(new GroupSymbol("a"))));
query.setSelect(select);
query.setFrom(from);
query.setLimit(new Limit(null, new Constant(1)));
// $NON-NLS-1$ //$NON-NLS-2$
helpTest("Select * from a fetch first row only", "SELECT * FROM a LIMIT 1", query);
}
use of org.teiid.query.sql.lang.UnaryFromClause in project teiid by teiid.
the class TestLimitParsing method testOffsetFetch.
@Test
public void testOffsetFetch() {
Query query = new Query();
Select select = new Select(Arrays.asList(new MultipleElementSymbol()));
// $NON-NLS-1$
From from = new From(Arrays.asList(new UnaryFromClause(new GroupSymbol("a"))));
query.setSelect(select);
query.setFrom(from);
query.setLimit(new Limit(new Constant(2), new Constant(5)));
// $NON-NLS-1$ //$NON-NLS-2$
helpTest("Select * from a offset 2 rows fetch first 5 rows only", "SELECT * FROM a LIMIT 2, 5", query);
}
use of org.teiid.query.sql.lang.UnaryFromClause in project teiid by teiid.
the class UpdateValidator method internalValidate.
private void internalValidate(Command command, List<ElementSymbol> viewSymbols) throws QueryMetadataException, TeiidComponentException {
if (!(command instanceof Query)) {
// $NON-NLS-1$
handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0001"), true, true, true);
return;
}
Query query = (Query) command;
if (query.getFrom() == null || query.getInto() != null) {
// $NON-NLS-1$
handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0001"), true, true, true);
return;
}
if (query.getWith() != null) {
// $NON-NLS-1$
String warning = QueryPlugin.Util.getString("ERR.015.012.0002");
updateReport.handleValidationWarning(warning);
deleteReport.handleValidationWarning(warning);
updateInfo.isSimple = false;
}
if (query.hasAggregates()) {
// $NON-NLS-1$
handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0006"), true, true, true);
return;
}
if (query.getLimit() != null) {
// $NON-NLS-1$
handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0013"), true, true, true);
return;
}
if (query.getSelect().isDistinct()) {
// $NON-NLS-1$
handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0008"), true, true, true);
return;
}
updateInfo.view = query;
List<Expression> projectedSymbols = query.getSelect().getProjectedSymbols();
for (int i = 0; i < projectedSymbols.size(); i++) {
Expression symbol = projectedSymbols.get(i);
Expression ex = SymbolMap.getExpression(symbol);
if (!metadata.elementSupports(viewSymbols.get(i).getMetadataID(), SupportConstants.Element.UPDATE)) {
continue;
}
if (ex instanceof ElementSymbol) {
ElementSymbol es = (ElementSymbol) ex;
String groupName = es.getGroupSymbol().getName();
UpdateMapping info = updateInfo.updatableGroups.get(groupName);
if (es.getGroupSymbol().getDefinition() != null) {
ElementSymbol clone = es.clone();
clone.setOutputName(null);
clone.getGroupSymbol().setName(clone.getGroupSymbol().getNonCorrelationName());
clone.getGroupSymbol().setDefinition(null);
es = clone;
}
if (info == null) {
info = new UpdateMapping();
info.group = es.getGroupSymbol();
info.correlatedName = ((ElementSymbol) ex).getGroupSymbol();
updateInfo.updatableGroups.put(groupName, info);
}
// TODO: warn if mapped twice
info.updatableViewSymbols.put(viewSymbols.get(i), es);
} else {
// TODO: look for reversable widening conversions
// $NON-NLS-1$
report.handleValidationWarning(QueryPlugin.Util.getString("ERR.015.012.0007", viewSymbols.get(i), symbol));
}
}
if (query.getFrom().getClauses().size() > 1 || (!(query.getFrom().getClauses().get(0) instanceof UnaryFromClause))) {
// $NON-NLS-1$
String warning = QueryPlugin.Util.getString("ERR.015.012.0009", query.getFrom());
updateReport.handleValidationWarning(warning);
deleteReport.handleValidationWarning(warning);
updateInfo.isSimple = false;
}
List<GroupSymbol> allGroups = query.getFrom().getGroups();
HashSet<GroupSymbol> keyPreservingGroups = new HashSet<GroupSymbol>();
ResolverUtil.findKeyPreserved(query, keyPreservingGroups, metadata);
for (GroupSymbol groupSymbol : keyPreservingGroups) {
setUpdateFlags(groupSymbol);
}
allGroups.removeAll(keyPreservingGroups);
if (updateInfo.isSimple) {
if (!allGroups.isEmpty()) {
setUpdateFlags(allGroups.iterator().next());
}
} else {
for (GroupSymbol groupSymbol : allGroups) {
UpdateMapping info = updateInfo.updatableGroups.get(groupSymbol.getName());
if (info == null) {
// not projected
continue;
}
// $NON-NLS-1$
String warning = QueryPlugin.Util.getString("ERR.015.012.0004", info.correlatedName);
report.handleValidationWarning(warning);
}
}
boolean updatable = false;
boolean insertable = false;
for (UpdateMapping info : updateInfo.updatableGroups.values()) {
if (info.updateAllowed) {
if (!updatable) {
this.updateInfo.deleteTarget = info;
} else if (!info.getGroup().equals(this.updateInfo.deleteTarget.getGroup())) {
// TODO: warning about multiple
this.updateInfo.deleteTarget = null;
}
}
updatable |= info.updateAllowed;
insertable |= info.insertAllowed;
}
if ((this.updateInfo.insertType == UpdateType.INHERENT && !insertable)) {
// $NON-NLS-1$
handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0015"), false, true, false);
}
if (this.updateInfo.updateType == UpdateType.INHERENT && !updatable) {
// $NON-NLS-1$
handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0005"), true, false, false);
}
if (this.updateInfo.deleteType == UpdateType.INHERENT) {
if (this.updateInfo.deleteTarget == null) {
if (this.updateInfo.isSimple && updatable) {
this.updateInfo.deleteTarget = this.updateInfo.updatableGroups.values().iterator().next();
} else {
// $NON-NLS-1$
handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0014"), false, false, true);
}
}
if (this.updateInfo.deleteTarget != null) {
GroupSymbol group = this.updateInfo.deleteTarget.group;
if (!this.updateInfo.isSimple && metadata.getPrimaryKey(group.getMetadataID()) == null && metadata.getUniqueKeysInGroup(group.getMetadataID()).isEmpty()) {
handleValidationError(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31267, viewSymbols.iterator().next().getGroupSymbol(), group), false, false, true);
}
}
}
}
use of org.teiid.query.sql.lang.UnaryFromClause in project teiid by teiid.
the class TestJoinImpl method helpExample.
public static JoinPredicate helpExample(JoinType type) {
// $NON-NLS-1$ //$NON-NLS-2$
ElementSymbol e1 = TestElementImpl.helpExample("vm1.g1", "e1");
// $NON-NLS-1$ //$NON-NLS-2$
ElementSymbol e2 = TestElementImpl.helpExample("vm1.g2", "e1");
ArrayList criteria = new ArrayList();
criteria.add(new CompareCriteria(e1, CompareCriteria.EQ, e2));
return new JoinPredicate(new UnaryFromClause(e1.getGroupSymbol()), new UnaryFromClause(e2.getGroupSymbol()), type, criteria);
}
Aggregations