org.apache.datasketches.pig.sampling

## Class DataToVarOptSketch

- java.lang.Object
- - org.apache.pig.EvalFunc<T>
  - - org.apache.pig.AccumulatorEvalFunc<org.apache.pig.data.DataByteArray>
    - - org.apache.datasketches.pig.sampling.DataToVarOptSketch

All Implemented Interfaces:
  org.apache.pig.Accumulator<org.apache.pig.data.DataByteArray>, org.apache.pig.Algebraic

    public class DataToVarOptSketch
    extends org.apache.pig.AccumulatorEvalFunc<org.apache.pig.data.DataByteArray>
    implements org.apache.pig.Algebraic

Creates a binary version of a VarOpt sampling over input tuples. The resulting `DataByteArray` can be read in Pig with `GetVarOptSamples`, although the per-record schema will be lost. It implements both the `Accumulator` and `Algebraic` interfaces for efficient performance.

Author:
  Jon Malkin

### Nested Class Summary

### Nested classes/interfaces inherited from class org.apache.pig.EvalFunc

`org.apache.pig.EvalFunc.SchemaType`

### Field Summary

### Fields inherited from class org.apache.pig.EvalFunc

`log, pigLogger, reporter, returnType`

### Constructor Summary

Constructors
Constructor and Description
`DataToVarOptSketch(String kStr)` VarOpt sampling constructor.
`DataToVarOptSketch(String kStr, String weightIdxStr)` VarOpt sampling constructor.

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `accumulate(org.apache.pig.data.Tuple inputTuple)`
`void` `cleanup()`
`String` `getFinal()`
`String` `getInitial()`
`String` `getIntermed()`
`org.apache.pig.data.DataByteArray` `getValue()`
`org.apache.pig.impl.logicalLayer.schema.Schema` `outputSchema(org.apache.pig.impl.logicalLayer.schema.Schema input)`

### Methods inherited from class org.apache.pig.AccumulatorEvalFunc

`exec`

### Methods inherited from class org.apache.pig.EvalFunc

`allowCompileTimeCalculation, finish, getArgToFuncMapping, getCacheFiles, getInputSchema, getLoadCaster, getLogger, getPigLogger, getReporter, getReturnType, getSchemaName, getSchemaType, getShipFiles, isAsynchronous, needEndOfAllInputProcessing, progress, setEndOfAllInput, setInputSchema, setPigLogger, setReporter, setUDFContextSignature, warn`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### DataToVarOptSketch

    public DataToVarOptSketch(String kStr)

VarOpt sampling constructor.

Parameters:
  `kStr` - String indicating the maximum number of desired entries in the reservoir.

#### DataToVarOptSketch

    public DataToVarOptSketch(String kStr,
                              String weightIdxStr)

VarOpt sampling constructor.

Parameters:
  `kStr` - String indicating the maximum number of desired samples to return.
  `weightIdxStr` - String indicating column index (0-based) of weight values

### Method Detail

#### accumulate

    public void accumulate(org.apache.pig.data.Tuple inputTuple)
                    throws IOException

Specified by:
  `accumulate` in interface `org.apache.pig.Accumulator<org.apache.pig.data.DataByteArray>`
Specified by:
  `accumulate` in class `org.apache.pig.AccumulatorEvalFunc<org.apache.pig.data.DataByteArray>`
Throws:
  `IOException`

#### getValue

    public org.apache.pig.data.DataByteArray getValue()

Specified by:
  `getValue` in interface `org.apache.pig.Accumulator<org.apache.pig.data.DataByteArray>`
Specified by:
  `getValue` in class `org.apache.pig.AccumulatorEvalFunc<org.apache.pig.data.DataByteArray>`

#### cleanup

    public void cleanup()

Specified by:
  `cleanup` in interface `org.apache.pig.Accumulator<org.apache.pig.data.DataByteArray>`
Specified by:
  `cleanup` in class `org.apache.pig.AccumulatorEvalFunc<org.apache.pig.data.DataByteArray>`

#### getInitial

    public String getInitial()

Specified by:
  `getInitial` in interface `org.apache.pig.Algebraic`

#### getIntermed

    public String getIntermed()

Specified by:
  `getIntermed` in interface `org.apache.pig.Algebraic`

#### getFinal

    public String getFinal()

Specified by:
  `getFinal` in interface `org.apache.pig.Algebraic`

#### outputSchema

    public org.apache.pig.impl.logicalLayer.schema.Schema outputSchema(org.apache.pig.impl.logicalLayer.schema.Schema input)

Overrides:
  `outputSchema` in class `org.apache.pig.EvalFunc<org.apache.pig.data.DataByteArray>`