001    /*
002     * Copyright (c) 2007-2015 Concurrent, Inc. All Rights Reserved.
003     *
004     * Project and contact information: http://www.cascading.org/
005     *
006     * This file is part of the Cascading project.
007     *
008     * Licensed under the Apache License, Version 2.0 (the "License");
009     * you may not use this file except in compliance with the License.
010     * You may obtain a copy of the License at
011     *
012     *     http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing, software
015     * distributed under the License is distributed on an "AS IS" BASIS,
016     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017     * See the License for the specific language governing permissions and
018     * limitations under the License.
019     */
020    
021    package cascading.pipe.assembly;
022    
023    import java.beans.ConstructorProperties;
024    
025    import cascading.flow.FlowProcess;
026    import cascading.operation.aggregator.Sum;
027    import cascading.pipe.Pipe;
028    import cascading.tuple.Fields;
029    import cascading.tuple.Tuple;
030    import cascading.tuple.TupleEntry;
031    import cascading.tuple.Tuples;
032    
033    /**
034     * Class CountBy is used to count duplicates in a tuple stream, where "duplicates" means all tuples with the same
035     * values for the groupingFields fields. The resulting count is output as a long value in the specified countField.
036     * <p/>
037     * Typically finding the count of a field in a tuple stream relies on a {@link cascading.pipe.GroupBy} and a
038     * {@link cascading.operation.aggregator.Count} {@link cascading.operation.Aggregator} operation.
039     * <p/>
040     * The CountBy SubAssembly is a (typically) more efficient replacement for these two steps, because it does map-side
041     * pre-reduce counting (via {@link CountBy.CountPartials}  {@link AggregateBy.Functor}) before the GroupBy operator;
042     * this reduces network I/O from the map to reduce phases.
043     * <p/>
044     * This strategy is similar to using {@code combiners}, except no sorting or serialization is invoked and results
045     * in a much simpler mechanism.
046     * <p/>
047     * The {@code threshold} value tells the underlying CountPartials functions how many unique key counts to accumulate
048     * in the LRU cache, before emitting the least recently used entry. This accumulation happens map-side, and thus is
049     * bounded by the size of your map task JVM and the typical size of each group key.
050     * <p/>
051     * By default, either the value of {@link cascading.pipe.assembly.AggregateByProps#AGGREGATE_BY_CAPACITY} System property
052     * or {@link cascading.pipe.assembly.AggregateByProps#AGGREGATE_BY_DEFAULT_CAPACITY} will be used.
053     * <p/>
054     * If {@code include} is {@link Include#NO_NULLS}, argument tuples with all null values will be ignored.
055     * <p/>
056     * The values in the argument Tuple are normally all the remaining fields not used for grouping, but this can be
057     * narrowed using the valueFields parameter. When counting the occurrence of a single field (when {@code valueFields}
058     * is set on the constructor), this is the same behavior as {@code select count(foo) ...} in SQL. If {@code include} is
059     * {@link Include#ONLY_NULLS} then only argument tuples with all null values will be counted.
060     *
061     * @see AggregateBy
062     */
063    public class CountBy extends AggregateBy
064      {
065      /** DEFAULT_THRESHOLD */
066      @Deprecated
067      public static final int DEFAULT_THRESHOLD = 10000;
068    
069      public enum Include
070        {
071          ALL,
072          NO_NULLS,
073          ONLY_NULLS
074        }
075    
076      /**
077       * Class CountPartials is a {@link AggregateBy.Functor} that is used to count observed duplicates from the tuple stream.
078       * <p/>
079       * Use this class typically in tandem with a {@link cascading.operation.aggregator.Sum}
080       * {@link cascading.operation.Aggregator} in order to improve counting performance by removing as many values
081       * as possible before the intermediate {@link cascading.pipe.GroupBy} operator.
082       *
083       * @see CountBy
084       */
085      public static class CountPartials implements Functor
086        {
087        private final Fields declaredFields;
088        private final Include include;
089    
090        /**
091         * Constructor CountPartials creates a new CountPartials instance.
092         *
093         * @param declaredFields of type Fields
094         */
095        public CountPartials( Fields declaredFields )
096          {
097          this( declaredFields, Include.ALL );
098          }
099    
100        public CountPartials( Fields declaredFields, Include include )
101          {
102          this.declaredFields = declaredFields;
103          this.include = include;
104    
105          if( !declaredFields.isDeclarator() || declaredFields.size() != 1 )
106            throw new IllegalArgumentException( "declaredFields should declare only one field name" );
107          }
108    
109        @Override
110        public Fields getDeclaredFields()
111          {
112          return declaredFields;
113          }
114    
115        @Override
116        public Tuple aggregate( FlowProcess flowProcess, TupleEntry args, Tuple context )
117          {
118          if( context == null )
119            context = new Tuple( 0L );
120    
121          switch( include )
122            {
123            case ALL:
124              break;
125    
126            case NO_NULLS:
127              if( Tuples.frequency( args, null ) == args.size() )
128                return context;
129    
130              break;
131    
132            case ONLY_NULLS:
133              if( Tuples.frequency( args, null ) != args.size() )
134                return context;
135    
136              break;
137            }
138    
139          context.set( 0, context.getLong( 0 ) + 1L );
140    
141          return context;
142          }
143    
144        @Override
145        public Tuple complete( FlowProcess flowProcess, Tuple context )
146          {
147          return context;
148          }
149        }
150    
151      //// AggregateBy param constructors
152    
153      /**
154       * Constructor CountBy creates a new CountBy instance. Use this constructor when used with a {@link AggregateBy}
155       * instance.
156       *
157       * @param countField of type Fields
158       */
159      @ConstructorProperties({"countField"})
160      public CountBy( Fields countField )
161        {
162        super( Fields.ALL, new CountPartials( countField.applyTypes( Long.TYPE ) ), new Sum( countField.applyTypes( Long.TYPE ) ) );
163        }
164    
165      /**
166       * Constructor CountBy creates a new CountBy instance. Use this constructor when used with a {@link AggregateBy}
167       * instance.
168       *
169       * @param countField of type Fields
170       * @param include    of type Include
171       */
172      @ConstructorProperties({"countField", "include"})
173      public CountBy( Fields countField, Include include )
174        {
175        super( Fields.ALL, new CountPartials( countField.applyTypes( Long.TYPE ), include ), new Sum( countField.applyTypes( Long.TYPE ) ) );
176        }
177    
178      /**
179       * Constructor CountBy creates a new CountBy instance. Use this constructor when used with a {@link AggregateBy}
180       * instance.
181       *
182       * @param countField of type Fields
183       */
184      @ConstructorProperties({"valueFields", "countField"})
185      public CountBy( Fields valueFields, Fields countField )
186        {
187        super( valueFields, new CountPartials( countField.applyTypes( Long.TYPE ) ), new Sum( countField.applyTypes( Long.TYPE ) ) );
188        }
189    
190      /**
191       * Constructor CountBy creates a new CountBy instance. Use this constructor when used with a {@link AggregateBy}
192       * instance.
193       *
194       * @param countField of type Fields
195       */
196      @ConstructorProperties({"valueFields", "countField", "include"})
197      public CountBy( Fields valueFields, Fields countField, Include include )
198        {
199        super( valueFields, new CountPartials( countField.applyTypes( Long.TYPE ), include ), new Sum( countField.applyTypes( Long.TYPE ) ) );
200        }
201    
202      ///////
203    
204      /**
205       * Constructor CountBy creates a new CountBy instance.
206       *
207       * @param pipe           of type Pipe
208       * @param groupingFields of type Fields
209       * @param countField     of type Fields
210       */
211      @ConstructorProperties({"pipe", "groupingFields", "countField"})
212      public CountBy( Pipe pipe, Fields groupingFields, Fields countField )
213        {
214        this( null, pipe, groupingFields, countField );
215        }
216    
217      /**
218       * Constructor CountBy creates a new CountBy instance.
219       *
220       * @param pipe           of type Pipe
221       * @param groupingFields of type Fields
222       * @param countField     fo type Fields
223       * @param threshold      of type int
224       */
225      @ConstructorProperties({"pipe", "groupingFields", "countField", "threshold"})
226      public CountBy( Pipe pipe, Fields groupingFields, Fields countField, int threshold )
227        {
228        this( null, pipe, groupingFields, countField, threshold );
229        }
230    
231      /**
232       * Constructor CountBy creates a new CountBy instance.
233       *
234       * @param name           of type String
235       * @param pipe           of type Pipe
236       * @param groupingFields of type Fields
237       * @param countField     of type Fields
238       */
239      @ConstructorProperties({"name", "pipe", "groupingFields", "countField"})
240      public CountBy( String name, Pipe pipe, Fields groupingFields, Fields countField )
241        {
242        this( name, pipe, groupingFields, countField, USE_DEFAULT_THRESHOLD );
243        }
244    
245      /**
246       * Constructor CountBy creates a new CountBy instance.
247       *
248       * @param name           of type String
249       * @param pipe           of type Pipe
250       * @param groupingFields of type Fields
251       * @param countField     of type Fields
252       * @param threshold      of type int
253       */
254      @ConstructorProperties({"name", "pipe", "groupingFields", "countField", "threshold"})
255      public CountBy( String name, Pipe pipe, Fields groupingFields, Fields countField, int threshold )
256        {
257        this( name, Pipe.pipes( pipe ), groupingFields, countField, threshold );
258        }
259    
260      /**
261       * Constructor CountBy creates a new CountBy instance.
262       *
263       * @param pipes          of type Pipe[]
264       * @param groupingFields of type Fields
265       * @param countField     of type Fields
266       */
267      @ConstructorProperties({"pipes", "groupingFields", "countField"})
268      public CountBy( Pipe[] pipes, Fields groupingFields, Fields countField )
269        {
270        this( null, pipes, groupingFields, countField, USE_DEFAULT_THRESHOLD );
271        }
272    
273      /**
274       * Constructor CountBy creates a new CountBy instance.
275       *
276       * @param pipes          of type Pipe[]
277       * @param groupingFields of type Fields
278       * @param countField     of type Fields
279       * @param threshold      of type int
280       */
281      @ConstructorProperties({"pipes", "groupingFields", "countField", "threshold"})
282      public CountBy( Pipe[] pipes, Fields groupingFields, Fields countField, int threshold )
283        {
284        this( null, pipes, groupingFields, countField, threshold );
285        }
286    
287      /**
288       * Constructor CountBy creates a new CountBy instance.
289       *
290       * @param name           of type String
291       * @param pipes          of type Pipe[]
292       * @param groupingFields of type Fields
293       * @param countField     of type Fields
294       */
295      @ConstructorProperties({"name", "pipes", "groupingFields", "countField"})
296      public CountBy( String name, Pipe[] pipes, Fields groupingFields, Fields countField )
297        {
298        this( name, pipes, groupingFields, countField, USE_DEFAULT_THRESHOLD );
299        }
300    
301      /**
302       * Constructor CountBy creates a new CountBy instance.
303       *
304       * @param name           of type String
305       * @param pipes          of type Pipe[]
306       * @param groupingFields of type Fields
307       * @param countField     of type Fields
308       * @param threshold      of type int
309       */
310      @ConstructorProperties({"name", "pipes", "groupingFields", "countField", "threshold"})
311      public CountBy( String name, Pipe[] pipes, Fields groupingFields, Fields countField, int threshold )
312        {
313        super( name, pipes, groupingFields, groupingFields, new CountPartials( countField.applyTypes( Long.TYPE ) ), new Sum( countField.applyTypes( Long.TYPE ) ), threshold );
314        }
315    
316      ///////
317    
318      /**
319       * Constructor CountBy creates a new CountBy instance.
320       *
321       * @param pipe           of type Pipe
322       * @param groupingFields of type Fields
323       * @param countField     of type Fields
324       * @param include        of type Include
325       */
326      @ConstructorProperties({"pipe", "groupingFields", "countField", "include"})
327      public CountBy( Pipe pipe, Fields groupingFields, Fields countField, Include include )
328        {
329        this( null, pipe, groupingFields, countField, include );
330        }
331    
332      /**
333       * Constructor CountBy creates a new CountBy instance.
334       *
335       * @param pipe           of type Pipe
336       * @param groupingFields of type Fields
337       * @param countField     fo type Fields
338       * @param include        of type Include
339       * @param threshold      of type int
340       */
341      @ConstructorProperties({"pipe", "groupingFields", "countField", "include", "threshold"})
342      public CountBy( Pipe pipe, Fields groupingFields, Fields countField, Include include, int threshold )
343        {
344        this( null, pipe, groupingFields, countField, include, threshold );
345        }
346    
347      /**
348       * Constructor CountBy creates a new CountBy instance.
349       *
350       * @param name           of type String
351       * @param pipe           of type Pipe
352       * @param groupingFields of type Fields
353       * @param countField     of type Fields
354       * @param include        of type Include
355       */
356      @ConstructorProperties({"name", "pipe", "groupingFields", "countField", "include"})
357      public CountBy( String name, Pipe pipe, Fields groupingFields, Fields countField, Include include )
358        {
359        this( name, pipe, groupingFields, countField, include, USE_DEFAULT_THRESHOLD );
360        }
361    
362      /**
363       * Constructor CountBy creates a new CountBy instance.
364       *
365       * @param name           of type String
366       * @param pipe           of type Pipe
367       * @param groupingFields of type Fields
368       * @param countField     of type Fields
369       * @param include        of type Include
370       * @param threshold      of type int
371       */
372      @ConstructorProperties({"name", "pipe", "groupingFields", "countField", "include", "threshold"})
373      public CountBy( String name, Pipe pipe, Fields groupingFields, Fields countField, Include include, int threshold )
374        {
375        this( name, Pipe.pipes( pipe ), groupingFields, countField, include, threshold );
376        }
377    
378      /**
379       * Constructor CountBy creates a new CountBy instance.
380       *
381       * @param pipes          of type Pipe[]
382       * @param groupingFields of type Fields
383       * @param countField     of type Fields
384       * @param include        of type Include
385       */
386      @ConstructorProperties({"pipes", "groupingFields", "countField", "include"})
387      public CountBy( Pipe[] pipes, Fields groupingFields, Fields countField, Include include )
388        {
389        this( null, pipes, groupingFields, countField, include, USE_DEFAULT_THRESHOLD );
390        }
391    
392      /**
393       * Constructor CountBy creates a new CountBy instance.
394       *
395       * @param pipes          of type Pipe[]
396       * @param groupingFields of type Fields
397       * @param countField     of type Fields
398       * @param include        of type Include
399       * @param threshold      of type int
400       */
401      @ConstructorProperties({"pipes", "groupingFields", "countField", "include", "threshold"})
402      public CountBy( Pipe[] pipes, Fields groupingFields, Fields countField, Include include, int threshold )
403        {
404        this( null, pipes, groupingFields, countField, include, threshold );
405        }
406    
407      /**
408       * Constructor CountBy creates a new CountBy instance.
409       *
410       * @param name           of type String
411       * @param pipes          of type Pipe[]
412       * @param groupingFields of type Fields
413       * @param countField     of type Fields
414       * @param include        of type Include
415       */
416      @ConstructorProperties({"name", "pipes", "groupingFields", "countField", "include"})
417      public CountBy( String name, Pipe[] pipes, Fields groupingFields, Fields countField, Include include )
418        {
419        this( name, pipes, groupingFields, countField, include, USE_DEFAULT_THRESHOLD );
420        }
421    
422      /**
423       * Constructor CountBy creates a new CountBy instance.
424       *
425       * @param name           of type String
426       * @param pipes          of type Pipe[]
427       * @param groupingFields of type Fields
428       * @param countField     of type Fields
429       * @param include        of type Include
430       * @param threshold      of type int
431       */
432      @ConstructorProperties({"name", "pipes", "groupingFields", "countField", "include", "threshold"})
433      public CountBy( String name, Pipe[] pipes, Fields groupingFields, Fields countField, Include include, int threshold )
434        {
435        super( name, pipes, groupingFields, groupingFields, new CountPartials( countField.applyTypes( Long.TYPE ), include ), new Sum( countField.applyTypes( Long.TYPE ) ), threshold );
436        }
437    
438    ////////////
439    
440      /**
441       * Constructor CountBy creates a new CountBy instance.
442       *
443       * @param pipe           of type Pipe
444       * @param groupingFields of type Fields
445       * @param valueFields    of type Fields
446       * @param countField     of type Fields
447       */
448      @ConstructorProperties({"pipe", "groupingFields", "valueFields", "countField"})
449      public CountBy( Pipe pipe, Fields groupingFields, Fields valueFields, Fields countField )
450        {
451        this( null, pipe, groupingFields, valueFields, countField, Include.ALL );
452        }
453    
454      /**
455       * Constructor CountBy creates a new CountBy instance.
456       *
457       * @param pipe           of type Pipe
458       * @param groupingFields of type Fields
459       * @param valueFields    of type Fields
460       * @param countField     fo type Fields
461       * @param threshold      of type int
462       */
463      @ConstructorProperties({"pipe", "groupingFields", "valueFields", "countField", "threshold"})
464      public CountBy( Pipe pipe, Fields groupingFields, Fields valueFields, Fields countField, int threshold )
465        {
466        this( null, pipe, groupingFields, valueFields, countField, threshold );
467        }
468    
469      /**
470       * Constructor CountBy creates a new CountBy instance.
471       *
472       * @param name           of type String
473       * @param pipe           of type Pipe
474       * @param groupingFields of type Fields
475       * @param valueFields    of type Fields
476       * @param countField     of type Fields
477       */
478      @ConstructorProperties({"name", "pipe", "groupingFields", "valueFields", "countField"})
479      public CountBy( String name, Pipe pipe, Fields groupingFields, Fields valueFields, Fields countField )
480        {
481        this( name, pipe, groupingFields, valueFields, countField, USE_DEFAULT_THRESHOLD );
482        }
483    
484      /**
485       * Constructor CountBy creates a new CountBy instance.
486       *
487       * @param name           of type String
488       * @param pipe           of type Pipe
489       * @param groupingFields of type Fields
490       * @param valueFields    of type Fields
491       * @param countField     of type Fields
492       * @param threshold      of type int
493       */
494      @ConstructorProperties({"name", "pipe", "groupingFields", "valueFields", "countField", "threshold"})
495      public CountBy( String name, Pipe pipe, Fields groupingFields, Fields valueFields, Fields countField, int threshold )
496        {
497        this( name, Pipe.pipes( pipe ), groupingFields, valueFields, countField, threshold );
498        }
499    
500      /**
501       * Constructor CountBy creates a new CountBy instance.
502       *
503       * @param pipes          of type Pipe[]
504       * @param groupingFields of type Fields
505       * @param valueFields    of type Fields
506       * @param countField     of type Fields
507       */
508      @ConstructorProperties({"pipes", "groupingFields", "valueFields", "countField"})
509      public CountBy( Pipe[] pipes, Fields groupingFields, Fields valueFields, Fields countField )
510        {
511        this( null, pipes, groupingFields, valueFields, countField, USE_DEFAULT_THRESHOLD );
512        }
513    
514      /**
515       * Constructor CountBy creates a new CountBy instance.
516       *
517       * @param pipes          of type Pipe[]
518       * @param groupingFields of type Fields
519       * @param valueFields    of type Fields
520       * @param countField     of type Fields
521       * @param threshold      of type int
522       */
523      @ConstructorProperties({"pipes", "groupingFields", "valueFields", "countField", "threshold"})
524      public CountBy( Pipe[] pipes, Fields groupingFields, Fields valueFields, Fields countField, int threshold )
525        {
526        this( null, pipes, groupingFields, valueFields, countField, threshold );
527        }
528    
529      /**
530       * Constructor CountBy creates a new CountBy instance.
531       *
532       * @param name           of type String
533       * @param pipes          of type Pipe[]
534       * @param groupingFields of type Fields
535       * @param valueFields    of type Fields
536       * @param countField     of type Fields
537       */
538      @ConstructorProperties({"name", "pipes", "groupingFields", "valueFields", "countField"})
539      public CountBy( String name, Pipe[] pipes, Fields groupingFields, Fields valueFields, Fields countField )
540        {
541        this( name, pipes, groupingFields, valueFields, countField, USE_DEFAULT_THRESHOLD );
542        }
543    
544      /**
545       * Constructor CountBy creates a new CountBy instance.
546       *
547       * @param name           of type String
548       * @param pipes          of type Pipe[]
549       * @param groupingFields of type Fields
550       * @param valueFields    of type Fields
551       * @param countField     of type Fields
552       * @param threshold      of type int
553       */
554      @ConstructorProperties({"name", "pipes", "groupingFields", "valueFields", "countField", "threshold"})
555      public CountBy( String name, Pipe[] pipes, Fields groupingFields, Fields valueFields, Fields countField, int threshold )
556        {
557        super( name, pipes, groupingFields, valueFields, new CountPartials( countField.applyTypes( Long.TYPE ) ), new Sum( countField.applyTypes( Long.TYPE ) ), threshold );
558        }
559    
560    ////////////
561    
562      /**
563       * Constructor CountBy creates a new CountBy instance.
564       *
565       * @param pipe           of type Pipe
566       * @param groupingFields of type Fields
567       * @param valueFields    of type Fields
568       * @param countField     of type Fields
569       * @param include        of type Include
570       */
571      @ConstructorProperties({"pipe", "groupingFields", "valueFields", "countField", "include"})
572      public CountBy( Pipe pipe, Fields groupingFields, Fields valueFields, Fields countField, Include include )
573        {
574        this( null, pipe, groupingFields, valueFields, countField, include );
575        }
576    
577      /**
578       * Constructor CountBy creates a new CountBy instance.
579       *
580       * @param pipe           of type Pipe
581       * @param groupingFields of type Fields
582       * @param valueFields    of type Fields
583       * @param countField     fo type Fields
584       * @param include        of type Include
585       * @param threshold      of type int
586       */
587      @ConstructorProperties({"pipe", "groupingFields", "valueFields", "countField", "include", "threshold"})
588      public CountBy( Pipe pipe, Fields groupingFields, Fields valueFields, Fields countField, Include include, int threshold )
589        {
590        this( null, pipe, groupingFields, valueFields, countField, include, threshold );
591        }
592    
593      /**
594       * Constructor CountBy creates a new CountBy instance.
595       *
596       * @param name           of type String
597       * @param pipe           of type Pipe
598       * @param valueFields    of type Fields
599       * @param groupingFields of type Fields
600       * @param countField     of type Fields
601       * @param include        of type Include
602       */
603      @ConstructorProperties({"name", "pipe", "groupingFields", "valueFields", "countField", "include"})
604      public CountBy( String name, Pipe pipe, Fields groupingFields, Fields valueFields, Fields countField, Include include )
605        {
606        this( name, pipe, groupingFields, valueFields, countField, include, USE_DEFAULT_THRESHOLD );
607        }
608    
609      /**
610       * Constructor CountBy creates a new CountBy instance.
611       *
612       * @param name           of type String
613       * @param pipe           of type Pipe
614       * @param groupingFields of type Fields
615       * @param valueFields    of type Fields
616       * @param countField     of type Fields
617       * @param include        of type Include
618       * @param threshold      of type int
619       */
620      @ConstructorProperties({"name", "pipe", "groupingFields", "valueFields", "countField", "include", "threshold"})
621      public CountBy( String name, Pipe pipe, Fields groupingFields, Fields valueFields, Fields countField, Include include, int threshold )
622        {
623        this( name, Pipe.pipes( pipe ), groupingFields, valueFields, countField, include, threshold );
624        }
625    
626      /**
627       * Constructor CountBy creates a new CountBy instance.
628       *
629       * @param pipes          of type Pipe[]
630       * @param groupingFields of type Fields
631       * @param valueFields    of type Fields
632       * @param countField     of type Fields
633       * @param include        of type Include
634       */
635      @ConstructorProperties({"pipes", "groupingFields", "valueFields", "countField", "include"})
636      public CountBy( Pipe[] pipes, Fields groupingFields, Fields valueFields, Fields countField, Include include )
637        {
638        this( null, pipes, groupingFields, valueFields, countField, include, USE_DEFAULT_THRESHOLD );
639        }
640    
641      /**
642       * Constructor CountBy creates a new CountBy instance.
643       *
644       * @param pipes          of type Pipe[]
645       * @param groupingFields of type Fields
646       * @param valueFields    of type Fields
647       * @param countField     of type Fields
648       * @param include        of type Include
649       * @param threshold      of type int
650       */
651      @ConstructorProperties({"pipes", "groupingFields", "valueFields", "countField", "include", "threshold"})
652      public CountBy( Pipe[] pipes, Fields groupingFields, Fields valueFields, Fields countField, Include include, int threshold )
653        {
654        this( null, pipes, groupingFields, valueFields, countField, include, threshold );
655        }
656    
657      /**
658       * Constructor CountBy creates a new CountBy instance.
659       *
660       * @param name           of type String
661       * @param pipes          of type Pipe[]
662       * @param groupingFields of type Fields
663       * @param valueFields    of type Fields
664       * @param countField     of type Fields
665       * @param include        of type Include
666       */
667      @ConstructorProperties({"name", "pipes", "groupingFields", "valueFields", "countField", "include"})
668      public CountBy( String name, Pipe[] pipes, Fields groupingFields, Fields valueFields, Fields countField, Include include )
669        {
670        this( name, pipes, groupingFields, valueFields, countField, include, USE_DEFAULT_THRESHOLD );
671        }
672    
673      /**
674       * Constructor CountBy creates a new CountBy instance.
675       *
676       * @param name           of type String
677       * @param pipes          of type Pipe[]
678       * @param groupingFields of type Fields
679       * @param valueFields    of type Fields
680       * @param countField     of type Fields
681       * @param include        of type Include
682       * @param threshold      of type int
683       */
684      @ConstructorProperties({"name", "pipes", "groupingFields", "valueFields", "countField", "include", "threshold"})
685      public CountBy( String name, Pipe[] pipes, Fields groupingFields, Fields valueFields, Fields countField, Include include, int threshold )
686        {
687        super( name, pipes, groupingFields, valueFields, new CountPartials( countField.applyTypes( Long.TYPE ), include ), new Sum( countField.applyTypes( Long.TYPE ) ), threshold );
688        }
689      }