private void processLimit(PlanNode node, QueryCommand query, QueryMetadataInterface metadata) { Expression limit = (Expression)node.getProperty(NodeConstants.Info.MAX_TUPLE_LIMIT); Expression offset = (Expression)node.getProperty(NodeConstants.Info.OFFSET_TUPLE_COUNT); PlanNode limitNode = NodeFactory.getNewNode(NodeConstants.Types.TUPLE_LIMIT); Expression childLimit = null; Expression childOffset = null; if (query.getLimit() != null) { childLimit = query.getLimit().getRowLimit(); childOffset = query.getLimit().getOffset(); } RulePushLimit.combineLimits(limitNode, metadata, limit, offset, childLimit, childOffset); Limit lim = new Limit((Expression)limitNode.getProperty(NodeConstants.Info.OFFSET_TUPLE_COUNT), (Expression)limitNode.getProperty(NodeConstants.Info.MAX_TUPLE_LIMIT)); lim.setImplicit(node.hasBooleanProperty(Info.IS_IMPLICIT_LIMIT) && (query.getLimit() == null || query.getLimit().isImplicit())); query.setLimit(lim); }
private static PlanNode attachTupleLimit(PlanNode plan, Limit limit, PlanHints hints) { hints.hasLimit = true; PlanNode limitNode = NodeFactory.getNewNode(NodeConstants.Types.TUPLE_LIMIT); boolean attach = false; if (limit.getOffset() != null) { limitNode.setProperty(NodeConstants.Info.OFFSET_TUPLE_COUNT, limit.getOffset()); attach = true; } if (limit.getRowLimit() != null) { limitNode.setProperty(NodeConstants.Info.MAX_TUPLE_LIMIT, limit.getRowLimit()); attach = true; } if (attach) { if (limit.isImplicit()) { limitNode.setProperty(Info.IS_IMPLICIT_LIMIT, true); } if (!limit.isStrict()) { limitNode.setProperty(Info.IS_NON_STRICT, true); } attachLast(limitNode, plan); plan = limitNode; } return plan; }
public void visit(Limit obj) { if (obj.getOffset() != null) { obj.setOffset(replaceExpression(obj.getOffset())); } obj.setRowLimit(replaceExpression(obj.getRowLimit())); }
public static void resolveLimit(Limit limit) throws QueryResolverException { if (limit.getOffset() != null) { setDesiredType(limit.getOffset(), DataTypeManager.DefaultDataClasses.INTEGER, limit); } setDesiredType(limit.getRowLimit(), DataTypeManager.DefaultDataClasses.INTEGER, limit); }
public Limit clone() { Limit clone = new Limit(); clone.implicit = this.implicit; clone.strict = this.strict; if (this.rowLimit != null) { clone.setRowLimit((Expression) this.rowLimit.clone()); } if (this.offset != null) { clone.setOffset((Expression) this.offset.clone()); } return clone; }
public void testClone() { Limit limit = new Limit(new Constant(new Integer(100)), new Constant(new Integer(50))); Limit clone = (Limit)limit.clone(); assertTrue(limit != clone); assertTrue(limit.equals(clone)); assertEquals(new Constant(new Integer(100)), clone.getOffset()); assertEquals(new Constant(new Integer(50)), clone.getRowLimit()); }
private void addImplicitLimit(SubqueryContainer<QueryCommand> container, int rowLimit) { if (container.getCommand().getLimit() != null) { Limit lim = container.getCommand().getLimit(); if (lim.getRowLimit() instanceof Constant) { Constant c = (Constant)lim.getRowLimit(); if (!c.isMultiValued() && Integer.valueOf(rowLimit).compareTo((Integer) c.getValue()) <= 0) { lim.setRowLimit(new Constant(rowLimit)); if (lim.getRowLimit() == null) { lim.setImplicit(true); container.getCommand().setOrderBy(null); } } } return; } boolean addLimit = true; if (container.getCommand() instanceof Query) { Query query = (Query)container.getCommand(); addLimit = !(query.hasAggregates() && query.getGroupBy() == null); } if (addLimit) { Limit lim = new Limit(null, new Constant(rowLimit)); lim.setImplicit(true); container.getCommand().setLimit(lim); } }
boolean skipAndTopApplied = false; if (!getCount && (topOption != null || skipOption != null)) { query.setLimit(new Limit(skipOption!=null?new Constant(skipOption):null, topOption!=null?new Constant(topOption):null)); skipAndTopApplied=true;
if (queryCommand.getLimit().getRowLimit() == null) { queryCommand.getLimit().setRowLimit(new Constant(1)); queryCommand.setLimit(new Limit(null, new Constant(1)));
@Override public void visit( Limit obj ) { if (!obj.isStrict()) { append(BEGIN_HINT); append(SPACE); append(Limit.NON_STRICT); append(SPACE); append(END_HINT); append(SPACE); } if (obj.getRowLimit() == null) { append(OFFSET); append(SPACE); visitNode(obj.getOffset()); append(SPACE); append(ROWS); return; } append(LIMIT); if (obj.getOffset() != null) { append(SPACE); visitNode(obj.getOffset()); append(","); //$NON-NLS-1$ } append(SPACE); visitNode(obj.getRowLimit()); }
public void testGetRowLimit() { Limit limit = new Limit(new Constant(new Integer(10)), new Constant(new Integer(30))); assertEquals(new Constant(new Integer(30)), limit.getRowLimit()); assertEquals(new Constant(new Integer(30)), limit.getRowLimit()); }
/** * Deep clone this object to produce a new identical query. * @return Deep clone */ public Object clone() { SetQuery copy = new SetQuery(this.operation); this.copyMetadataState(copy); copy.leftQuery = (QueryCommand)this.leftQuery.clone(); copy.rightQuery = (QueryCommand)this.rightQuery.clone(); copy.setAll(this.all); if(this.getOrderBy() != null) { copy.setOrderBy(this.getOrderBy().clone()); } if(this.getLimit() != null) { copy.setLimit( (Limit) this.getLimit().clone() ); } copy.setWith(LanguageObject.Util.deepClone(this.getWith(), WithQueryCommand.class)); if (this.projectedTypes != null) { copy.setProjectedTypes(new ArrayList<Class<?>>(projectedTypes), this.metadata); } return copy; }
public void testHashcode() { // Ensure that the hashcode for offset = null and offset = 0 are the same. Limit limit1 = new Limit(null, new Constant(new Integer(50))); Limit limit2 = new Limit(new Constant(new Integer(0)), new Constant(new Integer(50))); assertEquals(limit1.hashCode(), limit2.hashCode()); }
public void testToString() { assertEquals("LIMIT 50", new Limit(null, new Constant(new Integer(50))).toString()); //$NON-NLS-1$ assertEquals("LIMIT 100, 50", new Limit(new Constant(new Integer(100)), new Constant(new Integer(50))).toString()); //$NON-NLS-1$ assertEquals("LIMIT ?, ?", new Limit(new Reference(0), new Reference(1)).toString()); //$NON-NLS-1$ assertEquals("LIMIT -1, ?", new Limit(new Constant(new Integer(-1)), new Reference(1)).toString()); //$NON-NLS-1$ }
public void testEquals() { Limit limit1 = new Limit(new Constant(new Integer(100)), new Constant(new Integer(50))); Limit limit2 = new Limit(new Constant(new Integer(100)), new Constant(new Integer(50))); Limit limit3 = new Limit(new Constant(new Integer(99)), new Constant(new Integer(50))); Limit limit4 = new Limit(new Constant(new Integer(100)), new Constant(new Integer(49))); Limit limit5 = new Limit(null, new Constant(new Integer(50))); Limit limit6 = new Limit(new Constant(new Integer(0)), new Constant(new Integer(50))); Limit limit7 = new Limit(new Reference(0), new Constant(new Integer(50))); Limit limit8 = new Limit(new Reference(0), new Reference(1)); Limit limit9 = new Limit(null, new Reference(1)); assertTrue(limit1.equals(limit2)); assertTrue(limit2.equals(limit1)); assertTrue(limit1.equals(limit1)); assertFalse(limit1.equals(null)); assertFalse(limit1.equals(limit3)); assertFalse(limit1.equals(limit4)); assertFalse(limit6.equals(limit7)); assertFalse(limit7.equals(limit6)); assertFalse(limit5.equals(limit7)); assertFalse(limit7.equals(limit5)); assertFalse(limit7.equals(limit8)); assertFalse(limit8.equals(limit9)); assertFalse(limit5.equals(limit9)); }
public boolean planQuery(Collection<GroupSymbol> leftGroups, boolean requireDistinct, PlannedResult plannedResult) throws QueryMetadataException, TeiidComponentException { if ((plannedResult.query.getLimit() != null && !plannedResult.query.getLimit().isImplicit()) || plannedResult.query.getFrom() == null) { return false;
if (limit != null && limit.getRowLimit() instanceof Constant) { Constant rowLimit = (Constant)limit.getRowLimit(); if (Integer.valueOf(0).equals(rowLimit.getValue())) { return false;
public static void resolveLimit(Limit limit) throws QueryResolverException { if (limit.getOffset() != null) { setDesiredType(limit.getOffset(), DataTypeManager.DefaultDataClasses.INTEGER, limit); } setDesiredType(limit.getRowLimit(), DataTypeManager.DefaultDataClasses.INTEGER, limit); }