@Test public void testCorrectedSumOfSquares() { Schema schema = Schema.recordOf("test", Schema.Field.of("x", Schema.of(Schema.Type.INT))); CorrectedSumOfSquares correctedSumOfSquares = new CorrectedSumOfSquares("x", Schema.of(Schema.Type.INT)); CorrectedSumOfSquares correctedSumOfSquares1 = new CorrectedSumOfSquares("x", Schema.of(Schema.Type.INT)); testFunction(correctedSumOfSquares, schema, correctedSumOfSquares1, 0d, 0); testFunction(correctedSumOfSquares, schema, correctedSumOfSquares1, 17.5d, 1, 2, 3, 4, 5, 6); testFunction(correctedSumOfSquares, schema, correctedSumOfSquares1, 7946.75d, -10, 0, 3, 100); }
public CorrectedSumOfSquares(String fieldName, Schema fieldSchema) { this.fieldName = fieldName; boolean isNullable = fieldSchema.isNullable(); Schema.Type fieldType = isNullable ? fieldSchema.getNonNullable().getType() : fieldSchema.getType(); if (!AggregationUtils.isNumericType(fieldType)) { throw new IllegalArgumentException(String.format( "Cannot compute corrected sum of squares on field %s because its type %s is not numeric", fieldName, fieldType)); } outputSchema = isNullable ? Schema.nullableOf(Schema.of(Schema.Type.DOUBLE)) : Schema.of(Schema.Type.DOUBLE); }
CorrectedSumOfSquares implements AggregateFunction<Double, CorrectedSumOfSquares> { public CorrectedSumOfSquares(String fieldName, Schema fieldSchema) { this.fieldName = fieldName; boolean isNullable = fieldSchema.isNullable(); Schema.Type fieldType = isNullable ? fieldSchema.getNonNullable().getType() : fieldSchema.getType(); if (!AggregationUtils.isNumericType(fieldType)) { throw new IllegalArgumentException(String.format( "Cannot compute corrected sum of squares on field %s because its type %s is not numeric", fieldName, fieldType)); } outputSchema = isNullable ? Schema.nullableOf(Schema.of(Schema.Type.DOUBLE)) : Schema.of(Schema.Type.DOUBLE); } }
CorrectedSumOfSquares implements AggregateFunction<Double, CorrectedSumOfSquares> { public CorrectedSumOfSquares(String fieldName, Schema fieldSchema) { this.fieldName = fieldName; boolean isNullable = fieldSchema.isNullable(); Schema.Type fieldType = isNullable ? fieldSchema.getNonNullable().getType() : fieldSchema.getType(); if (!AggregationUtils.isNumericType(fieldType)) { throw new IllegalArgumentException(String.format( "Cannot compute corrected sum of squares on field %s because its type %s is not numeric", fieldName, fieldType)); } outputSchema = isNullable ? Schema.nullableOf(Schema.of(Schema.Type.DOUBLE)) : Schema.of(Schema.Type.DOUBLE); } CorrectedSumOfSquares(String fieldName, Schema fieldSchema); }
CorrectedSumOfSquares implements AggregateFunction<Double, CorrectedSumOfSquares> { public CorrectedSumOfSquares(String fieldName, Schema fieldSchema) { this.fieldName = fieldName; boolean isNullable = fieldSchema.isNullable(); Schema.Type fieldType = isNullable ? fieldSchema.getNonNullable().getType() : fieldSchema.getType(); if (!AggregationUtils.isNumericType(fieldType)) { throw new IllegalArgumentException(String.format( "Cannot compute corrected sum of squares on field %s because its type %s is not numeric", fieldName, fieldType)); } outputSchema = isNullable ? Schema.nullableOf(Schema.of(Schema.Type.DOUBLE)) : Schema.of(Schema.Type.DOUBLE); } CorrectedSumOfSquares(String fieldName, Schema fieldSchema); @Override void initialize(); @Override void mergeValue(StructuredRecord record); @Override void mergeAggregates(CorrectedSumOfSquares otherAgg); @Override Double getAggregate(); @Override Schema getOutputSchema(); }
CorrectedSumOfSquares implements AggregateFunction<Double, CorrectedSumOfSquares> { public CorrectedSumOfSquares(String fieldName, Schema fieldSchema) { this.fieldName = fieldName; boolean isNullable = fieldSchema.isNullable(); Schema.Type fieldType = isNullable ? fieldSchema.getNonNullable().getType() : fieldSchema.getType(); if (!AggregationUtils.isNumericType(fieldType)) { throw new IllegalArgumentException(String.format( "Cannot compute corrected sum of squares on field %s because its type %s is not numeric", fieldName, fieldType)); } outputSchema = isNullable ? Schema.nullableOf(Schema.of(Schema.Type.DOUBLE)) : Schema.of(Schema.Type.DOUBLE); } CorrectedSumOfSquares(String fieldName, Schema fieldSchema); @Override void initialize(); @Override void mergeValue(StructuredRecord record); @Override void mergeAggregates(CorrectedSumOfSquares otherAgg); @Override Double getAggregate(); @Override Schema getOutputSchema();  }