/** * Returns an appropriate, empty {@code SelectResults} * * @param objectType The {@code ObjectType} of the query results * @return an appropriate, empty {@code SelectResults} */ public static SelectResults getEmptySelectResults(ObjectType objectType, CachePerfStats statsOrNull) { SelectResults emptyResults = null; if (objectType instanceof StructType) { emptyResults = new StructBag((StructTypeImpl) objectType, statsOrNull); } else { emptyResults = new ResultsBag(objectType, statsOrNull); } return emptyResults; }
@Override public boolean addAll(Collection c) { if (c instanceof StructFields) { return addAll((StructFields) c); } return super.addAll(c); }
@Override public boolean removeAll(Collection c) { if (c instanceof StructFields) { return removeAll((StructFields) c); } return super.removeAll(c); }
public boolean retainAll(StructFields ss) { if (!this.elementType.equals(ss.getCollectionType().getElementType())) { if (isEmpty()) { return false; // nothing modified } else { clear(); return true; // nothing retained in receiver collection } } boolean changed = false; int size = size(); Iterator it; it = fieldValuesIterator(); while (size-- > 0) { Object[] vals = (Object[]) it.next(); if (!ss.containsFieldValues(vals)) { it.remove(); changed = true; } } return changed; }
StructBag bag1 = (StructBag) getBagObject(Integer.class); bag1.add(wrap(null, bag1.getCollectionType().getElementType())); bag1.add(wrap(null, bag1.getCollectionType().getElementType())); bag1.add(wrap(new Integer(1), bag1.getCollectionType().getElementType())); bag1.add(wrap(new Integer(2), bag1.getCollectionType().getElementType())); bag1.add(wrap(new Integer(2), bag1.getCollectionType().getElementType())); bag1.add(wrap(new Integer(3), bag1.getCollectionType().getElementType())); bag1.add(wrap(new Integer(3), bag1.getCollectionType().getElementType())); bag1.add(wrap(new Integer(4), bag1.getCollectionType().getElementType())); bag1.applyLimit(4); StructBag bag2 = (StructBag) getBagObject(Integer.class); bag2.addAll((StructFields) bag1); Iterator itr2 = bag2.iterator(); Struct first = (Struct) itr2.next(); int occrnce = 0; assertTrue(bag1.removeAll((StructFields) bag2)); assertEquals(occrnce, bag1.size()); Iterator itr = bag1.iterator(); for (int i = 0; i < occrnce; ++i) { itr.next();
bag1.add(wrap(new Integer(1), bag1.getCollectionType().getElementType())); bag1.add(wrap(new Integer(2), bag1.getCollectionType().getElementType())); bag1.add(wrap(new Integer(2), bag1.getCollectionType().getElementType())); bag1.add(wrap(new Integer(3), bag1.getCollectionType().getElementType())); bag1.add(wrap(new Integer(3), bag1.getCollectionType().getElementType())); bag1.add(wrap(new Integer(4), bag1.getCollectionType().getElementType())); bag1.add(wrap(null, bag1.getCollectionType().getElementType())); bag1.add(wrap(null, bag1.getCollectionType().getElementType())); bag1.applyLimit(4); StructBag bag2 = (StructBag) getBagObject(Integer.class); bag2.addAll((StructFields) bag1); Iterator itr2 = bag2.iterator(); Struct first = (Struct) itr2.next(); int occrnce = 0; bag1.retainAll((StructFields) bag2); assertEquals(4, bag1.size()); Iterator itr = bag1.iterator(); for (int i = 0; i < 4; ++i) { itr.next();
@Override public boolean retainAll(Collection c) { if (c instanceof StructFields) { return retainAll((StructFields) c); } return super.retainAll(c); }
/** Add a Struct */ @Override public boolean add(Object obj) { if (!(obj instanceof StructImpl)) { throw new IllegalArgumentException( "This set only accepts StructImpl"); } StructImpl s = (StructImpl) obj; if (!this.elementType.equals(s.getStructType())) { throw new IllegalArgumentException( String.format( "obj does not have the same StructType.; collection structype,%s; added obj type=%s", this.elementType, s.getStructType())); } return addFieldValues(s.getFieldValues()); }
public static SelectResults createStructCollection(boolean distinct, StructType elementType, ExecutionContext context) { return distinct ? new StructSet(elementType) : new StructBag(elementType, context.getCachePerfStats()); }
public static SelectResults createStructCollection(ExecutionContext context, StructType elementType) { return context.isDistinct() ? new StructSet(elementType) : new StructBag(elementType, context.getCachePerfStats()); }
public ResultsBag getBagObject(Class clazz) { ObjectType[] types = new ObjectType[] {new ObjectTypeImpl(clazz), new ObjectTypeImpl(clazz)}; StructType type = new StructTypeImpl(new String[] {"field1", "field2"}, types); return new StructBag(type, null); }
private SelectResults<Struct> buildListOfStructs(String... values) { SelectResults<Struct> results = new StructBag(); StructTypeImpl elementType = new StructTypeImpl(new String[] {"field1"}); results.setElementType(elementType); for (String value : values) { results.add(new StructImpl(elementType, new Object[] {value})); } return results; }
: new StructBag(0, new StructTypeImpl(fieldNames, fieldTypes), context.getCachePerfStats());
return new ResultsSet(elementType); case UNORDERED_INDISTINCT_STRUCT: return new StructBag((StructType) elementType, context.getCachePerfStats()); case UNORDERED_INDISTINCT_RESULTS: return new ResultsBag(elementType, context.getCachePerfStats());