Convert HashAggregate into a Serialized Aggregate

@param hashAggregateNode HashAggregatePlanNode
@return AggregatePlanNode
767125
public static AggregatePlanNode convertToSerialAggregatePlanNode(HashAggregatePlanNode hashAggregateNode) {
        AggregatePlanNode serialAggr = new AggregatePlanNode();
        return setAggregatePlanNode(hashAggregateNode, serialAggr);
    }
1081135
private RelBuilder convertMonopole(RelBuilder relBuilder, Aggregate aggregate,
			List<Integer> argList, int filterArg) {
		// For example,
		//    SELECT deptno, COUNT(DISTINCT sal), SUM(DISTINCT sal)
		//    FROM emp
		//    GROUP BY deptno
		//
		// becomes
		//
		//    SELECT deptno, COUNT(distinct_sal), SUM(distinct_sal)
		//    FROM (
		//      SELECT DISTINCT deptno, sal AS distinct_sal
		//      FROM EMP GROUP BY deptno)
		//    GROUP BY deptno

		// Project the columns of the GROUP BY plus the arguments
		// to the agg function.
		final Map<Integer, Integer> sourceOf = new HashMap<>();
		createSelectDistinct(relBuilder, aggregate, argList, filterArg, sourceOf);

		// Create an aggregate on top, with the new aggregate list.
		final List<AggregateCall> newAggCalls =
				com.google.common.collect.Lists.newArrayList(aggregate.getAggCallList());
		rewriteAggCalls(newAggCalls, argList, sourceOf);
		final int cardinality = aggregate.getGroupSet().cardinality();
		relBuilder.push(
				aggregate.copy(aggregate.getTraitSet(), relBuilder.build(),
						aggregate.indicator, ImmutableBitSet.range(cardinality), null,
						newAggCalls));
		return relBuilder;
	}
33692
Map<String, Object> serialize() {

		final Map<String, Object> serializedForm       = new TreeMap<>();
		final Map<String, Object> serializedProperties = new TreeMap<>();
		final Map<String, Object> serializedMethods    = new TreeMap<>();

		// populate properties
		for (final StructrPropertyDefinition property : properties) {
			serializedProperties.put(property.getName(), property.serialize());
		}

		// populate methods
		for (final StructrMethodDefinition method : methods) {

			final String name = method.getName();

			if (serializedMethods.containsKey(name)) {

				// Name is already present in the map, so there are at least
				// two method with the same name.
				final Object currentValue = serializedMethods.get(name);
				if (currentValue instanceof Collection) {

					// add serialized method to collection
					final Collection collection = (Collection)currentValue;

					collection.add(method.serialize());

				} else if (currentValue instanceof Map) {

					// remove map, add collection, add
					// map to collection
					final Map<String, Object> otherMethod   = (Map<String, Object>)serializedMethods.get(name);
					final Map<String, Object> currentMethod = method.serialize();
					final List<Map<String, Object>> list    = new LinkedList<>();

					list.add(otherMethod);
					list.add(currentMethod);

					serializedMethods.put(name, list);

				} else {

					logger.warn("Invalid storage datastructure for methods: {}", currentValue.getClass().getName());
				}

			} else {

				serializedMethods.put(method.getName(), method.serialize());
			}
		}

		serializedForm.put(JsonSchema.KEY_TYPE, "object");
		serializedForm.put(JsonSchema.KEY_IS_ABSTRACT, isAbstract);
		serializedForm.put(JsonSchema.KEY_IS_INTERFACE, isInterface);
		if (getClass().equals(StructrNodeTypeDefinition.class)) {
			serializedForm.put(JsonSchema.KEY_IS_BUILTIN_TYPE, isBuiltinType);
		}

		// properties
		if (!serializedProperties.isEmpty()) {
			serializedForm.put(JsonSchema.KEY_PROPERTIES, serializedProperties);
		}

		// required
		final Set<String> requiredProperties = getRequiredProperties();
		if (!requiredProperties.isEmpty()) {
			serializedForm.put(JsonSchema.KEY_REQUIRED, requiredProperties);
		}

		// views
		if (!views.isEmpty()) {

			// FIXME: views are different

			serializedForm.put(JsonSchema.KEY_VIEWS, views);
			serializedForm.put(JsonSchema.KEY_VIEW_ORDER, viewOrder);
		}

		// methods
		if (!serializedMethods.isEmpty()) {
			serializedForm.put(JsonSchema.KEY_METHODS, serializedMethods);
		}

		final URI ext = getExtends();
		if (ext != null) {

			serializedForm.put(JsonSchema.KEY_EXTENDS, root.toJsonPointer(ext));
		}

		if (!implementedInterfaces.isEmpty()) {

			final Set<String> interfaces = new TreeSet<>();

			for (final URI uri : implementedInterfaces) {
				interfaces.add(root.toJsonPointer(uri));
			}

			if (!interfaces.isEmpty()) {
				serializedForm.put(JsonSchema.KEY_IMPLEMENTS, interfaces);
			}
		}

		if (StringUtils.isNotBlank(category)) {
			serializedForm.put(JsonSchema.KEY_CATEGORY, category);
		}

		return serializedForm;
	}
