Repository: incubator-hivemall Updated Branches: refs/heads/master e63494998 -> 1add38b6d
Apply formatter Project: http://git-wip-us.apache.org/repos/asf/incubator-hivemall/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-hivemall/commit/1add38b6 Tree: http://git-wip-us.apache.org/repos/asf/incubator-hivemall/tree/1add38b6 Diff: http://git-wip-us.apache.org/repos/asf/incubator-hivemall/diff/1add38b6 Branch: refs/heads/master Commit: 1add38b6d0c0a5bc3c6e3d28231dca2539a18a3b Parents: e634949 Author: Takuya Kitazawa <[email protected]> Authored: Mon Dec 18 09:55:57 2017 +0900 Committer: Takuya Kitazawa <[email protected]> Committed: Mon Dec 18 09:55:57 2017 +0900 ---------------------------------------------------------------------- .../KernelExpansionPassiveAggressiveUDTF.java | 3 +- .../hivemall/fm/FactorizationMachineUDTF.java | 33 +++++---- .../fm/FieldAwareFactorizationMachineUDTF.java | 14 ++-- .../java/hivemall/math/matrix/FloatMatrix.java | 3 +- .../builders/ColumnMajorDenseMatrixBuilder.java | 3 +- .../matrix/sparse/floats/DoKFloatMatrix.java | 7 +- .../main/java/hivemall/recommend/SlimUDTF.java | 78 ++++++++++---------- .../sketch/hll/ApproxCountDistinctUDAF.java | 10 +-- .../hivemall/utils/collections/Fastutil.java | 46 ++++++------ .../java/hivemall/utils/hadoop/HiveUtils.java | 50 ++++++------- 10 files changed, 119 insertions(+), 128 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/1add38b6/core/src/main/java/hivemall/classifier/KernelExpansionPassiveAggressiveUDTF.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/classifier/KernelExpansionPassiveAggressiveUDTF.java b/core/src/main/java/hivemall/classifier/KernelExpansionPassiveAggressiveUDTF.java index 4ecc028..731083d 100644 --- a/core/src/main/java/hivemall/classifier/KernelExpansionPassiveAggressiveUDTF.java +++ b/core/src/main/java/hivemall/classifier/KernelExpansionPassiveAggressiveUDTF.java @@ -116,8 +116,7 @@ public final class KernelExpansionPassiveAggressiveUDTF extends BinaryOnlineClas if (c_str != null) { c = Float.parseFloat(c_str); if (c <= 0.f) { - throw new UDFArgumentException( - "Aggressiveness parameter C must be C > 0: " + c); + throw new UDFArgumentException("Aggressiveness parameter C must be C > 0: " + c); } } algo = cl.getOptionValue("algo", algo); http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/1add38b6/core/src/main/java/hivemall/fm/FactorizationMachineUDTF.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/fm/FactorizationMachineUDTF.java b/core/src/main/java/hivemall/fm/FactorizationMachineUDTF.java index 4eb740b..e1982a8 100644 --- a/core/src/main/java/hivemall/fm/FactorizationMachineUDTF.java +++ b/core/src/main/java/hivemall/fm/FactorizationMachineUDTF.java @@ -65,7 +65,8 @@ import org.apache.hadoop.io.Text; import org.apache.hadoop.mapred.Counters.Counter; import org.apache.hadoop.mapred.Reporter; -@Description(name = "train_fm", +@Description( + name = "train_fm", value = "_FUNC_(array<string> x, double y [, const string options]) - Returns a prediction model") public class FactorizationMachineUDTF extends UDTFWithOptions { private static final Log LOG = LogFactory.getLog(FactorizationMachineUDTF.class); @@ -203,9 +204,10 @@ public class FactorizationMachineUDTF extends UDTFWithOptions { @Override public StructObjectInspector initialize(ObjectInspector[] argOIs) throws UDFArgumentException { if (argOIs.length != 2 && argOIs.length != 3) { - throw new UDFArgumentException(getClass().getSimpleName() - + " takes 2 or 3 arguments: array<string> x, double y [, CONSTANT STRING options]: " - + Arrays.toString(argOIs)); + throw new UDFArgumentException( + getClass().getSimpleName() + + " takes 2 or 3 arguments: array<string> x, double y [, CONSTANT STRING options]: " + + Arrays.toString(argOIs)); } this._xOI = HiveUtils.asListOI(argOIs[0]); HiveUtils.validateFeatureOI(_xOI.getListElementObjectInspector()); @@ -242,8 +244,7 @@ public class FactorizationMachineUDTF extends UDTFWithOptions { fieldNames.add("W_i"); fieldOIs.add(PrimitiveObjectInspectorFactory.writableFloatObjectInspector); fieldNames.add("V_if"); - fieldOIs.add(ObjectInspectorFactory.getStandardListObjectInspector( - PrimitiveObjectInspectorFactory.writableFloatObjectInspector)); + fieldOIs.add(ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.writableFloatObjectInspector)); return ObjectInspectorFactory.getStandardStructObjectInspector(fieldNames, fieldOIs); } @@ -310,8 +311,8 @@ public class FactorizationMachineUDTF extends UDTFWithOptions { file = File.createTempFile("hivemall_fm", ".sgmt"); file.deleteOnExit(); if (!file.canWrite()) { - throw new UDFArgumentException( - "Cannot write a temporary file: " + file.getAbsolutePath()); + throw new UDFArgumentException("Cannot write a temporary file: " + + file.getAbsolutePath()); } LOG.info("Record training examples to a file: " + file.getAbsolutePath()); } catch (IOException ioe) { @@ -542,8 +543,8 @@ public class FactorizationMachineUDTF extends UDTFWithOptions { final boolean adaregr = _va_rand != null; final Reporter reporter = getReporter(); - final Counter iterCounter = (reporter == null) ? null - : reporter.getCounter("hivemall.fm.FactorizationMachines$Counter", "iteration"); + final Counter iterCounter = (reporter == null) ? null : reporter.getCounter( + "hivemall.fm.FactorizationMachines$Counter", "iteration"); try { if (fileIO.getPosition() == 0L) {// run iterations w/o temporary file @@ -588,8 +589,8 @@ public class FactorizationMachineUDTF extends UDTFWithOptions { try { fileIO.flush(); } catch (IOException e) { - throw new HiveException( - "Failed to flush a file: " + fileIO.getFile().getAbsolutePath(), e); + throw new HiveException("Failed to flush a file: " + + fileIO.getFile().getAbsolutePath(), e); } if (LOG.isInfoEnabled()) { File tmpFile = fileIO.getFile(); @@ -614,8 +615,8 @@ public class FactorizationMachineUDTF extends UDTFWithOptions { try { bytesRead = fileIO.read(inputBuf); } catch (IOException e) { - throw new HiveException( - "Failed to read a file: " + fileIO.getFile().getAbsolutePath(), e); + throw new HiveException("Failed to read a file: " + + fileIO.getFile().getAbsolutePath(), e); } if (bytesRead == 0) { // reached file EOF break; @@ -666,8 +667,8 @@ public class FactorizationMachineUDTF extends UDTFWithOptions { try { fileIO.close(true); } catch (IOException e) { - throw new HiveException( - "Failed to close a file: " + fileIO.getFile().getAbsolutePath(), e); + throw new HiveException("Failed to close a file: " + + fileIO.getFile().getAbsolutePath(), e); } this._inputBuf = null; this._fileIO = null; http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/1add38b6/core/src/main/java/hivemall/fm/FieldAwareFactorizationMachineUDTF.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/fm/FieldAwareFactorizationMachineUDTF.java b/core/src/main/java/hivemall/fm/FieldAwareFactorizationMachineUDTF.java index 610fa3d..953e090 100644 --- a/core/src/main/java/hivemall/fm/FieldAwareFactorizationMachineUDTF.java +++ b/core/src/main/java/hivemall/fm/FieldAwareFactorizationMachineUDTF.java @@ -56,7 +56,8 @@ import org.apache.hadoop.io.Text; * @link https://www.csie.ntu.edu.tw/~cjlin/libffm/ * @since v0.5-rc.1 */ -@Description(name = "train_ffm", +@Description( + name = "train_ffm", value = "_FUNC_(array<string> x, double y [, const string options]) - Returns a prediction model") public final class FieldAwareFactorizationMachineUDTF extends FactorizationMachineUDTF { private static final Log LOG = LogFactory.getLog(FieldAwareFactorizationMachineUDTF.class); @@ -85,8 +86,7 @@ public final class FieldAwareFactorizationMachineUDTF extends FactorizationMachi Options opts = super.getOptions(); opts.addOption("w0", "global_bias", false, "Whether to include global bias term w0 [default: OFF]"); - opts.addOption("disable_wi", "no_coeff", false, - "Not to include linear term [default: OFF]"); + opts.addOption("disable_wi", "no_coeff", false, "Not to include linear term [default: OFF]"); // feature hashing opts.addOption("feature_hashing", true, "The number of bits for feature hashing in range [18,31] [default: -1]. No feature hashing for -1."); @@ -101,7 +101,10 @@ public final class FieldAwareFactorizationMachineUDTF extends FactorizationMachi "Alpha value (learning rate) of Follow-The-Regularized-Reader [default: 0.2]"); opts.addOption("beta", "betaFTRL", true, "Beta value (a learning smoothing parameter) of Follow-The-Regularized-Reader [default: 1.0]"); - opts.addOption("l1", "lambda1", true, + opts.addOption( + "l1", + "lambda1", + true, "L1 regularization value of Follow-The-Regularized-Reader that controls model Sparseness [default: 0.001]"); opts.addOption("l2", "lambda2", true, "L2 regularization value of Follow-The-Regularized-Reader [default: 0.0001]"); @@ -154,8 +157,7 @@ public final class FieldAwareFactorizationMachineUDTF extends FactorizationMachi fieldOIs.add(PrimitiveObjectInspectorFactory.writableFloatObjectInspector); fieldNames.add("Vi"); - fieldOIs.add(ObjectInspectorFactory.getStandardListObjectInspector( - PrimitiveObjectInspectorFactory.writableFloatObjectInspector)); + fieldOIs.add(ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.writableFloatObjectInspector)); return ObjectInspectorFactory.getStandardStructObjectInspector(fieldNames, fieldOIs); } http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/1add38b6/core/src/main/java/hivemall/math/matrix/FloatMatrix.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/math/matrix/FloatMatrix.java b/core/src/main/java/hivemall/math/matrix/FloatMatrix.java index afc54a0..fe26175 100644 --- a/core/src/main/java/hivemall/math/matrix/FloatMatrix.java +++ b/core/src/main/java/hivemall/math/matrix/FloatMatrix.java @@ -39,8 +39,7 @@ public interface FloatMatrix extends Matrix { * @throws IndexOutOfBoundsException * @throws UnsupportedOperationException */ - public float getAndSet(@Nonnegative final int row, @Nonnegative final int col, - final float value); + public float getAndSet(@Nonnegative final int row, @Nonnegative final int col, final float value); /** * @return returns dst http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/1add38b6/core/src/main/java/hivemall/math/matrix/builders/ColumnMajorDenseMatrixBuilder.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/math/matrix/builders/ColumnMajorDenseMatrixBuilder.java b/core/src/main/java/hivemall/math/matrix/builders/ColumnMajorDenseMatrixBuilder.java index b830219..d212271 100644 --- a/core/src/main/java/hivemall/math/matrix/builders/ColumnMajorDenseMatrixBuilder.java +++ b/core/src/main/java/hivemall/math/matrix/builders/ColumnMajorDenseMatrixBuilder.java @@ -49,8 +49,7 @@ public final class ColumnMajorDenseMatrixBuilder extends MatrixBuilder { } @Override - public ColumnMajorDenseMatrixBuilder nextColumn(@Nonnegative final int col, - final double value) { + public ColumnMajorDenseMatrixBuilder nextColumn(@Nonnegative final int col, final double value) { if (value == 0.d) { return this; } http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/1add38b6/core/src/main/java/hivemall/math/matrix/sparse/floats/DoKFloatMatrix.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/math/matrix/sparse/floats/DoKFloatMatrix.java b/core/src/main/java/hivemall/math/matrix/sparse/floats/DoKFloatMatrix.java index 36b8d7a..110e391 100644 --- a/core/src/main/java/hivemall/math/matrix/sparse/floats/DoKFloatMatrix.java +++ b/core/src/main/java/hivemall/math/matrix/sparse/floats/DoKFloatMatrix.java @@ -61,8 +61,8 @@ public final class DoKFloatMatrix extends AbstractMatrix implements FloatMatrix public DoKFloatMatrix(@Nonnegative int numRows, @Nonnegative int numCols, @Nonnegative float sparsity) { super(); - Preconditions.checkArgument(sparsity >= 0.f && sparsity <= 1.f, - "Invalid Sparsity value: " + sparsity); + Preconditions.checkArgument(sparsity >= 0.f && sparsity <= 1.f, "Invalid Sparsity value: " + + sparsity); int initialCapacity = Math.max(16384, Math.round(numRows * numCols * sparsity)); this.elements = new Long2FloatOpenHashTable(initialCapacity); elements.defaultReturnValue(0.f); @@ -205,8 +205,7 @@ public final class DoKFloatMatrix extends AbstractMatrix implements FloatMatrix } @Override - public float getAndSet(@Nonnegative final int row, @Nonnegative final int col, - final float value) { + public float getAndSet(@Nonnegative final int row, @Nonnegative final int col, final float value) { checkIndex(row, col); final long index = index(row, col); http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/1add38b6/core/src/main/java/hivemall/recommend/SlimUDTF.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/recommend/SlimUDTF.java b/core/src/main/java/hivemall/recommend/SlimUDTF.java index 1e84dc8..1689744 100644 --- a/core/src/main/java/hivemall/recommend/SlimUDTF.java +++ b/core/src/main/java/hivemall/recommend/SlimUDTF.java @@ -78,7 +78,8 @@ import org.apache.hadoop.mapred.Reporter; * Xia Ning and George Karypis, SLIM: Sparse Linear Methods for Top-N Recommender Systems, Proc. ICDM, 2011. * </pre> */ -@Description(name = "train_slim", +@Description( + name = "train_slim", value = "_FUNC_( int i, map<int, double> r_i, map<int, map<int, double>> topKRatesOfI, int j, map<int, double> r_j [, constant string options]) " + "- Returns row index, column index and non-zero weight value of prediction model") public class SlimUDTF extends UDTFWithOptions { @@ -172,10 +173,8 @@ public class SlimUDTF extends UDTFWithOptions { this.knnItemsOI = HiveUtils.asMapOI(argOIs[2]); this.knnItemsKeyOI = HiveUtils.asIntCompatibleOI(knnItemsOI.getMapKeyObjectInspector()); this.knnItemsValueOI = HiveUtils.asMapOI(knnItemsOI.getMapValueObjectInspector()); - this.knnItemsValueKeyOI = - HiveUtils.asIntCompatibleOI(knnItemsValueOI.getMapKeyObjectInspector()); - this.knnItemsValueValueOI = - HiveUtils.asDoubleCompatibleOI(knnItemsValueOI.getMapValueObjectInspector()); + this.knnItemsValueKeyOI = HiveUtils.asIntCompatibleOI(knnItemsValueOI.getMapKeyObjectInspector()); + this.knnItemsValueValueOI = HiveUtils.asDoubleCompatibleOI(knnItemsValueOI.getMapValueObjectInspector()); this.itemJOI = HiveUtils.asIntCompatibleOI(argOIs[3]); @@ -245,8 +244,8 @@ public class SlimUDTF extends UDTFWithOptions { numIterations = Primitives.parseInt(cl.getOptionValue("iters"), numIterations); if (numIterations <= 0) { - throw new UDFArgumentException( - "Argument `int iters` must be greater than 0: " + numIterations); + throw new UDFArgumentException("Argument `int iters` must be greater than 0: " + + numIterations); } conversionCheck = !cl.hasOption("disable_cvtest"); @@ -280,8 +279,8 @@ public class SlimUDTF extends UDTFWithOptions { if (itemI != _previousItemId || _ri == null) { // cache Ri and kNNi - this._ri = - int2floatMap(itemI, riOI.getMap(args[1]), riKeyOI, riValueOI, _dataMatrix, _ri); + this._ri = int2floatMap(itemI, riOI.getMap(args[1]), riKeyOI, riValueOI, _dataMatrix, + _ri); this._kNNi = kNNentries(args[2], knnItemsOI, knnItemsKeyOI, knnItemsValueOI, knnItemsValueKeyOI, knnItemsValueValueOI, _kNNi, _nnzKNNi); @@ -293,8 +292,7 @@ public class SlimUDTF extends UDTFWithOptions { } int itemJ = PrimitiveObjectInspectorUtils.getInt(args[3], itemJOI); - Int2FloatMap rj = - int2floatMap(itemJ, rjOI.getMap(args[4]), rjKeyOI, rjValueOI, _dataMatrix); + Int2FloatMap rj = int2floatMap(itemJ, rjOI.getMap(args[4]), rjKeyOI, rjValueOI, _dataMatrix); train(itemI, _ri, _kNNi, itemJ, rj); _observedTrainingExamples++; @@ -313,8 +311,8 @@ public class SlimUDTF extends UDTFWithOptions { file = File.createTempFile("hivemall_slim", ".sgmt"); // to save KNN data file.deleteOnExit(); if (!file.canWrite()) { - throw new UDFArgumentException( - "Cannot write a temporary file: " + file.getAbsolutePath()); + throw new UDFArgumentException("Cannot write a temporary file: " + + file.getAbsolutePath()); } } catch (IOException ioe) { throw new UDFArgumentException(ioe); @@ -452,8 +450,8 @@ public class SlimUDTF extends UDTFWithOptions { return pred; } - private static double getUpdateTerm(final double gradSum, final double rateSum, final double l1, - final double l2) { + private static double getUpdateTerm(final double gradSum, final double rateSum, + final double l1, final double l2) { double update = 0.d; if (Math.abs(gradSum) > l1) { if (gradSum > 0.d) { @@ -495,8 +493,8 @@ public class SlimUDTF extends UDTFWithOptions { assert (dst != null); final Reporter reporter = getReporter(); - final Counters.Counter iterCounter = (reporter == null) ? null - : reporter.getCounter("hivemall.recommend.slim$Counter", "iteration"); + final Counters.Counter iterCounter = (reporter == null) ? null : reporter.getCounter( + "hivemall.recommend.slim$Counter", "iteration"); try { if (dst.getPosition() == 0L) {// run iterations w/o temporary file @@ -519,12 +517,13 @@ public class SlimUDTF extends UDTFWithOptions { break; } } - logger.info("Performed " + _cvState.getCurrentIteration() + " iterations of " + logger.info("Performed " + + _cvState.getCurrentIteration() + + " iterations of " + NumberUtils.formatNumber(_observedTrainingExamples) + " training examples on memory (thus " - + NumberUtils.formatNumber( - _observedTrainingExamples * _cvState.getCurrentIteration()) - + " training updates in total) "); + + NumberUtils.formatNumber(_observedTrainingExamples + * _cvState.getCurrentIteration()) + " training updates in total) "); } else { // read training examples in the temporary file and invoke train for each example // write KNNi in buffer to a temporary file @@ -535,16 +534,17 @@ public class SlimUDTF extends UDTFWithOptions { try { dst.flush(); } catch (IOException e) { - throw new HiveException( - "Failed to flush a file: " + dst.getFile().getAbsolutePath(), e); + throw new HiveException("Failed to flush a file: " + + dst.getFile().getAbsolutePath(), e); } if (logger.isInfoEnabled()) { File tmpFile = dst.getFile(); - logger.info( - "Wrote KNN entries of axis items to a temporary file for iterative training: " - + tmpFile.getAbsolutePath() + " (" - + FileUtils.prettyFileSize(tmpFile) + ")"); + logger.info("Wrote KNN entries of axis items to a temporary file for iterative training: " + + tmpFile.getAbsolutePath() + + " (" + + FileUtils.prettyFileSize(tmpFile) + + ")"); } // run iterations @@ -561,8 +561,8 @@ public class SlimUDTF extends UDTFWithOptions { try { bytesRead = dst.read(buf); } catch (IOException e) { - throw new HiveException( - "Failed to read a file: " + dst.getFile().getAbsolutePath(), e); + throw new HiveException("Failed to read a file: " + + dst.getFile().getAbsolutePath(), e); } if (bytesRead == 0) { // reached file EOF break; @@ -593,12 +593,13 @@ public class SlimUDTF extends UDTFWithOptions { break; } } - logger.info("Performed " + _cvState.getCurrentIteration() + " iterations of " + logger.info("Performed " + + _cvState.getCurrentIteration() + + " iterations of " + NumberUtils.formatNumber(_observedTrainingExamples) + " training examples on memory and KNNi data on secondary storage (thus " - + NumberUtils.formatNumber( - _observedTrainingExamples * _cvState.getCurrentIteration()) - + " training updates in total) "); + + NumberUtils.formatNumber(_observedTrainingExamples + * _cvState.getCurrentIteration()) + " training updates in total) "); } } catch (Throwable e) { @@ -608,8 +609,8 @@ public class SlimUDTF extends UDTFWithOptions { try { dst.close(true); } catch (IOException e) { - throw new HiveException( - "Failed to close a file: " + dst.getFile().getAbsolutePath(), e); + throw new HiveException("Failed to close a file: " + + dst.getFile().getAbsolutePath(), e); } this._inputBuf = null; this._fileIO = null; @@ -721,16 +722,15 @@ public class SlimUDTF extends UDTFWithOptions { @Nonnull private static Int2FloatMap int2floatMap(final int item, @Nonnull final Map<?, ?> map, @Nonnull final PrimitiveObjectInspector keyOI, - @Nonnull final PrimitiveObjectInspector valueOI, - @Nullable final FloatMatrix dataMatrix) { + @Nonnull final PrimitiveObjectInspector valueOI, @Nullable final FloatMatrix dataMatrix) { return int2floatMap(item, map, keyOI, valueOI, dataMatrix, null); } @Nonnull private static Int2FloatMap int2floatMap(final int item, @Nonnull final Map<?, ?> map, @Nonnull final PrimitiveObjectInspector keyOI, - @Nonnull final PrimitiveObjectInspector valueOI, @Nullable final FloatMatrix dataMatrix, - @Nullable Int2FloatMap dst) { + @Nonnull final PrimitiveObjectInspector valueOI, + @Nullable final FloatMatrix dataMatrix, @Nullable Int2FloatMap dst) { if (dst == null) { dst = new Int2FloatOpenHashMap(map.size()); dst.defaultReturnValue(0.f); http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/1add38b6/core/src/main/java/hivemall/sketch/hll/ApproxCountDistinctUDAF.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/sketch/hll/ApproxCountDistinctUDAF.java b/core/src/main/java/hivemall/sketch/hll/ApproxCountDistinctUDAF.java index 3a1c2a6..2575026 100644 --- a/core/src/main/java/hivemall/sketch/hll/ApproxCountDistinctUDAF.java +++ b/core/src/main/java/hivemall/sketch/hll/ApproxCountDistinctUDAF.java @@ -55,8 +55,7 @@ import com.clearspring.analytics.stream.cardinality.HyperLogLogPlus; public final class ApproxCountDistinctUDAF extends AbstractGenericUDAFResolver { @Override - public GenericUDAFEvaluator getEvaluator(@Nonnull TypeInfo[] typeInfo) - throws SemanticException { + public GenericUDAFEvaluator getEvaluator(@Nonnull TypeInfo[] typeInfo) throws SemanticException { if (typeInfo.length != 1 && typeInfo.length != 2) { throw new UDFArgumentTypeException(typeInfo.length - 1, "_FUNC_ takes one or two arguments"); @@ -120,13 +119,13 @@ public final class ApproxCountDistinctUDAF extends AbstractGenericUDAFResolver { if (mode == Mode.PARTIAL1 || mode == Mode.COMPLETE) {// from original data processOptions(parameters); this.origInputOI = parameters[0]; - } else {// from partial aggregation + } else {// from partial aggregation this.mergeInputOI = HiveUtils.asBinaryOI(parameters[0]); } // initialize output final ObjectInspector outputOI; - if (mode == Mode.PARTIAL1 || mode == Mode.PARTIAL2) {// terminatePartial + if (mode == Mode.PARTIAL1 || mode == Mode.PARTIAL2) {// terminatePartial outputOI = PrimitiveObjectInspectorFactory.javaByteArrayObjectInspector; } else {// terminate outputOI = PrimitiveObjectInspectorFactory.writableLongObjectInspector; @@ -163,8 +162,7 @@ public final class ApproxCountDistinctUDAF extends AbstractGenericUDAFResolver { } HLLBuffer buf = (HLLBuffer) agg; - Object value = - ObjectInspectorUtils.copyToStandardJavaObject(parameters[0], origInputOI); + Object value = ObjectInspectorUtils.copyToStandardJavaObject(parameters[0], origInputOI); Preconditions.checkNotNull(buf.hll, HiveException.class); buf.hll.offer(value); } http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/1add38b6/core/src/main/java/hivemall/utils/collections/Fastutil.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/utils/collections/Fastutil.java b/core/src/main/java/hivemall/utils/collections/Fastutil.java index c6ace89..0ef1c21 100644 --- a/core/src/main/java/hivemall/utils/collections/Fastutil.java +++ b/core/src/main/java/hivemall/utils/collections/Fastutil.java @@ -38,24 +38,22 @@ public final class Fastutil { @Nonnull public static ObjectIterable<Int2LongMap.Entry> fastIterable(@Nonnull final Int2LongMap map) { final ObjectSet<Int2LongMap.Entry> entries = map.int2LongEntrySet(); - return entries instanceof Int2LongMap.FastEntrySet - ? new ObjectIterable<Int2LongMap.Entry>() { - public ObjectIterator<Int2LongMap.Entry> iterator() { - return ((Int2LongMap.FastEntrySet) entries).fastIterator(); - } - } + return entries instanceof Int2LongMap.FastEntrySet ? new ObjectIterable<Int2LongMap.Entry>() { + public ObjectIterator<Int2LongMap.Entry> iterator() { + return ((Int2LongMap.FastEntrySet) entries).fastIterator(); + } + } : entries; } @Nonnull public static ObjectIterable<Int2FloatMap.Entry> fastIterable(@Nonnull final Int2FloatMap map) { final ObjectSet<Int2FloatMap.Entry> entries = map.int2FloatEntrySet(); - return entries instanceof Int2FloatMap.FastEntrySet - ? new ObjectIterable<Int2FloatMap.Entry>() { - public ObjectIterator<Int2FloatMap.Entry> iterator() { - return ((Int2FloatMap.FastEntrySet) entries).fastIterator(); - } - } + return entries instanceof Int2FloatMap.FastEntrySet ? new ObjectIterable<Int2FloatMap.Entry>() { + public ObjectIterator<Int2FloatMap.Entry> iterator() { + return ((Int2FloatMap.FastEntrySet) entries).fastIterator(); + } + } : entries; } @@ -63,12 +61,11 @@ public final class Fastutil { public static <V> ObjectIterable<Int2ObjectMap.Entry<V>> fastIterable( @Nonnull final Int2ObjectMap<V> map) { final ObjectSet<Int2ObjectMap.Entry<V>> entries = map.int2ObjectEntrySet(); - return entries instanceof Int2ObjectMap.FastEntrySet - ? new ObjectIterable<Int2ObjectMap.Entry<V>>() { - public ObjectIterator<Int2ObjectMap.Entry<V>> iterator() { - return ((Int2ObjectMap.FastEntrySet<V>) entries).fastIterator(); - } - } + return entries instanceof Int2ObjectMap.FastEntrySet ? new ObjectIterable<Int2ObjectMap.Entry<V>>() { + public ObjectIterator<Int2ObjectMap.Entry<V>> iterator() { + return ((Int2ObjectMap.FastEntrySet<V>) entries).fastIterator(); + } + } : entries; } @@ -76,13 +73,12 @@ public final class Fastutil { public static <K, V> ObjectIterable<Object2ObjectMap.Entry<K, V>> fastIterable( @Nonnull final Object2ObjectMap<K, V> map) { final ObjectSet<Object2ObjectMap.Entry<K, V>> entries = map.object2ObjectEntrySet(); - return entries instanceof Object2ObjectMap.FastEntrySet - ? new ObjectIterable<Object2ObjectMap.Entry<K, V>>() { - @SuppressWarnings("unchecked") - public ObjectIterator<Object2ObjectMap.Entry<K, V>> iterator() { - return ((Object2ObjectMap.FastEntrySet<K, V>) entries).fastIterator(); - } - } + return entries instanceof Object2ObjectMap.FastEntrySet ? new ObjectIterable<Object2ObjectMap.Entry<K, V>>() { + @SuppressWarnings("unchecked") + public ObjectIterator<Object2ObjectMap.Entry<K, V>> iterator() { + return ((Object2ObjectMap.FastEntrySet<K, V>) entries).fastIterator(); + } + } : entries; } http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/1add38b6/core/src/main/java/hivemall/utils/hadoop/HiveUtils.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/utils/hadoop/HiveUtils.java b/core/src/main/java/hivemall/utils/hadoop/HiveUtils.java index e9a1efb..44475eb 100644 --- a/core/src/main/java/hivemall/utils/hadoop/HiveUtils.java +++ b/core/src/main/java/hivemall/utils/hadoop/HiveUtils.java @@ -102,8 +102,8 @@ public final class HiveUtils { if (o instanceof LongWritable) { long l = ((LongWritable) o).get(); if (l > 0x7fffffffL) { - throw new IllegalArgumentException( - "feature index must be less than " + Integer.MAX_VALUE + ", but was " + l); + throw new IllegalArgumentException("feature index must be less than " + + Integer.MAX_VALUE + ", but was " + l); } return (int) l; } @@ -491,8 +491,8 @@ public final class HiveUtils { } ConstantObjectInspector constOI = (ConstantObjectInspector) oi; if (constOI.getCategory() != Category.LIST) { - throw new UDFArgumentException( - "argument must be an array: " + TypeInfoUtils.getTypeInfoFromObjectInspector(oi)); + throw new UDFArgumentException("argument must be an array: " + + TypeInfoUtils.getTypeInfoFromObjectInspector(oi)); } final List<?> lst = (List<?>) constOI.getWritableConstantValue(); if (lst == null) { @@ -518,12 +518,11 @@ public final class HiveUtils { } ConstantObjectInspector constOI = (ConstantObjectInspector) oi; if (constOI.getCategory() != Category.LIST) { - throw new UDFArgumentException( - "argument must be an array: " + TypeInfoUtils.getTypeInfoFromObjectInspector(oi)); + throw new UDFArgumentException("argument must be an array: " + + TypeInfoUtils.getTypeInfoFromObjectInspector(oi)); } StandardConstantListObjectInspector listOI = (StandardConstantListObjectInspector) constOI; - PrimitiveObjectInspector elemOI = - HiveUtils.asDoubleCompatibleOI(listOI.getListElementObjectInspector()); + PrimitiveObjectInspector elemOI = HiveUtils.asDoubleCompatibleOI(listOI.getListElementObjectInspector()); final List<?> lst = listOI.getWritableConstantValue(); if (lst == null) { @@ -784,8 +783,8 @@ public final class HiveUtils { } final int length = listOI.getListLength(argObj); if (out.length != length) { - throw new UDFArgumentException( - "Dimension mismatched. Expected: " + out.length + ", Actual: " + length); + throw new UDFArgumentException("Dimension mismatched. Expected: " + out.length + + ", Actual: " + length); } for (int i = 0; i < length; i++) { Object o = listOI.getListElement(argObj, i); @@ -810,8 +809,8 @@ public final class HiveUtils { } final int length = listOI.getListLength(argObj); if (out.length != length) { - throw new UDFArgumentException( - "Dimension mismatched. Expected: " + out.length + ", Actual: " + length); + throw new UDFArgumentException("Dimension mismatched. Expected: " + out.length + + ", Actual: " + length); } for (int i = 0; i < length; i++) { Object o = listOI.getListElement(argObj, i); @@ -946,8 +945,8 @@ public final class HiveUtils { case STRING: break; default: - throw new UDFArgumentTypeException(0, - "Unxpected type '" + argOI.getTypeName() + "' is passed."); + throw new UDFArgumentTypeException(0, "Unxpected type '" + argOI.getTypeName() + + "' is passed."); } return oi; } @@ -973,8 +972,8 @@ public final class HiveUtils { case TIMESTAMP: break; default: - throw new UDFArgumentTypeException(0, - "Unxpected type '" + argOI.getTypeName() + "' is passed."); + throw new UDFArgumentTypeException(0, "Unxpected type '" + argOI.getTypeName() + + "' is passed."); } return oi; } @@ -994,15 +993,15 @@ public final class HiveUtils { case BYTE: break; default: - throw new UDFArgumentTypeException(0, - "Unxpected type '" + argOI.getTypeName() + "' is passed."); + throw new UDFArgumentTypeException(0, "Unxpected type '" + argOI.getTypeName() + + "' is passed."); } return oi; } @Nonnull - public static PrimitiveObjectInspector asDoubleCompatibleOI( - @Nonnull final ObjectInspector argOI) throws UDFArgumentTypeException { + public static PrimitiveObjectInspector asDoubleCompatibleOI(@Nonnull final ObjectInspector argOI) + throws UDFArgumentTypeException { if (argOI.getCategory() != Category.PRIMITIVE) { throw new UDFArgumentTypeException(0, "Only primitive type arguments are accepted but " + argOI.getTypeName() + " is passed."); @@ -1165,8 +1164,8 @@ public final class HiveUtils { @Nonnull public static LazyString lazyString(@Nonnull final String str, final byte escapeChar) { - LazyStringObjectInspector oi = - LazyPrimitiveObjectInspectorFactory.getLazyStringObjectInspector(false, escapeChar); + LazyStringObjectInspector oi = LazyPrimitiveObjectInspectorFactory.getLazyStringObjectInspector( + false, escapeChar); return lazyString(str, oi); } @@ -1183,16 +1182,15 @@ public final class HiveUtils { @Nonnull public static LazyInteger lazyInteger(@Nonnull final int v) { - LazyInteger lazy = - new LazyInteger(LazyPrimitiveObjectInspectorFactory.LAZY_INT_OBJECT_INSPECTOR); + LazyInteger lazy = new LazyInteger( + LazyPrimitiveObjectInspectorFactory.LAZY_INT_OBJECT_INSPECTOR); lazy.getWritableObject().set(v); return lazy; } @Nonnull public static LazyLong lazyLong(@Nonnull final long v) { - LazyLong lazy = - new LazyLong(LazyPrimitiveObjectInspectorFactory.LAZY_LONG_OBJECT_INSPECTOR); + LazyLong lazy = new LazyLong(LazyPrimitiveObjectInspectorFactory.LAZY_LONG_OBJECT_INSPECTOR); lazy.getWritableObject().set(v); return lazy; }
