yunfengzhou-hub commented on code in PR #139:
URL: https://github.com/apache/flink-ml/pull/139#discussion_r946290131


##########
flink-ml-lib/src/test/java/org/apache/flink/ml/feature/KBinsDiscretizerTest.java:
##########
@@ -0,0 +1,296 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.ml.feature;
+
+import org.apache.flink.api.common.restartstrategy.RestartStrategies;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.ml.feature.kbinsdiscretizer.KBinsDiscretizer;
+import org.apache.flink.ml.feature.kbinsdiscretizer.KBinsDiscretizerModel;
+import org.apache.flink.ml.feature.kbinsdiscretizer.KBinsDiscretizerModelData;
+import org.apache.flink.ml.feature.kbinsdiscretizer.KBinsDiscretizerParams;
+import org.apache.flink.ml.linalg.Vector;
+import org.apache.flink.ml.linalg.Vectors;
+import org.apache.flink.ml.util.ReadWriteUtils;
+import org.apache.flink.ml.util.TestUtils;
+import 
org.apache.flink.streaming.api.environment.ExecutionCheckpointingOptions;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.table.api.Table;
+import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
+import org.apache.flink.test.util.AbstractTestBase;
+import org.apache.flink.types.Row;
+
+import org.apache.commons.collections.IteratorUtils;
+import org.apache.commons.lang3.exception.ExceptionUtils;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static org.apache.flink.table.api.Expressions.$;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+/** Tests {@link KBinsDiscretizer} and {@link KBinsDiscretizerModel}. */
+public class KBinsDiscretizerTest extends AbstractTestBase {
+    @Rule public final TemporaryFolder tempFolder = new TemporaryFolder();
+    private StreamExecutionEnvironment env;
+    private StreamTableEnvironment tEnv;
+    private Table trainTable;
+    private Table testTable;
+
+    // Column0 for normal cases, column1 for constant cases, column2 for 
numDistinct < numBins
+    // cases.
+    private static final List<Row> TRAIN_INPUT =
+            Arrays.asList(
+                    Row.of(Vectors.dense(1, 10, 0)),
+                    Row.of(Vectors.dense(1, 10, 0)),
+                    Row.of(Vectors.dense(1, 10, 0)),
+                    Row.of(Vectors.dense(4, 10, 0)),
+                    Row.of(Vectors.dense(5, 10, 0)),
+                    Row.of(Vectors.dense(6, 10, 0)),
+                    Row.of(Vectors.dense(7, 10, 0)),
+                    Row.of(Vectors.dense(10, 10, 0)),
+                    Row.of(Vectors.dense(13, 10, 3)));
+
+    private static final List<Row> TEST_INPUT =
+            Arrays.asList(
+                    Row.of(Vectors.dense(-1, 0, 0)),
+                    Row.of(Vectors.dense(1, 1, 1)),
+                    Row.of(Vectors.dense(1.5, 1, 2)),
+                    Row.of(Vectors.dense(5, 2, 3)),
+                    Row.of(Vectors.dense(7.25, 3, 4)),
+                    Row.of(Vectors.dense(13, 4, 5)),
+                    Row.of(Vectors.dense(15, 4, 6)));
+
+    private static final double[][] UNIFORM_MODEL_DATA =
+            new double[][] {
+                new double[] {1, 5, 9, 13},
+                new double[] {Double.MIN_VALUE, Double.MAX_VALUE},
+                new double[] {0, 1, 2, 3}
+            };
+
+    private static final List<Row> UNIFORM_OUTPUT =
+            Arrays.asList(
+                    Row.of(Vectors.dense(0, 0, 0)),
+                    Row.of(Vectors.dense(0, 0, 1)),
+                    Row.of(Vectors.dense(0, 0, 2)),
+                    Row.of(Vectors.dense(1, 0, 2)),
+                    Row.of(Vectors.dense(1, 0, 2)),
+                    Row.of(Vectors.dense(2, 0, 2)),
+                    Row.of(Vectors.dense(2, 0, 2)));
+
+    private static final List<Row> QUANTILE_OUTPUT =
+            Arrays.asList(
+                    Row.of(Vectors.dense(0, 0, 0)),
+                    Row.of(Vectors.dense(0, 0, 0)),
+                    Row.of(Vectors.dense(0, 0, 0)),
+                    Row.of(Vectors.dense(1, 0, 0)),
+                    Row.of(Vectors.dense(2, 0, 0)),
+                    Row.of(Vectors.dense(2, 0, 0)),
+                    Row.of(Vectors.dense(2, 0, 0)));
+
+    private static final List<Row> KMEANS_OUTPUT =
+            Arrays.asList(
+                    Row.of(Vectors.dense(0, 0, 0)),
+                    Row.of(Vectors.dense(0, 0, 1)),
+                    Row.of(Vectors.dense(0, 0, 2)),
+                    Row.of(Vectors.dense(1, 0, 2)),
+                    Row.of(Vectors.dense(1, 0, 2)),
+                    Row.of(Vectors.dense(2, 0, 2)),
+                    Row.of(Vectors.dense(2, 0, 2)));
+
+    private static final double TOLERANCE = 1e-7;
+
+    @Before
+    public void before() {
+        Configuration config = new Configuration();
+        
config.set(ExecutionCheckpointingOptions.ENABLE_CHECKPOINTS_AFTER_TASKS_FINISH, 
true);
+        env = StreamExecutionEnvironment.getExecutionEnvironment(config);
+        env.setParallelism(4);
+        env.enableCheckpointing(100);
+        env.setRestartStrategy(RestartStrategies.noRestart());
+        tEnv = StreamTableEnvironment.create(env);
+        trainTable = 
tEnv.fromDataStream(env.fromCollection(TRAIN_INPUT)).as("input");
+        testTable = 
tEnv.fromDataStream(env.fromCollection(TEST_INPUT)).as("input");
+    }
+
+    @SuppressWarnings("all")
+    private void verifyPredictionResult(
+            List<Row> expectedOutput, Table output, String predictionCol) 
throws Exception {
+        List<Row> collectedResult =
+                IteratorUtils.toList(
+                        
tEnv.toDataStream(output.select($(predictionCol))).executeAndCollect());
+        compareResultCollections(
+                expectedOutput,
+                collectedResult,
+                (o1, o2) -> {

Review Comment:
   There is a method called `TestUtils::compare`, which might be useful here. 
And #142 has been generalizing the method from `DenseVector` to `Vector`.



##########
flink-ml-lib/src/main/java/org/apache/flink/ml/feature/kbinsdiscretizer/KBinsDiscretizerParams.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.ml.feature.kbinsdiscretizer;
+
+import org.apache.flink.ml.param.IntParam;
+import org.apache.flink.ml.param.Param;
+import org.apache.flink.ml.param.ParamValidators;
+import org.apache.flink.ml.param.StringParam;
+
+/**
+ * Params for {@link KBinsDiscretizer}.
+ *
+ * @param <T> The class type of this instance.
+ */
+public interface KBinsDiscretizerParams<T> extends 
KBinsDiscretizerModelParams<T> {
+    String UNIFORM = "uniform";
+    String QUANTILE = "quantile";
+    String KMEANS = "kmeans";
+
+    /**
+     * Supported options to define the widths of the bins are listed as 
follows.
+     *
+     * <ul>
+     *   <li>uniform: all bins in each feature have identical widths.
+     *   <li>quantile: all bins in each feature have the same number of points.
+     *   <li>kmeans: values in each bin have the same nearest center of a 1D 
kmeans cluster.
+     * </ul>
+     */
+    Param<String> STRATEGY =
+            new StringParam(
+                    "strategy",
+                    "Strategy used to define the width of the bin.",
+                    QUANTILE,
+                    ParamValidators.inArray(UNIFORM, QUANTILE, KMEANS));
+
+    Param<Integer> NUM_BINS =
+            new IntParam("numBins", "Number of bins to produce.", 5, 
ParamValidators.gtEq(2));
+
+    Param<Integer> SUB_SAMPLES =
+            new IntParam(
+                    "subSamples",
+                    "Maximum number of samples used to fit the model.",
+                    200000,
+                    ParamValidators.gt(0));

Review Comment:
   nit: Shall we add a check that `subSamples >= 2` or `subSamples >= numBins`?



##########
flink-ml-lib/src/main/java/org/apache/flink/ml/feature/kbinsdiscretizer/KBinsDiscretizer.java:
##########
@@ -0,0 +1,340 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.ml.feature.kbinsdiscretizer;
+
+import org.apache.flink.api.common.functions.MapFunction;
+import org.apache.flink.api.common.functions.MapPartitionFunction;
+import org.apache.flink.ml.api.Estimator;
+import org.apache.flink.ml.common.datastream.DataStreamUtils;
+import 
org.apache.flink.ml.feature.minmaxscaler.MinMaxScaler.MinMaxReduceFunctionOperator;
+import org.apache.flink.ml.linalg.DenseVector;
+import org.apache.flink.ml.linalg.Vector;
+import org.apache.flink.ml.param.Param;
+import org.apache.flink.ml.util.ParamUtils;
+import org.apache.flink.ml.util.ReadWriteUtils;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.table.api.Table;
+import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
+import org.apache.flink.table.api.internal.TableImpl;
+import org.apache.flink.types.Row;
+import org.apache.flink.util.Collector;
+import org.apache.flink.util.Preconditions;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * An Estimator which implements discretization (also known as quantization or 
binning), which
+ * transforms continuous features into discrete ones. The output values are in 
[0, numBins).
+ *
+ * <p>KBinsDiscretizer implements three different binning strategies, and it 
can be set by {@link
+ * KBinsDiscretizerParams#STRATEGY}. If the strategy is set as {@link 
KBinsDiscretizerParams#KMEANS}
+ * or {@link KBinsDiscretizerParams#QUANTILE}, users should further set {@link
+ * KBinsDiscretizerParams#SUB_SAMPLES} for better performance.
+ *
+ * <p>There are several corner cases for different inputs as listed below:
+ *
+ * <ul>
+ *   <li>When the input values of one column are all the same, then they 
should be mapped to the
+ *       same bin (i.e., the zero-th bin). Thus the corresponding bin edges 
are `{Double.MIN_VALUE,
+ *       Double.MAX_VALUE}`.
+ *   <li>When the number of distinct values of one column is less than the 
specified number of bins
+ *       and the {@link KBinsDiscretizerParams#STRATEGY} is set as {@link
+ *       KBinsDiscretizerParams#KMEANS}, we switch to {@link 
KBinsDiscretizerParams#UNIFORM}.
+ *   <li>When the width of one output bin is zero, i.e., the left edge equals 
to the right edge of
+ *       the bin, we remove it.
+ * </ul>
+ */
+public class KBinsDiscretizer
+        implements Estimator<KBinsDiscretizer, KBinsDiscretizerModel>,
+                KBinsDiscretizerParams<KBinsDiscretizer> {
+    private static final Logger LOG = 
LoggerFactory.getLogger(KBinsDiscretizer.class);
+    private final Map<Param<?>, Object> paramMap = new HashMap<>();
+
+    public KBinsDiscretizer() {
+        ParamUtils.initializeMapWithDefaultValues(paramMap, this);
+    }
+
+    @Override
+    public KBinsDiscretizerModel fit(Table... inputs) {
+        Preconditions.checkArgument(inputs.length == 1);
+        StreamTableEnvironment tEnv =
+                (StreamTableEnvironment) ((TableImpl) 
inputs[0]).getTableEnvironment();
+
+        String inputCol = getInputCol();
+        String strategy = getStrategy();
+        int numBins = getNumBins();
+
+        DataStream<DenseVector> inputData =
+                tEnv.toDataStream(inputs[0])
+                        .map(
+                                (MapFunction<Row, DenseVector>)
+                                        value -> ((Vector) 
value.getField(inputCol)).toDense());
+
+        DataStream<DenseVector> preprocessedData;
+        if (strategy.equals(UNIFORM)) {
+            preprocessedData =
+                    inputData
+                            .transform(
+                                    "reduceInEachPartition",
+                                    inputData.getType(),
+                                    new MinMaxReduceFunctionOperator())
+                            .transform(
+                                    "reduceInFinalPartition",
+                                    inputData.getType(),
+                                    new MinMaxReduceFunctionOperator())
+                            .setParallelism(1);
+        } else {
+            preprocessedData = DataStreamUtils.sample(inputData, 
getSubSamples(), 2022L);

Review Comment:
   Would it be better to change the random seed from `2022L` to 
`getClass().getName().hashCode()`? If one day we would support the random seed 
parameter, this would be its default value.



##########
flink-ml-lib/src/main/java/org/apache/flink/ml/feature/kbinsdiscretizer/KBinsDiscretizer.java:
##########
@@ -0,0 +1,340 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.ml.feature.kbinsdiscretizer;
+
+import org.apache.flink.api.common.functions.MapFunction;
+import org.apache.flink.api.common.functions.MapPartitionFunction;
+import org.apache.flink.ml.api.Estimator;
+import org.apache.flink.ml.common.datastream.DataStreamUtils;
+import 
org.apache.flink.ml.feature.minmaxscaler.MinMaxScaler.MinMaxReduceFunctionOperator;
+import org.apache.flink.ml.linalg.DenseVector;
+import org.apache.flink.ml.linalg.Vector;
+import org.apache.flink.ml.param.Param;
+import org.apache.flink.ml.util.ParamUtils;
+import org.apache.flink.ml.util.ReadWriteUtils;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.table.api.Table;
+import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
+import org.apache.flink.table.api.internal.TableImpl;
+import org.apache.flink.types.Row;
+import org.apache.flink.util.Collector;
+import org.apache.flink.util.Preconditions;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * An Estimator which implements discretization (also known as quantization or 
binning), which
+ * transforms continuous features into discrete ones. The output values are in 
[0, numBins).
+ *
+ * <p>KBinsDiscretizer implements three different binning strategies, and it 
can be set by {@link
+ * KBinsDiscretizerParams#STRATEGY}. If the strategy is set as {@link 
KBinsDiscretizerParams#KMEANS}
+ * or {@link KBinsDiscretizerParams#QUANTILE}, users should further set {@link
+ * KBinsDiscretizerParams#SUB_SAMPLES} for better performance.
+ *
+ * <p>There are several corner cases for different inputs as listed below:
+ *
+ * <ul>
+ *   <li>When the input values of one column are all the same, then they 
should be mapped to the
+ *       same bin (i.e., the zero-th bin). Thus the corresponding bin edges 
are `{Double.MIN_VALUE,
+ *       Double.MAX_VALUE}`.
+ *   <li>When the number of distinct values of one column is less than the 
specified number of bins
+ *       and the {@link KBinsDiscretizerParams#STRATEGY} is set as {@link
+ *       KBinsDiscretizerParams#KMEANS}, we switch to {@link 
KBinsDiscretizerParams#UNIFORM}.
+ *   <li>When the width of one output bin is zero, i.e., the left edge equals 
to the right edge of
+ *       the bin, we remove it.
+ * </ul>
+ */
+public class KBinsDiscretizer
+        implements Estimator<KBinsDiscretizer, KBinsDiscretizerModel>,
+                KBinsDiscretizerParams<KBinsDiscretizer> {
+    private static final Logger LOG = 
LoggerFactory.getLogger(KBinsDiscretizer.class);
+    private final Map<Param<?>, Object> paramMap = new HashMap<>();
+
+    public KBinsDiscretizer() {
+        ParamUtils.initializeMapWithDefaultValues(paramMap, this);
+    }
+
+    @Override
+    public KBinsDiscretizerModel fit(Table... inputs) {
+        Preconditions.checkArgument(inputs.length == 1);
+        StreamTableEnvironment tEnv =
+                (StreamTableEnvironment) ((TableImpl) 
inputs[0]).getTableEnvironment();
+
+        String inputCol = getInputCol();
+        String strategy = getStrategy();
+        int numBins = getNumBins();
+
+        DataStream<DenseVector> inputData =
+                tEnv.toDataStream(inputs[0])
+                        .map(
+                                (MapFunction<Row, DenseVector>)
+                                        value -> ((Vector) 
value.getField(inputCol)).toDense());
+
+        DataStream<DenseVector> preprocessedData;
+        if (strategy.equals(UNIFORM)) {
+            preprocessedData =
+                    inputData
+                            .transform(
+                                    "reduceInEachPartition",
+                                    inputData.getType(),
+                                    new MinMaxReduceFunctionOperator())
+                            .transform(
+                                    "reduceInFinalPartition",
+                                    inputData.getType(),
+                                    new MinMaxReduceFunctionOperator())
+                            .setParallelism(1);
+        } else {
+            preprocessedData = DataStreamUtils.sample(inputData, 
getSubSamples(), 2022L);
+        }
+
+        DataStream<KBinsDiscretizerModelData> modelData =
+                DataStreamUtils.mapPartition(
+                        preprocessedData,
+                        new MapPartitionFunction<DenseVector, 
KBinsDiscretizerModelData>() {
+                            @Override
+                            public void mapPartition(
+                                    Iterable<DenseVector> iterable,
+                                    Collector<KBinsDiscretizerModelData> 
collector) {
+                                List<DenseVector> list = new ArrayList<>();
+                                
iterable.iterator().forEachRemaining(list::add);
+
+                                if (list.size() == 0) {
+                                    throw new RuntimeException("The training 
set is empty.");
+                                }
+
+                                double[][] binEdges;
+                                switch (strategy) {
+                                    case UNIFORM:
+                                        binEdges = 
findBinEdgesWithUniformStrategy(list, numBins);
+                                        break;
+                                    case QUANTILE:
+                                        binEdges = 
findBinEdgesWithQuantileStrategy(list, numBins);
+                                        break;
+                                    case KMEANS:
+                                        binEdges = 
findBinEdgesWithKMeansStrategy(list, numBins);
+                                        break;
+                                    default:
+                                        throw new 
UnsupportedOperationException(
+                                                "Unsupported "
+                                                        + STRATEGY
+                                                        + " type: "
+                                                        + strategy
+                                                        + ".");
+                                }
+
+                                collector.collect(new 
KBinsDiscretizerModelData(binEdges));
+                            }
+                        });
+        modelData.getTransformation().setParallelism(1);
+
+        KBinsDiscretizerModel model =
+                new 
KBinsDiscretizerModel().setModelData(tEnv.fromDataStream(modelData));
+        ReadWriteUtils.updateExistingParams(model, getParamMap());
+        return model;
+    }
+
+    @Override
+    public Map<Param<?>, Object> getParamMap() {
+        return paramMap;
+    }
+
+    @Override
+    public void save(String path) throws IOException {
+        ReadWriteUtils.saveMetadata(this, path);
+    }
+
+    public static KBinsDiscretizer load(StreamTableEnvironment tEnv, String 
path)
+            throws IOException {
+        return ReadWriteUtils.loadStageParam(path);
+    }
+
+    private static double[][] findBinEdgesWithUniformStrategy(
+            List<DenseVector> input, int numBins) {
+        DenseVector minVector = input.get(0);
+        DenseVector maxVector = input.get(1);
+        int numColumns = minVector.size();
+        double[][] binEdges = new double[numColumns][];
+
+        for (int columnId = 0; columnId < numColumns; columnId++) {
+            double min = minVector.get(columnId);
+            double max = maxVector.get(columnId);
+            if (min == max) {
+                LOG.warn("Feature " + columnId + " is constant and the output 
will all be zero.");
+                binEdges[columnId] = new double[] {Double.MIN_VALUE, 
Double.MAX_VALUE};
+            } else {
+                double width = (max - min) / numBins;
+                binEdges[columnId] = new double[numBins + 1];
+                binEdges[columnId][0] = min;
+                for (int edgeId = 1; edgeId < numBins + 1; edgeId++) {
+                    binEdges[columnId][edgeId] = binEdges[columnId][edgeId - 
1] + width;
+                }
+            }
+        }
+        return binEdges;
+    }
+
+    private static double[][] findBinEdgesWithQuantileStrategy(
+            List<DenseVector> input, int numBins) {
+        int numColumns = input.get(0).size();
+        int numData = input.size();
+        double[][] binEdges = new double[numColumns][];
+        double[] features = new double[numData];
+
+        for (int columnId = 0; columnId < numColumns; columnId++) {
+            for (int i = 0; i < numData; i++) {
+                features[i] = input.get(i).get(columnId);
+            }
+            Arrays.sort(features);
+
+            if (features[0] == features[numData - 1]) {
+                LOG.warn("Feature " + columnId + " is constant and the output 
will all be zero.");
+                binEdges[columnId] = new double[] {Double.MIN_VALUE, 
Double.MAX_VALUE};
+            } else {
+                double width = 1.0 * features.length / numBins;
+                double[] tempBinEdges = new double[numBins + 1];
+
+                for (int binEdgeId = 0; binEdgeId < numBins; binEdgeId++) {
+                    tempBinEdges[binEdgeId] = features[(int) (binEdgeId * 
width)];
+                }
+                tempBinEdges[numBins] = features[numData - 1];
+
+                // Removes bins who are empty, i.e., the left edge equals to 
the right edge.
+                Set<Double> edges = new HashSet<>(numBins);
+                for (double edge : tempBinEdges) {
+                    edges.add(edge);
+                }
+
+                binEdges[columnId] = 
edges.stream().mapToDouble(Double::doubleValue).toArray();
+                Arrays.sort(binEdges[columnId]);
+            }
+        }
+        return binEdges;
+    }
+
+    private static double[][] findBinEdgesWithKMeansStrategy(List<DenseVector> 
input, int numBins) {
+        int numColumns = input.get(0).size();
+        int numData = input.size();
+        double[][] binEdges = new double[numColumns][numBins + 1];
+        double[] features = new double[numData];
+
+        double[] kMeansCentroids = new double[numBins];
+        double[] sumByCluster = new double[numBins];
+
+        for (int columnId = 0; columnId < numColumns; columnId++) {
+            for (int i = 0; i < numData; i++) {
+                features[i] = input.get(i).get(columnId);
+            }
+            Arrays.sort(features);
+
+            if (features[0] == features[numData - 1]) {
+                LOG.warn("Feature " + columnId + " is constant and the output 
will all be zero.");
+                binEdges[columnId] = new double[] {Double.MIN_VALUE, 
Double.MAX_VALUE};
+            } else {
+                // Checks whether there are more than {numBins} distinct 
feature values in each
+                // column.
+                // If the number of distinct values is less than {numBins + 
1}, then we do not need
+                // to conduct KMeans. Instead, we switch to use {@link
+                // KBinsDiscretizerParams#UNIFORM} for binning.
+                Set<Double> distinctFeatureValues = new HashSet<>(numBins + 1);
+                for (double feature : features) {
+                    distinctFeatureValues.add(feature);
+                    if (distinctFeatureValues.size() >= numBins + 1) {
+                        break;
+                    }
+                }
+                if (distinctFeatureValues.size() <= numBins) {
+                    double min = features[0];
+                    double max = features[features.length - 1];
+                    double width = (max - min) / numBins;
+                    binEdges[columnId] = new double[numBins + 1];
+                    binEdges[columnId][0] = min;
+                    for (int edgeId = 1; edgeId < numBins + 1; edgeId++) {
+                        binEdges[columnId][edgeId] = binEdges[columnId][edgeId 
- 1] + width;
+                    }
+                    continue;
+                } else {
+                    // Conducts KMeans here.
+                    double width = 1.0 * features.length / numBins;
+                    for (int clusterId = 0; clusterId < numBins; clusterId++) {
+                        kMeansCentroids[clusterId] = features[(int) (clusterId 
* width)];
+                    }
+
+                    // Default values for KMeans following sklearn:
+                    // 
https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.KBinsDiscretizer.html#sklearn-preprocessing-kbinsdiscretizer.

Review Comment:
   Do you think it would be better to remove comments like this? This 
information is useful for reviewers, that the implementation is following an 
existing practice. But I wonder if this information will also be necessary for 
future readers, or if this information will be outdated when sklearn got 
updated.



##########
flink-ml-lib/src/test/java/org/apache/flink/ml/feature/KBinsDiscretizerTest.java:
##########
@@ -0,0 +1,296 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.ml.feature;
+
+import org.apache.flink.api.common.restartstrategy.RestartStrategies;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.ml.feature.kbinsdiscretizer.KBinsDiscretizer;
+import org.apache.flink.ml.feature.kbinsdiscretizer.KBinsDiscretizerModel;
+import org.apache.flink.ml.feature.kbinsdiscretizer.KBinsDiscretizerModelData;
+import org.apache.flink.ml.feature.kbinsdiscretizer.KBinsDiscretizerParams;
+import org.apache.flink.ml.linalg.Vector;
+import org.apache.flink.ml.linalg.Vectors;
+import org.apache.flink.ml.util.ReadWriteUtils;
+import org.apache.flink.ml.util.TestUtils;
+import 
org.apache.flink.streaming.api.environment.ExecutionCheckpointingOptions;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.table.api.Table;
+import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
+import org.apache.flink.test.util.AbstractTestBase;
+import org.apache.flink.types.Row;
+
+import org.apache.commons.collections.IteratorUtils;
+import org.apache.commons.lang3.exception.ExceptionUtils;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static org.apache.flink.table.api.Expressions.$;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+/** Tests {@link KBinsDiscretizer} and {@link KBinsDiscretizerModel}. */
+public class KBinsDiscretizerTest extends AbstractTestBase {
+    @Rule public final TemporaryFolder tempFolder = new TemporaryFolder();
+    private StreamExecutionEnvironment env;
+    private StreamTableEnvironment tEnv;
+    private Table trainTable;
+    private Table testTable;
+
+    // Column0 for normal cases, column1 for constant cases, column2 for 
numDistinct < numBins
+    // cases.
+    private static final List<Row> TRAIN_INPUT =
+            Arrays.asList(
+                    Row.of(Vectors.dense(1, 10, 0)),
+                    Row.of(Vectors.dense(1, 10, 0)),
+                    Row.of(Vectors.dense(1, 10, 0)),
+                    Row.of(Vectors.dense(4, 10, 0)),
+                    Row.of(Vectors.dense(5, 10, 0)),
+                    Row.of(Vectors.dense(6, 10, 0)),
+                    Row.of(Vectors.dense(7, 10, 0)),
+                    Row.of(Vectors.dense(10, 10, 0)),
+                    Row.of(Vectors.dense(13, 10, 3)));
+
+    private static final List<Row> TEST_INPUT =
+            Arrays.asList(
+                    Row.of(Vectors.dense(-1, 0, 0)),
+                    Row.of(Vectors.dense(1, 1, 1)),
+                    Row.of(Vectors.dense(1.5, 1, 2)),
+                    Row.of(Vectors.dense(5, 2, 3)),
+                    Row.of(Vectors.dense(7.25, 3, 4)),
+                    Row.of(Vectors.dense(13, 4, 5)),
+                    Row.of(Vectors.dense(15, 4, 6)));
+
+    private static final double[][] UNIFORM_MODEL_DATA =
+            new double[][] {
+                new double[] {1, 5, 9, 13},
+                new double[] {Double.MIN_VALUE, Double.MAX_VALUE},
+                new double[] {0, 1, 2, 3}
+            };
+
+    private static final List<Row> UNIFORM_OUTPUT =
+            Arrays.asList(
+                    Row.of(Vectors.dense(0, 0, 0)),
+                    Row.of(Vectors.dense(0, 0, 1)),
+                    Row.of(Vectors.dense(0, 0, 2)),
+                    Row.of(Vectors.dense(1, 0, 2)),
+                    Row.of(Vectors.dense(1, 0, 2)),
+                    Row.of(Vectors.dense(2, 0, 2)),
+                    Row.of(Vectors.dense(2, 0, 2)));
+
+    private static final List<Row> QUANTILE_OUTPUT =
+            Arrays.asList(
+                    Row.of(Vectors.dense(0, 0, 0)),
+                    Row.of(Vectors.dense(0, 0, 0)),
+                    Row.of(Vectors.dense(0, 0, 0)),
+                    Row.of(Vectors.dense(1, 0, 0)),
+                    Row.of(Vectors.dense(2, 0, 0)),
+                    Row.of(Vectors.dense(2, 0, 0)),
+                    Row.of(Vectors.dense(2, 0, 0)));
+
+    private static final List<Row> KMEANS_OUTPUT =
+            Arrays.asList(
+                    Row.of(Vectors.dense(0, 0, 0)),
+                    Row.of(Vectors.dense(0, 0, 1)),
+                    Row.of(Vectors.dense(0, 0, 2)),
+                    Row.of(Vectors.dense(1, 0, 2)),
+                    Row.of(Vectors.dense(1, 0, 2)),
+                    Row.of(Vectors.dense(2, 0, 2)),
+                    Row.of(Vectors.dense(2, 0, 2)));
+
+    private static final double TOLERANCE = 1e-7;
+
+    @Before
+    public void before() {
+        Configuration config = new Configuration();
+        
config.set(ExecutionCheckpointingOptions.ENABLE_CHECKPOINTS_AFTER_TASKS_FINISH, 
true);
+        env = StreamExecutionEnvironment.getExecutionEnvironment(config);
+        env.setParallelism(4);
+        env.enableCheckpointing(100);
+        env.setRestartStrategy(RestartStrategies.noRestart());
+        tEnv = StreamTableEnvironment.create(env);
+        trainTable = 
tEnv.fromDataStream(env.fromCollection(TRAIN_INPUT)).as("input");
+        testTable = 
tEnv.fromDataStream(env.fromCollection(TEST_INPUT)).as("input");
+    }
+
+    @SuppressWarnings("all")

Review Comment:
   nit: it might be better to replace this with the detailed warnings you want 
to suppress.



##########
flink-ml-lib/src/test/java/org/apache/flink/ml/feature/KBinsDiscretizerTest.java:
##########
@@ -0,0 +1,296 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.ml.feature;
+
+import org.apache.flink.api.common.restartstrategy.RestartStrategies;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.ml.feature.kbinsdiscretizer.KBinsDiscretizer;
+import org.apache.flink.ml.feature.kbinsdiscretizer.KBinsDiscretizerModel;
+import org.apache.flink.ml.feature.kbinsdiscretizer.KBinsDiscretizerModelData;
+import org.apache.flink.ml.feature.kbinsdiscretizer.KBinsDiscretizerParams;
+import org.apache.flink.ml.linalg.Vector;
+import org.apache.flink.ml.linalg.Vectors;
+import org.apache.flink.ml.util.ReadWriteUtils;
+import org.apache.flink.ml.util.TestUtils;
+import 
org.apache.flink.streaming.api.environment.ExecutionCheckpointingOptions;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.table.api.Table;
+import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
+import org.apache.flink.test.util.AbstractTestBase;
+import org.apache.flink.types.Row;
+
+import org.apache.commons.collections.IteratorUtils;
+import org.apache.commons.lang3.exception.ExceptionUtils;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static org.apache.flink.table.api.Expressions.$;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+/** Tests {@link KBinsDiscretizer} and {@link KBinsDiscretizerModel}. */
+public class KBinsDiscretizerTest extends AbstractTestBase {
+    @Rule public final TemporaryFolder tempFolder = new TemporaryFolder();
+    private StreamExecutionEnvironment env;
+    private StreamTableEnvironment tEnv;
+    private Table trainTable;
+    private Table testTable;
+
+    // Column0 for normal cases, column1 for constant cases, column2 for 
numDistinct < numBins
+    // cases.
+    private static final List<Row> TRAIN_INPUT =
+            Arrays.asList(
+                    Row.of(Vectors.dense(1, 10, 0)),
+                    Row.of(Vectors.dense(1, 10, 0)),
+                    Row.of(Vectors.dense(1, 10, 0)),
+                    Row.of(Vectors.dense(4, 10, 0)),
+                    Row.of(Vectors.dense(5, 10, 0)),
+                    Row.of(Vectors.dense(6, 10, 0)),
+                    Row.of(Vectors.dense(7, 10, 0)),
+                    Row.of(Vectors.dense(10, 10, 0)),
+                    Row.of(Vectors.dense(13, 10, 3)));
+
+    private static final List<Row> TEST_INPUT =
+            Arrays.asList(
+                    Row.of(Vectors.dense(-1, 0, 0)),
+                    Row.of(Vectors.dense(1, 1, 1)),
+                    Row.of(Vectors.dense(1.5, 1, 2)),
+                    Row.of(Vectors.dense(5, 2, 3)),
+                    Row.of(Vectors.dense(7.25, 3, 4)),
+                    Row.of(Vectors.dense(13, 4, 5)),
+                    Row.of(Vectors.dense(15, 4, 6)));
+
+    private static final double[][] UNIFORM_MODEL_DATA =
+            new double[][] {
+                new double[] {1, 5, 9, 13},
+                new double[] {Double.MIN_VALUE, Double.MAX_VALUE},
+                new double[] {0, 1, 2, 3}
+            };
+
+    private static final List<Row> UNIFORM_OUTPUT =
+            Arrays.asList(
+                    Row.of(Vectors.dense(0, 0, 0)),
+                    Row.of(Vectors.dense(0, 0, 1)),
+                    Row.of(Vectors.dense(0, 0, 2)),
+                    Row.of(Vectors.dense(1, 0, 2)),
+                    Row.of(Vectors.dense(1, 0, 2)),
+                    Row.of(Vectors.dense(2, 0, 2)),
+                    Row.of(Vectors.dense(2, 0, 2)));
+
+    private static final List<Row> QUANTILE_OUTPUT =
+            Arrays.asList(
+                    Row.of(Vectors.dense(0, 0, 0)),
+                    Row.of(Vectors.dense(0, 0, 0)),
+                    Row.of(Vectors.dense(0, 0, 0)),
+                    Row.of(Vectors.dense(1, 0, 0)),
+                    Row.of(Vectors.dense(2, 0, 0)),
+                    Row.of(Vectors.dense(2, 0, 0)),
+                    Row.of(Vectors.dense(2, 0, 0)));
+
+    private static final List<Row> KMEANS_OUTPUT =
+            Arrays.asList(
+                    Row.of(Vectors.dense(0, 0, 0)),
+                    Row.of(Vectors.dense(0, 0, 1)),
+                    Row.of(Vectors.dense(0, 0, 2)),
+                    Row.of(Vectors.dense(1, 0, 2)),
+                    Row.of(Vectors.dense(1, 0, 2)),
+                    Row.of(Vectors.dense(2, 0, 2)),
+                    Row.of(Vectors.dense(2, 0, 2)));
+
+    private static final double TOLERANCE = 1e-7;
+
+    @Before
+    public void before() {
+        Configuration config = new Configuration();
+        
config.set(ExecutionCheckpointingOptions.ENABLE_CHECKPOINTS_AFTER_TASKS_FINISH, 
true);
+        env = StreamExecutionEnvironment.getExecutionEnvironment(config);
+        env.setParallelism(4);
+        env.enableCheckpointing(100);
+        env.setRestartStrategy(RestartStrategies.noRestart());
+        tEnv = StreamTableEnvironment.create(env);
+        trainTable = 
tEnv.fromDataStream(env.fromCollection(TRAIN_INPUT)).as("input");
+        testTable = 
tEnv.fromDataStream(env.fromCollection(TEST_INPUT)).as("input");
+    }
+
+    @SuppressWarnings("all")
+    private void verifyPredictionResult(
+            List<Row> expectedOutput, Table output, String predictionCol) 
throws Exception {
+        List<Row> collectedResult =
+                IteratorUtils.toList(
+                        
tEnv.toDataStream(output.select($(predictionCol))).executeAndCollect());
+        compareResultCollections(
+                expectedOutput,
+                collectedResult,
+                (o1, o2) -> {
+                    Vector vec1 = (Vector) o1.getField(0);
+                    Vector vec2 = (Vector) o2.getField(0);
+                    int size = Math.min(vec1.size(), vec2.size());
+                    for (int i = 0; i < size; i++) {
+                        int cmp = Double.compare(vec1.get(i), vec2.get(i));
+                        if (cmp != 0) {
+                            return cmp;
+                        }
+                    }
+                    return 0;
+                });
+    }
+
+    @Test
+    public void testParam() {
+        KBinsDiscretizer kBinsDiscretizer = new KBinsDiscretizer();
+
+        assertEquals("input", kBinsDiscretizer.getInputCol());
+        assertEquals(5, kBinsDiscretizer.getNumBins());
+        assertEquals("quantile", kBinsDiscretizer.getStrategy());
+        assertEquals(200000, kBinsDiscretizer.getSubSamples());
+        assertEquals("output", kBinsDiscretizer.getOutputCol());
+
+        kBinsDiscretizer
+                .setInputCol("test_input")
+                .setNumBins(10)
+                .setStrategy(KBinsDiscretizerParams.KMEANS)
+                .setSubSamples(1000)
+                .setOutputCol("test_output");
+
+        assertEquals("test_input", kBinsDiscretizer.getInputCol());
+        assertEquals(10, kBinsDiscretizer.getNumBins());
+        assertEquals("kmeans", kBinsDiscretizer.getStrategy());
+        assertEquals(1000, kBinsDiscretizer.getSubSamples());
+        assertEquals("test_output", kBinsDiscretizer.getOutputCol());
+    }
+
+    @Test
+    public void testOutputSchema() {
+        Table tempTable =
+                tEnv.fromDataStream(env.fromElements(Row.of("", "")))
+                        .as("test_input", "dummy_input");
+        KBinsDiscretizer kBinsDiscretizer =
+                new 
KBinsDiscretizer().setInputCol("test_input").setOutputCol("test_output");
+        Table output = kBinsDiscretizer.fit(tempTable).transform(tempTable)[0];
+
+        assertEquals(
+                Arrays.asList("test_input", "dummy_input", "test_output"),
+                output.getResolvedSchema().getColumnNames());
+    }
+
+    @Test
+    public void testFitAndPredict() throws Exception {
+        KBinsDiscretizer kBinsDiscretizer = new 
KBinsDiscretizer().setNumBins(3);
+        Table output;
+
+        // Tests uniform strategy.
+        kBinsDiscretizer.setStrategy(KBinsDiscretizerParams.UNIFORM);
+        output = kBinsDiscretizer.fit(trainTable).transform(testTable)[0];
+        verifyPredictionResult(UNIFORM_OUTPUT, output, 
kBinsDiscretizer.getOutputCol());
+
+        // Tests quantile strategy.
+        kBinsDiscretizer.setStrategy(KBinsDiscretizerParams.QUANTILE);
+        output = kBinsDiscretizer.fit(trainTable).transform(testTable)[0];
+        verifyPredictionResult(QUANTILE_OUTPUT, output, 
kBinsDiscretizer.getOutputCol());
+
+        // Tests kmeans strategy.
+        kBinsDiscretizer.setStrategy(KBinsDiscretizerParams.KMEANS);
+        output = kBinsDiscretizer.fit(trainTable).transform(testTable)[0];
+        verifyPredictionResult(KMEANS_OUTPUT, output, 
kBinsDiscretizer.getOutputCol());
+    }
+
+    @Test
+    public void testSaveLoadAndPredict() throws Exception {
+        KBinsDiscretizer kBinsDiscretizer =
+                new 
KBinsDiscretizer().setNumBins(3).setStrategy(KBinsDiscretizerParams.UNIFORM);
+        kBinsDiscretizer =
+                TestUtils.saveAndReload(
+                        tEnv, kBinsDiscretizer, 
tempFolder.newFolder().getAbsolutePath());
+
+        KBinsDiscretizerModel model = kBinsDiscretizer.fit(trainTable);
+        model = TestUtils.saveAndReload(tEnv, model, 
tempFolder.newFolder().getAbsolutePath());
+
+        assertEquals(
+                Collections.singletonList("binEdges"),
+                model.getModelData()[0].getResolvedSchema().getColumnNames());
+
+        Table output = model.transform(testTable)[0];
+        verifyPredictionResult(UNIFORM_OUTPUT, output, 
kBinsDiscretizer.getOutputCol());
+    }
+
+    @Test
+    @SuppressWarnings("unchecked")
+    public void testGetModelData() throws Exception {
+        KBinsDiscretizer kBinsDiscretizer =
+                new 
KBinsDiscretizer().setNumBins(3).setStrategy(KBinsDiscretizerParams.UNIFORM);
+        KBinsDiscretizerModel model = kBinsDiscretizer.fit(trainTable);
+        Table modelDataTable = model.getModelData()[0];
+
+        assertEquals(
+                Collections.singletonList("binEdges"),
+                modelDataTable.getResolvedSchema().getColumnNames());
+
+        List<KBinsDiscretizerModelData> collectedModelData =
+                (List<KBinsDiscretizerModelData>)
+                        IteratorUtils.toList(
+                                
KBinsDiscretizerModelData.getModelDataStream(modelDataTable)
+                                        .executeAndCollect());
+        assertEquals(1, collectedModelData.size());
+
+        KBinsDiscretizerModelData modelData = collectedModelData.get(0);
+        assertEquals(UNIFORM_MODEL_DATA.length, modelData.binEdges.length);
+        for (int i = 0; i < modelData.binEdges.length; i++) {
+            assertArrayEquals(UNIFORM_MODEL_DATA[i], modelData.binEdges[i], 
TOLERANCE);
+        }
+    }
+
+    @Test
+    public void testSetModelData() throws Exception {
+        KBinsDiscretizer kBinsDiscretizer =
+                new 
KBinsDiscretizer().setNumBins(3).setStrategy(KBinsDiscretizerParams.UNIFORM);
+
+        KBinsDiscretizerModel model = kBinsDiscretizer.fit(trainTable);
+
+        KBinsDiscretizerModel newModel = new KBinsDiscretizerModel();
+        ReadWriteUtils.updateExistingParams(newModel, model.getParamMap());
+        newModel.setModelData(model.getModelData());
+        Table output = newModel.transform(testTable)[0];
+
+        verifyPredictionResult(UNIFORM_OUTPUT, output, 
kBinsDiscretizer.getOutputCol());
+    }
+
+    @Test
+    public void testFitOnEmptyData() {
+        Table emptyTable =
+                tEnv.fromDataStream(env.fromCollection(TRAIN_INPUT).filter(x 
-> x.getArity() == 0))
+                        .as("input");
+        KBinsDiscretizerModel model = new KBinsDiscretizer().fit(emptyTable);
+        Table modelDataTable = model.getModelData()[0];
+        try {
+            IteratorUtils.toList(

Review Comment:
   nit: `modelDataTable.execute().collect().next();` might be simpler here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to