/** * Get hashcode for Select. WARNING: The hash code relies on the variables * in the select, so changing the variables will change the hash code, causing * a select to be lost in a hash structure. Do not hash a Select if you plan * to change it. * @return Hash code */ public int hashCode() { return HashCodeUtil.hashCode(0, getSymbols()); }
public void visit(Select obj) { List<Expression> symbols = obj.getSymbols(); for (int i = 0; i < symbols.size(); i++) { Expression symbol = symbols.get(i); if (symbol instanceof MultipleElementSymbol) { continue; } Expression replacmentSymbol = replaceSymbol(symbol, true); symbols.set(i, replacmentSymbol); } }
/** * Get hashcode for Select. WARNING: The hash code relies on the variables * in the select, so changing the variables will change the hash code, causing * a select to be lost in a hash structure. Do not hash a Select if you plan * to change it. * @return Hash code */ public int hashCode() { return HashCodeUtil.hashCode(0, getSymbols()); }
public void visit(Select obj) { List<Expression> symbols = obj.getSymbols(); for (int i = 0; i < symbols.size(); i++) { Expression symbol = symbols.get(i); if (symbol instanceof MultipleElementSymbol) { continue; } Expression replacmentSymbol = replaceSymbol(symbol, true); symbols.set(i, replacmentSymbol); } }
/** * Get hashcode for Select. WARNING: The hash code relies on the variables * in the select, so changing the variables will change the hash code, causing * a select to be lost in a hash structure. Do not hash a Select if you plan * to change it. * @return Hash code */ public int hashCode() { return HashCodeUtil.hashCode(0, getSymbols()); }
public void visit(Select obj) { List<Expression> symbols = obj.getSymbols(); for (int i = 0; i < symbols.size(); i++) { Expression symbol = symbols.get(i); if (symbol instanceof MultipleElementSymbol) { continue; } Expression replacmentSymbol = replaceSymbol(symbol, true); symbols.set(i, replacmentSymbol); } }
/** * Compare two Selects for equality. Order is important in the select (for * determining the order of the returned columns), so this is a compare * with order, not just a set comparison. * @param obj Other object * @return True if equal */ public boolean equals(Object obj) { if(obj == this) { return true; } if(!(obj instanceof Select)) { return false; } Select other = (Select) obj; return other.isDistinct() == isDistinct() && EquivalenceUtil.areEqual(getSymbols(), other.getSymbols()); }
public void visit(Select obj) { preVisitVisitor(obj); visitNodes(obj.getSymbols()); postVisitVisitor(obj); } public void visit(SetCriteria obj) {
public void visit(Select obj) { preVisitVisitor(obj); visitNodes(obj.getSymbols()); postVisitVisitor(obj); } public void visit(SetCriteria obj) {
public void visit(Select obj) { preVisitVisitor(obj); visitNodes(obj.getSymbols()); postVisitVisitor(obj); } public void visit(SetCriteria obj) {
@Override public void visit( Select obj ) { if (obj.isDistinct()) { append(SPACE); append(DISTINCT); } beginClause(2); Iterator<Expression> iter = obj.getSymbols().iterator(); while (iter.hasNext()) { Expression symbol = iter.next(); visitNode(symbol); if (iter.hasNext()) { append(", "); //$NON-NLS-1$ } } }
@Override public void visit( Select obj ) { if (obj.isDistinct()) { append(SPACE); append(DISTINCT); } beginClause(2); Iterator<Expression> iter = obj.getSymbols().iterator(); while (iter.hasNext()) { Expression symbol = iter.next(); visitNode(symbol); if (iter.hasNext()) { append(", "); //$NON-NLS-1$ } } }
@Override public void visit( Select obj ) { if (obj.isDistinct()) { append(SPACE); append(DISTINCT); } beginClause(2); Iterator<Expression> iter = obj.getSymbols().iterator(); while (iter.hasNext()) { Expression symbol = iter.next(); visitNode(symbol); if (iter.hasNext()) { append(", "); //$NON-NLS-1$ } } }
private List<Criteria> createPkCriteria(GroupSymbol group, String correlationName, Query query, GroupSymbol varGroup) throws TeiidComponentException, QueryMetadataException { Object pk = metadata.getPrimaryKey(group.getMetadataID()); if (pk == null) { pk = metadata.getUniqueKeysInGroup(group.getMetadataID()).iterator().next(); } int i = query.getSelect().getSymbols().size(); List<Object> ids = metadata.getElementIDsInKey(pk); List<Criteria> pkCriteria = new ArrayList<Criteria>(ids.size()); for (Object object : ids) { ElementSymbol es = new ElementSymbol(correlationName + Symbol.SEPARATOR + metadata.getName(object)); query.getSelect().addSymbol(new AliasSymbol("s_" +i, es)); //$NON-NLS-1$ es = new ElementSymbol(group.getName() + Symbol.SEPARATOR + metadata.getName(object)); pkCriteria.add(new CompareCriteria(es, CompareCriteria.EQ, new ElementSymbol("s_" + i, varGroup.clone()))); //$NON-NLS-1$ i++; } return pkCriteria; }
private List<Criteria> createPkCriteria(GroupSymbol viewGroup, GroupSymbol group, String correlationName, Query query, GroupSymbol varGroup) throws TeiidComponentException, QueryMetadataException, QueryValidatorException { Object pk = metadata.getPrimaryKey(group.getMetadataID()); if (pk == null) { Collection uniqueKeysInGroup = metadata.getUniqueKeysInGroup(group.getMetadataID()); if (uniqueKeysInGroup.isEmpty()) { throw new QueryValidatorException(QueryPlugin.Event.TEIID31267, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31267, viewGroup, group)); } pk = uniqueKeysInGroup.iterator().next(); } int i = query.getSelect().getSymbols().size(); List<Object> ids = metadata.getElementIDsInKey(pk); List<Criteria> pkCriteria = new ArrayList<Criteria>(ids.size()); for (Object object : ids) { ElementSymbol es = new ElementSymbol(correlationName + Symbol.SEPARATOR + metadata.getName(object)); query.getSelect().addSymbol(new AliasSymbol("s_" +i, es)); //$NON-NLS-1$ es = new ElementSymbol(group.getName() + Symbol.SEPARATOR + metadata.getName(object)); pkCriteria.add(new CompareCriteria(es, CompareCriteria.EQ, new ElementSymbol("s_" + i, varGroup.clone()))); //$NON-NLS-1$ i++; } return pkCriteria; }
public void setQueryExpression( QueryCommand query ) { if (query instanceof Query) { Query expr = (Query)query; //a single row constructor query is the same as values if (expr.isRowConstructor()) { this.values.clear(); this.queryExpression = null; for (Expression ex : expr.getSelect().getSymbols()) { addValue(SymbolMap.getExpression(ex)); } if (expr.getOption() != null && this.getOption() == null) { //this isn't ideal, parsing associates the option with values this.setOption(expr.getOption()); } return; } } this.queryExpression = query; }
public void setQueryExpression( QueryCommand query ) { if (query instanceof Query) { Query expr = (Query)query; //a single row constructor query is the same as values if (expr.isRowConstructor()) { this.values.clear(); this.queryExpression = null; for (Expression ex : expr.getSelect().getSymbols()) { addValue(SymbolMap.getExpression(ex)); } if (expr.getOption() != null && this.getOption() == null) { //this isn't ideal, parsing associates the option with values this.setOption(expr.getOption()); } return; } } this.queryExpression = query; }
public void setQueryExpression( QueryCommand query ) { if (query instanceof Query) { Query expr = (Query)query; //a single row constructor query is the same as values if (expr.isRowConstructor()) { this.values.clear(); this.queryExpression = null; for (Expression ex : expr.getSelect().getSymbols()) { addValue(SymbolMap.getExpression(ex)); } if (expr.getOption() != null && this.getOption() == null) { //this isn't ideal, parsing associates the option with values this.setOption(expr.getOption()); } return; } } this.queryExpression = query; }
@Test public void testXmlQueryWithParam() { Query q = (Query)helpResolve("select xmlquery('/a' passing ?)"); XMLQuery ex = (XMLQuery) SymbolMap.getExpression(q.getSelect().getSymbols().get(0)); assertEquals(DataTypeManager.DefaultDataClasses.XML, ex.getPassing().get(0).getExpression().getType()); }
@Test public void testNullConstantInSelect() throws Exception { String userSql = "SELECT null as x"; //$NON-NLS-1$ Query query = (Query)helpParse(userSql); QueryResolver.resolveCommand(query, RealMetadataFactory.exampleBQTCached()); // Check type of resolved null constant Expression symbol = query.getSelect().getSymbols().get(0); assertNotNull(symbol.getType()); assertEquals(DataTypeManager.DefaultDataClasses.STRING, symbol.getType()); }