907581
function swarmHashBlock (data, totalLength) {
  var hash = new Keccak(256)
  var tmp = Buffer.alloc(8)
  tmp.writeUIntLE(totalLength, 0, 6)
  hash.update(tmp)
  hash.update(data)
  return Buffer.from(hash.digest('bin'), 'binary')
}
70986
public static long getFragmentIdForPlanHash(byte[] planHash) {
        Sha1Wrapper key = new Sha1Wrapper(planHash);
        FragInfo frag = null;
        synchronized (FragInfo.class) {
            frag = m_plansByHash.get(key);
        }
        assert(frag != null);
        return frag.fragId;
    }
784362
function serializeHash() {
      var hash = {}
      eachFormElement.apply(function (name, value) {
        if (name in hash) {
          hash[name] && !isArray(hash[name]) && (hash[name] = [hash[name]])
          hash[name].push(value)
        } else hash[name] = value
      }, arguments)
      return hash
    }
823114
function createHash(root) {
    // visit(root, function (node) {
    //     return node.data && node.data.hData && node.data.hData.hash;
    // }, function (node) {
    //     debugger
    // })

    var children = root.children;

    var hashs = children.map(function (node) {
        return (node.type === "paragraph" && node.data && node.data.hData && node.data.hData.hash)?node.data.hData.hash:0;
    });

    return [].concat(hashs).reduce(function (a, b) {
        return a+b;
    })

}
1067213
public static void serialize(ByteBuffer out, int position, BloomKFilter bloomFilter)
  {
    /**
     * Serialized BloomKFilter format:
     * 1 byte for the number of hash functions.
     * 1 big endian int(to match OutputStream) for the number of longs in the bitset
     * big endian longs in the BloomKFilter bitset
     */
    ByteBuffer view = out.duplicate().order(ByteOrder.BIG_ENDIAN);
    view.position(position);
    view.put((byte) bloomFilter.k);
    view.putInt(bloomFilter.getBitSet().length);
    for (long value : bloomFilter.getBitSet()) {
      view.putLong(value);
    }
  }
332876
@SuppressWarnings("unchecked")
    public static <A extends AggregateRoot<I>, I> Class<I> resolveAggregateIdClass(Class<A> aggregateRootClass) {
        checkNotNull(aggregateRootClass, "aggregateRootClass should not be null");
        return (Class<I>) resolveGenerics(AggregateRoot.class, aggregateRootClass)[0];
    }
