Skip to content

Commit

Permalink
These are all code cleanup changes.
Browse files Browse the repository at this point in the history
Vast majority: Fixing unqualified access to class members (by adding
"this.").

A few cases of: Removing redundant generic attributes.
  • Loading branch information
leerho committed Mar 3, 2021
1 parent e70423a commit 29292bd
Show file tree
Hide file tree
Showing 54 changed files with 403 additions and 400 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public static class DataToSketchEvaluator extends SketchEvaluator {
public AggregationBuffer getNewAggregationBuffer() throws HiveException {
// Different State is used for the iterate phase and the merge phase.
// SketchState is more space-efficient, so let's use SketchState if possible.
if (mode_ == Mode.PARTIAL1 || mode_ == Mode.COMPLETE) { // iterate() will be used
if (this.mode_ == Mode.PARTIAL1 || this.mode_ == Mode.COMPLETE) { // iterate() will be used
return new SketchState();
}
return new UnionState();
Expand All @@ -141,19 +141,19 @@ public AggregationBuffer getNewAggregationBuffer() throws HiveException {
@Override
public ObjectInspector init(final Mode mode, final ObjectInspector[] parameters) throws HiveException {
super.init(mode, parameters);
mode_ = mode;
this.mode_ = mode;
if (mode == Mode.PARTIAL1 || mode == Mode.COMPLETE) {
// input is original data
inputInspector_ = (PrimitiveObjectInspector) parameters[0];
this.inputInspector_ = (PrimitiveObjectInspector) parameters[0];
if (parameters.length > 1) {
lgKInspector_ = (PrimitiveObjectInspector) parameters[1];
this.lgKInspector_ = (PrimitiveObjectInspector) parameters[1];
}
if (parameters.length > 2) {
seedInspector_ = (PrimitiveObjectInspector) parameters[2];
this.seedInspector_ = (PrimitiveObjectInspector) parameters[2];
}
} else {
// input for PARTIAL2 and FINAL is the output from PARTIAL1
intermediateInspector_ = (StructObjectInspector) parameters[0];
this.intermediateInspector_ = (StructObjectInspector) parameters[0];
}

if (mode == Mode.PARTIAL1 || mode == Mode.PARTIAL2) {
Expand Down Expand Up @@ -181,24 +181,25 @@ public ObjectInspector init(final Mode mode, final ObjectInspector[] parameters)
* java.lang.Object[])
*/
@Override
public void iterate(final @SuppressWarnings("deprecation") AggregationBuffer agg,
@SuppressWarnings("deprecation")
public void iterate(final AggregationBuffer agg,
final Object[] parameters) throws HiveException {
if (parameters[0] == null) { return; }
final SketchState state = (SketchState) agg;
if (!state.isInitialized()) {
initializeState(state, parameters);
}
state.update(parameters[0], inputInspector_);
state.update(parameters[0], this.inputInspector_);
}

private void initializeState(final State state, final Object[] parameters) {
int lgK = DEFAULT_LG_K;
if (lgKInspector_ != null) {
lgK = PrimitiveObjectInspectorUtils.getInt(parameters[1], lgKInspector_);
if (this.lgKInspector_ != null) {
lgK = PrimitiveObjectInspectorUtils.getInt(parameters[1], this.lgKInspector_);
}
long seed = DEFAULT_UPDATE_SEED;
if (seedInspector_ != null) {
seed = PrimitiveObjectInspectorUtils.getLong(parameters[2], seedInspector_);
if (this.seedInspector_ != null) {
seed = PrimitiveObjectInspectorUtils.getLong(parameters[2], this.seedInspector_);
}
state.init(lgK, seed);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,24 @@ public Object terminatePartial(final @SuppressWarnings("deprecation") Aggregatio
}

@Override
public void merge(final @SuppressWarnings("deprecation") AggregationBuffer buf, final Object data)
@SuppressWarnings("deprecation")
public void merge(final AggregationBuffer buf, final Object data)
throws HiveException {
if (data == null) { return; }
final UnionState state = (UnionState) buf;
if (!state.isInitialized()) {
initializeState(state, data);
}
final BytesWritable serializedSketch = (BytesWritable) intermediateInspector_.getStructFieldData(
data, intermediateInspector_.getStructFieldRef(SKETCH_FIELD));
final BytesWritable serializedSketch = (BytesWritable) this.intermediateInspector_.getStructFieldData(
data, this.intermediateInspector_.getStructFieldRef(SKETCH_FIELD));
state.update(CpcSketch.heapify(BytesWritableHelper.wrapAsMemory(serializedSketch), state.getSeed()));
}

private void initializeState(final UnionState state, final Object data) {
final int lgK = ((IntWritable) intermediateInspector_.getStructFieldData(
data, intermediateInspector_.getStructFieldRef(LG_K_FIELD))).get();
final long seed = ((LongWritable) intermediateInspector_.getStructFieldData(
data, intermediateInspector_.getStructFieldRef(SEED_FIELD))).get();
final int lgK = ((IntWritable) this.intermediateInspector_.getStructFieldData(
data, this.intermediateInspector_.getStructFieldRef(LG_K_FIELD))).get();
final long seed = ((LongWritable) this.intermediateInspector_.getStructFieldData(
data, this.intermediateInspector_.getStructFieldRef(SEED_FIELD))).get();
state.init(lgK, seed);
}

Expand Down
28 changes: 14 additions & 14 deletions src/main/java/org/apache/datasketches/hive/cpc/SketchState.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,47 +29,47 @@ class SketchState extends State {

@Override
boolean isInitialized() {
return sketch_ != null;
return this.sketch_ != null;
}

@Override
void init(final int logK, final long seed) {
super.init(logK, seed);
sketch_ = new CpcSketch(logK, seed);
this.sketch_ = new CpcSketch(logK, seed);
}

void update(final Object data, final PrimitiveObjectInspector objectInspector) {
switch (objectInspector.getPrimitiveCategory()) {
case BINARY:
sketch_.update(PrimitiveObjectInspectorUtils.getBinary(data, objectInspector)
this.sketch_.update(PrimitiveObjectInspectorUtils.getBinary(data, objectInspector)
.copyBytes());
return;
case BYTE:
sketch_.update(PrimitiveObjectInspectorUtils.getByte(data, objectInspector));
this.sketch_.update(PrimitiveObjectInspectorUtils.getByte(data, objectInspector));
return;
case DOUBLE:
sketch_.update(PrimitiveObjectInspectorUtils.getDouble(data, objectInspector));
this.sketch_.update(PrimitiveObjectInspectorUtils.getDouble(data, objectInspector));
return;
case FLOAT:
sketch_.update(PrimitiveObjectInspectorUtils.getFloat(data, objectInspector));
this.sketch_.update(PrimitiveObjectInspectorUtils.getFloat(data, objectInspector));
return;
case INT:
sketch_.update(PrimitiveObjectInspectorUtils.getInt(data, objectInspector));
this.sketch_.update(PrimitiveObjectInspectorUtils.getInt(data, objectInspector));
return;
case LONG:
sketch_.update(PrimitiveObjectInspectorUtils.getLong(data, objectInspector));
this.sketch_.update(PrimitiveObjectInspectorUtils.getLong(data, objectInspector));
return;
case STRING:
// conversion to char[] avoids costly UTF-8 encoding
sketch_.update(PrimitiveObjectInspectorUtils.getString(data, objectInspector)
this.sketch_.update(PrimitiveObjectInspectorUtils.getString(data, objectInspector)
.toCharArray());
return;
case CHAR:
sketch_.update(PrimitiveObjectInspectorUtils.getHiveChar(data, objectInspector)
this.sketch_.update(PrimitiveObjectInspectorUtils.getHiveChar(data, objectInspector)
.getValue().toCharArray());
return;
case VARCHAR:
sketch_.update(PrimitiveObjectInspectorUtils.getHiveVarchar(data, objectInspector)
this.sketch_.update(PrimitiveObjectInspectorUtils.getHiveVarchar(data, objectInspector)
.getValue().toCharArray());
return;
default:
Expand All @@ -82,13 +82,13 @@ void update(final Object data, final PrimitiveObjectInspector objectInspector) {

@Override
CpcSketch getResult() {
if (sketch_ == null) { return null; }
return sketch_;
if (this.sketch_ == null) { return null; }
return this.sketch_;
}

@Override
void reset() {
sketch_ = null;
this.sketch_ = null;
}

}
8 changes: 4 additions & 4 deletions src/main/java/org/apache/datasketches/hive/cpc/State.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ abstract class State extends AbstractAggregationBuffer {
private long seed_;

void init(final int lgK, final long seed) {
lgK_ = lgK;
seed_ = seed;
this.lgK_ = lgK;
this.seed_ = seed;
}

int getLgK() {
return lgK_;
return this.lgK_;
}

long getSeed() {
return seed_;
return this.seed_;
}

abstract boolean isInitialized();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,16 @@ public ObjectInspector init(final Mode mode, final ObjectInspector[] parameters)
super.init(mode, parameters);

if ((mode == Mode.PARTIAL1) || (mode == Mode.COMPLETE)) {
inputInspector_ = (PrimitiveObjectInspector) parameters[0];
this.inputInspector_ = (PrimitiveObjectInspector) parameters[0];
if (parameters.length > 1) {
lgKInspector_ = (PrimitiveObjectInspector) parameters[1];
this.lgKInspector_ = (PrimitiveObjectInspector) parameters[1];
}
if (parameters.length > 2) {
seedInspector_ = (PrimitiveObjectInspector) parameters[2];
this.seedInspector_ = (PrimitiveObjectInspector) parameters[2];
}
} else {
// mode = partial2 || final
intermediateInspector_ = (StandardStructObjectInspector) parameters[0];
this.intermediateInspector_ = (StandardStructObjectInspector) parameters[0];
}

if ((mode == Mode.PARTIAL1) || (mode == Mode.PARTIAL2)) {
Expand Down Expand Up @@ -173,19 +173,19 @@ public void iterate(final @SuppressWarnings("deprecation") AggregationBuffer buf
if (!state.isInitialized()) {
initializeState(state, parameters);
}
final byte[] serializedSketch = (byte[]) inputInspector_.getPrimitiveJavaObject(parameters[0]);
final byte[] serializedSketch = (byte[]) this.inputInspector_.getPrimitiveJavaObject(parameters[0]);
if (serializedSketch == null) { return; }
state.update(CpcSketch.heapify(Memory.wrap(serializedSketch), state.getSeed()));
}

private void initializeState(final UnionState state, final Object[] parameters) {
int lgK = DEFAULT_LG_K;
if (lgKInspector_ != null) {
lgK = PrimitiveObjectInspectorUtils.getInt(parameters[1], lgKInspector_);
if (this.lgKInspector_ != null) {
lgK = PrimitiveObjectInspectorUtils.getInt(parameters[1], this.lgKInspector_);
}
long seed = DEFAULT_UPDATE_SEED;
if (seedInspector_ != null) {
seed = PrimitiveObjectInspectorUtils.getLong(parameters[2], seedInspector_);
if (this.seedInspector_ != null) {
seed = PrimitiveObjectInspectorUtils.getLong(parameters[2], this.seedInspector_);
}
state.init(lgK, seed);
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/apache/datasketches/hive/cpc/UnionState.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,28 @@ class UnionState extends State {

@Override
boolean isInitialized() {
return union_ != null;
return this.union_ != null;
}

@Override
void init(final int lgK, final long seed) {
super.init(lgK, seed);
union_ = new CpcUnion(lgK, seed);
this.union_ = new CpcUnion(lgK, seed);
}

void update(final CpcSketch sketch) {
union_.update(sketch);
this.union_.update(sketch);
}

@Override
CpcSketch getResult() {
if (union_ == null) { return null; }
return union_.getResult();
if (this.union_ == null) { return null; }
return this.union_.getResult();
}

@Override
void reset() {
union_ = null;
this.union_ = null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public ObjectInspector init(final Mode mode, final ObjectInspector[] parameters)
// In PARTIAL2 and FINAL mode, the parameters are just partial aggregations.
if ((mode == Mode.PARTIAL1) || (mode == Mode.COMPLETE)) {
if (parameters.length > 1) {
maxMapSizeObjectInspector = (PrimitiveObjectInspector) parameters[1];
this.maxMapSizeObjectInspector = (PrimitiveObjectInspector) parameters[1];
}
}

Expand All @@ -98,10 +98,10 @@ public void iterate(final AggregationBuffer buf, final Object[] data) throws Hiv
@SuppressWarnings("unchecked")
final ItemsState<T> state = (ItemsState<T>) buf;
if (!state.isInitialized()) {
final int maxMapSize = PrimitiveObjectInspectorUtils.getInt(data[1], maxMapSizeObjectInspector);
final int maxMapSize = PrimitiveObjectInspectorUtils.getInt(data[1], this.maxMapSizeObjectInspector);
state.init(maxMapSize);
}
state.update(extractValue(data[0], inputObjectInspector));
state.update(extractValue(data[0], this.inputObjectInspector));
}

public abstract T extractValue(final Object data, final ObjectInspector objectInspector)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static class DataToStringsSketchEvaluator extends DataToItemsSketchEvaluator<Str
@Override
public String extractValue(final Object data, final ObjectInspector objectInspector)
throws HiveException {
final Object value = inputObjectInspector.getPrimitiveJavaObject(data);
final Object value = this.inputObjectInspector.getPrimitiveJavaObject(data);
if (value instanceof String) {
return (String) value;
} else if (value instanceof HiveChar) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,22 @@ public StructObjectInspector initialize(final ObjectInspector[] inspectors) thro
throw new UDFArgumentTypeException(0, "Primitive argument expected, but "
+ inspectors[0].getCategory().name() + " was recieved");
}
inputObjectInspector = (PrimitiveObjectInspector) inspectors[0];
if (inputObjectInspector.getPrimitiveCategory() != PrimitiveObjectInspector.PrimitiveCategory.BINARY) {
this.inputObjectInspector = (PrimitiveObjectInspector) inspectors[0];
if (this.inputObjectInspector.getPrimitiveCategory() != PrimitiveObjectInspector.PrimitiveCategory.BINARY) {
throw new UDFArgumentTypeException(0, "Binary value expected as the first argument, but "
+ inputObjectInspector.getPrimitiveCategory().name() + " was recieved");
+ this.inputObjectInspector.getPrimitiveCategory().name() + " was recieved");
}

if (inspectors.length > 1) {
if (inspectors[1].getCategory() != ObjectInspector.Category.PRIMITIVE) {
throw new UDFArgumentTypeException(1, "Primitive argument expected, but "
+ inspectors[1].getCategory().name() + " was recieved");
}
errorTypeObjectInspector = (PrimitiveObjectInspector) inspectors[1];
if (errorTypeObjectInspector.getPrimitiveCategory()
this.errorTypeObjectInspector = (PrimitiveObjectInspector) inspectors[1];
if (this.errorTypeObjectInspector.getPrimitiveCategory()
!= PrimitiveObjectInspector.PrimitiveCategory.STRING) {
throw new UDFArgumentTypeException(1, "String value expected as the first argument, but "
+ errorTypeObjectInspector.getPrimitiveCategory().name() + " was recieved");
+ this.errorTypeObjectInspector.getPrimitiveCategory().name() + " was recieved");
}
}

Expand All @@ -92,12 +92,12 @@ public StructObjectInspector initialize(final ObjectInspector[] inspectors) thro
public void process(final Object[] data) throws HiveException {
if (data == null || data[0] == null) { return; }
final BytesWritable serializedSketch =
(BytesWritable) inputObjectInspector.getPrimitiveWritableObject(data[0]);
(BytesWritable) this.inputObjectInspector.getPrimitiveWritableObject(data[0]);
final ItemsSketch<String> sketch = ItemsSketch.getInstance(
BytesWritableHelper.wrapAsMemory(serializedSketch), new ArrayOfStringsSerDe());
ErrorType errorType = ErrorType.NO_FALSE_POSITIVES;
if (data.length > 1) {
errorType = ErrorType.valueOf((String) errorTypeObjectInspector.getPrimitiveJavaObject(data[1]));
errorType = ErrorType.valueOf((String) this.errorTypeObjectInspector.getPrimitiveJavaObject(data[1]));
}
final ItemsSketch.Row<String>[] result = sketch.getFrequentItems(errorType);
for (int i = 0; i < result.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ abstract class ItemsEvaluator<T> extends GenericUDAFEvaluator {
protected PrimitiveObjectInspector inputObjectInspector;

ItemsEvaluator(final ArrayOfItemsSerDe<T> serDe) {
serDe_ = serDe;
this.serDe_ = serDe;
}

@Override
public ObjectInspector init(final Mode mode, final ObjectInspector[] parameters) throws HiveException {
super.init(mode, parameters);
inputObjectInspector = (PrimitiveObjectInspector) parameters[0];
this.inputObjectInspector = (PrimitiveObjectInspector) parameters[0];
return PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(PrimitiveCategory.BINARY);
}

Expand All @@ -68,7 +68,7 @@ public void merge(final AggregationBuffer buf, final Object data) throws HiveExc
@SuppressWarnings("unchecked")
final ItemsState<T> state = (ItemsState<T>) buf;
final Memory serializedSketch = BytesWritableHelper.wrapAsMemory(
(BytesWritable) inputObjectInspector.getPrimitiveWritableObject(data));
(BytesWritable) this.inputObjectInspector.getPrimitiveWritableObject(data));
state.update(serializedSketch);
}

Expand All @@ -79,13 +79,13 @@ public Object terminate(final AggregationBuffer buf) throws HiveException {
final ItemsState<T> state = (ItemsState<T>) buf;
final ItemsSketch<T> resultSketch = state.getResult();
if (resultSketch == null) { return null; }
return new BytesWritable(resultSketch.toByteArray(serDe_));
return new BytesWritable(resultSketch.toByteArray(this.serDe_));
}

@SuppressWarnings("deprecation")
@Override
public AggregationBuffer getNewAggregationBuffer() throws HiveException {
return new ItemsState<>(serDe_);
return new ItemsState<>(this.serDe_);
}

}
Loading

0 comments on commit 29292bd

Please sign in to comment.