276800
@Override
	public void setAggregator(IAggregator aggregator) {
		if (this.aggregator != null) {
			throw new IllegalStateException();
		}
		this.aggregator = aggregator;

		// See if the max cache entries init-param has changed and
		int newMaxCapacity = getMaxCapacity(aggregator);

		// If the maximum size has changed, then create a new layerBuildMap with the new
		// max size and copy the entries from the existing map to the new map
		ConcurrentLinkedHashMap<String, CacheEntry> oldLayerBuildMap = null;
		// have no layer builds in the layerBuildMap
		if (maxCapacity != newMaxCapacity) {
			maxCapacity = newMaxCapacity;
			oldLayerBuildMap = layerBuildMap;
			layerBuildMap = new ConcurrentLinkedHashMap.Builder<String, CacheEntry>()
					.maximumWeightedCapacity(maxCapacity)
					.listener(newEvictionListener())
					.weigher(newWeigher())
					.build();
			// Need to call setLayerBuildAccessors BEFORE calling putAll because
			// it might result in the eviction handler being called.
			setLayerBuildAccessors(oldLayerBuildMap.keySet());
			layerBuildMap.putAll(oldLayerBuildMap.ascendingMap());
			oldLayerBuildMap.clear();
		} else {
			setLayerBuildAccessors(layerBuildMap.keySet());
		}
	}
1349380
private AggregateOperator<T> aggregate(Aggregations agg, int field, String callLocationName) {
		return new AggregateOperator<T>(this, agg, field, callLocationName);
	}
1126086
@Override
  public <T extends OutputStream> T serialize(final FSA fsa, T os) throws IOException {

    // Prepare space for arc offsets and linearize all the states.
    int[] linearized = linearize(fsa);

    /*
     * Calculate the number of bytes required for the node data, if
     * serializing with numbers.
     */
    int nodeDataLength = 0;
    if (withNumbers) {
      this.numbers = FSAUtils.rightLanguageForAllStates(fsa);
      int maxNumber = numbers.get(fsa.getRootNode());
      while (maxNumber > 0) {
        nodeDataLength++;
        maxNumber >>>= 8;
      }
    }

    // Calculate minimal goto length.
    int gtl = 1;
    while (true) {
      // First pass: calculate offsets of states.
      if (!emitArcs(fsa, null, linearized, gtl, nodeDataLength)) {
        gtl++;
        continue;
      }

      // Second pass: check if goto overflows anywhere.
      if (emitArcs(fsa, null, linearized, gtl, nodeDataLength))
        break;

      gtl++;
    }

    /*
     * Emit the header.
     */
    FSAHeader.write(os, FSA5.VERSION);
    os.write(fillerByte);
    os.write(annotationByte);
    os.write((nodeDataLength << 4) | gtl);

    /*
     * Emit the automaton.
     */
    boolean gtlUnchanged = emitArcs(fsa, os, linearized, gtl, nodeDataLength);
    assert gtlUnchanged : "gtl changed in the final pass.";

    return os;
  }
1004231
private FilterAggregationBuilder buildWhereAggregations(EntityMetadata entityMetadata, QueryBuilder filter)
    {
        filter = filter != null ? filter : QueryBuilders.matchAllQuery();
        FilterAggregationBuilder filteragg = AggregationBuilders.filter(ESConstants.AGGREGATION_NAME).filter(filter);

        return filteragg;
    }
582387
@Override
	public Map<String, SerializedValue<OptionalFailure<Object>>> getAccumulatorsSerialized() {
		return aggregateUserAccumulators()
			.entrySet()
			.stream()
			.collect(Collectors.toMap(
				Map.Entry::getKey,
				entry -> serializeAccumulator(entry.getKey(), entry.getValue())));
	}
1332563
public function addAggregation(AbstractAggregation $abstractAggregation)
    {
        if (!$this->aggregations) {
            $this->aggregations = $this->createBuilderBag();
        }

        $this->aggregations->add($abstractAggregation);
        
        return $this;
    }
894500
public AggregationResult aggregate(String rAggregateFormula) throws DDFException {

    return mAggregationHandler.aggregate(AggregateField.fromSqlFieldSpecs(parseRAggregateFormula(rAggregateFormula)));
  }
277632
public static <Key, Value> Aggregation<Key, Value, Long> count() {
        return new AggregationAdapter(new CountAggregation<Key, Value>());
    }