You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/02/17 03:55:05 UTC

[GitHub] [flink-ml] weibozhao opened a new pull request #60: [FLINK-26205] Support Online Model Save in FlinkML

weibozhao opened a new pull request #60:
URL: https://github.com/apache/flink-ml/pull/60


   ## What is the purpose of the change
   Support Online Model Save in FlinkML.
   
   ## Brief change log
   Add code of online model save.
   
   ## Does this pull request potentially affect one of the following parts:
   Dependencies (does it add or upgrade a dependency): (no)
   The public API, i.e., is any changed class annotated with @public(Evolving): (no)
   Does this pull request introduce a new feature? (no)
   If yes, how is the feature documented? (Java doc)


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink-ml] weibozhao commented on a change in pull request #60: [FLINK-26205] Support Online Model Save in FlinkML

Posted by GitBox <gi...@apache.org>.
weibozhao commented on a change in pull request #60:
URL: https://github.com/apache/flink-ml/pull/60#discussion_r810864244



##########
File path: flink-ml-lib/src/test/java/org/apache/flink/ml/classification/OnlineModelSaveLoadTest.java
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.classification;
+
+import org.apache.flink.api.common.restartstrategy.RestartStrategies;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.ml.classification.logisticregression.LogisticRegressionModel;
+import org.apache.flink.ml.classification.logisticregression.LogisticRegressionModelData;
+import org.apache.flink.ml.linalg.DenseVector;
+import org.apache.flink.ml.linalg.Vectors;
+import org.apache.flink.streaming.api.environment.ExecutionCheckpointingOptions;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.Schema;
+import org.apache.flink.table.api.Table;
+import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
+import org.apache.flink.types.Row;
+
+import org.apache.commons.collections.IteratorUtils;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.apache.flink.ml.util.ReadWriteUtils.loadModelData;
+
+/** Tests online LogisticRegression model save and load. */
+public class OnlineModelSaveLoadTest {
+    @Rule public final TemporaryFolder tempFolder = new TemporaryFolder();
+
+    StreamTableEnvironment tEnv;
+    Schema modelSchema = Schema.newBuilder().column("f0", DataTypes.of(DenseVector.class)).build();
+    Schema dataSchema =
+            Schema.newBuilder()
+                    .column("f0", DataTypes.of(Double.class))
+                    .column("f1", DataTypes.of(DenseVector.class))
+                    .build();
+
+    private static final List<Row> modelData =
+            new ArrayList<>(
+                    Arrays.asList(
+                            Row.of(Vectors.dense(2.0, 4.5, 3.0)),
+                            Row.of(Vectors.dense(2.1, 4.6, 3.1)),
+                            Row.of(Vectors.dense(20.1, 5.6, 3.1)),
+                            Row.of(Vectors.dense(2.1, 4.7, 3.1))));
+
+    private static final List<Row> validData =
+            new ArrayList<>(
+                    Arrays.asList(
+                            Row.of(1.0, Vectors.dense(1.0, 3.5, -4.0)),
+                            Row.of(0.0, Vectors.dense(1.1, -8.6, 3.3))));
+
+    @Test
+    public void saveAndLoadOnlineModel() throws Exception {
+        Configuration config = new Configuration();
+        config.set(ExecutionCheckpointingOptions.ENABLE_CHECKPOINTS_AFTER_TASKS_FINISH, true);
+        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(config);
+        env.enableCheckpointing(100);
+        env.setRestartStrategy(RestartStrategies.noRestart());
+        tEnv = StreamTableEnvironment.create(env);
+        env.setParallelism(1);
+
+        String tmpPath = tempFolder.newFolder().getAbsolutePath();
+
+        /* Constructs online LogisticRegression model. */
+        Table lrModelStream =
+                tEnv.fromDataStream(env.fromCollection(modelData), modelSchema).as("coefficient");
+        LogisticRegressionModel lr = new LogisticRegressionModel();
+        /* Saves online model to given path (tmpPath). */
+        lr.setModelData(lrModelStream);
+        lr.save(tmpPath);
+        env.execute();
+
+        /* Constructs validated data table. */
+        Table validDataTable =
+                tEnv.fromDataStream(env.fromCollection(validData), dataSchema).as("label, vec");
+
+        Process proc = Runtime.getRuntime().exec("ls " + tmpPath + "/data");
+        BufferedReader bufferedReader =
+                new BufferedReader(new InputStreamReader(proc.getInputStream()));
+
+        /* Loads every LogisticRegression model in model path and validates it. */
+        String modelVersion;
+        while ((modelVersion = bufferedReader.readLine()) != null) {

Review comment:
       OK




-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink-ml] weibozhao commented on a change in pull request #60: [FLINK-26205] Support Online Model Save in FlinkML

Posted by GitBox <gi...@apache.org>.
weibozhao commented on a change in pull request #60:
URL: https://github.com/apache/flink-ml/pull/60#discussion_r810892684



##########
File path: flink-ml-core/src/main/java/org/apache/flink/ml/util/ReadWriteUtils.java
##########
@@ -431,8 +426,37 @@ public static void updateExistingParams(Stage<?> stage, Map<Param<?>, Object> pa
      */
     public static <T> DataStream<T> loadModelData(
             StreamExecutionEnvironment env, String path, SimpleStreamFormat<T> modelDecoder) {
+        String[] fileNames = new File(path).list();
+        org.apache.flink.core.fs.Path modelPath = null;
+        for (String fileName : fileNames) {
+            if (new File(path + "/" + fileName).isDirectory()) {
+                modelPath = new org.apache.flink.core.fs.Path(path + "/" + fileName);
+            }
+        }
+        Source<T, ?, ?> source = FileSource.forRecordStreamFormat(modelDecoder, modelPath).build();

Review comment:
       OK, I will refine it.




-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink-ml] weibozhao commented on a change in pull request #60: [FLINK-26205] Support Online Model Save in FlinkML

Posted by GitBox <gi...@apache.org>.
weibozhao commented on a change in pull request #60:
URL: https://github.com/apache/flink-ml/pull/60#discussion_r810859676



##########
File path: flink-ml-core/src/main/java/org/apache/flink/ml/util/ReadWriteUtils.java
##########
@@ -401,6 +383,19 @@ public static void updateExistingParams(Stage<?> stage, Map<Param<?>, Object> pa
         }
     }
 
+    /** Returns a subdirectory of the given path for saving/loading model data. */
+    private static String getDataPath(String path) {
+        return Paths.get(path, "data").toString();
+    }
+
+    /** Assigns model version for every model data when sinking to files. */
+    public static class ModelVersionAssigner<T> extends BasePathBucketAssigner<T> {

Review comment:
       OK




-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink-ml] weibozhao commented on a change in pull request #60: [FLINK-26205] Support Online Model Save in FlinkML

Posted by GitBox <gi...@apache.org>.
weibozhao commented on a change in pull request #60:
URL: https://github.com/apache/flink-ml/pull/60#discussion_r810861246



##########
File path: flink-ml-core/src/main/java/org/apache/flink/ml/util/ReadWriteUtils.java
##########
@@ -431,8 +426,37 @@ public static void updateExistingParams(Stage<?> stage, Map<Param<?>, Object> pa
      */
     public static <T> DataStream<T> loadModelData(
             StreamExecutionEnvironment env, String path, SimpleStreamFormat<T> modelDecoder) {
+        String[] fileNames = new File(path).list();
+        org.apache.flink.core.fs.Path modelPath = null;
+        for (String fileName : fileNames) {
+            if (new File(path + "/" + fileName).isDirectory()) {
+                modelPath = new org.apache.flink.core.fs.Path(path + "/" + fileName);
+            }
+        }
+        Source<T, ?, ?> source = FileSource.forRecordStreamFormat(modelDecoder, modelPath).build();
+        return env.fromSource(source, WatermarkStrategy.noWatermarks(), "modelData");
+    }
+
+    /**
+     * Loads the model data from the given path which has more than one model.

Review comment:
       OK, I will update the doc. This function can get a model data with special model version from the path which has more than one model version.




-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink-ml] zhipeng93 commented on pull request #60: [FLINK-26205] Support Online Model Save in FlinkML

Posted by GitBox <gi...@apache.org>.
zhipeng93 commented on pull request #60:
URL: https://github.com/apache/flink-ml/pull/60#issuecomment-1074878659


   Closing for now. We can open it later if needed.


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink-ml] weibozhao commented on a change in pull request #60: [FLINK-26205] Support Online Model Save in FlinkML

Posted by GitBox <gi...@apache.org>.
weibozhao commented on a change in pull request #60:
URL: https://github.com/apache/flink-ml/pull/60#discussion_r810864110



##########
File path: flink-ml-lib/src/test/java/org/apache/flink/ml/classification/OnlineModelSaveLoadTest.java
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.classification;
+
+import org.apache.flink.api.common.restartstrategy.RestartStrategies;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.ml.classification.logisticregression.LogisticRegressionModel;
+import org.apache.flink.ml.classification.logisticregression.LogisticRegressionModelData;
+import org.apache.flink.ml.linalg.DenseVector;
+import org.apache.flink.ml.linalg.Vectors;
+import org.apache.flink.streaming.api.environment.ExecutionCheckpointingOptions;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.Schema;
+import org.apache.flink.table.api.Table;
+import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
+import org.apache.flink.types.Row;
+
+import org.apache.commons.collections.IteratorUtils;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.apache.flink.ml.util.ReadWriteUtils.loadModelData;
+
+/** Tests online LogisticRegression model save and load. */
+public class OnlineModelSaveLoadTest {
+    @Rule public final TemporaryFolder tempFolder = new TemporaryFolder();
+
+    StreamTableEnvironment tEnv;
+    Schema modelSchema = Schema.newBuilder().column("f0", DataTypes.of(DenseVector.class)).build();
+    Schema dataSchema =
+            Schema.newBuilder()
+                    .column("f0", DataTypes.of(Double.class))
+                    .column("f1", DataTypes.of(DenseVector.class))
+                    .build();
+
+    private static final List<Row> modelData =
+            new ArrayList<>(
+                    Arrays.asList(
+                            Row.of(Vectors.dense(2.0, 4.5, 3.0)),
+                            Row.of(Vectors.dense(2.1, 4.6, 3.1)),
+                            Row.of(Vectors.dense(20.1, 5.6, 3.1)),
+                            Row.of(Vectors.dense(2.1, 4.7, 3.1))));
+
+    private static final List<Row> validData =
+            new ArrayList<>(
+                    Arrays.asList(
+                            Row.of(1.0, Vectors.dense(1.0, 3.5, -4.0)),
+                            Row.of(0.0, Vectors.dense(1.1, -8.6, 3.3))));
+
+    @Test
+    public void saveAndLoadOnlineModel() throws Exception {
+        Configuration config = new Configuration();

Review comment:
       OK




-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink-ml] weibozhao commented on a change in pull request #60: [FLINK-26205] Support Online Model Save in FlinkML

Posted by GitBox <gi...@apache.org>.
weibozhao commented on a change in pull request #60:
URL: https://github.com/apache/flink-ml/pull/60#discussion_r810862420



##########
File path: flink-ml-lib/src/test/java/org/apache/flink/ml/classification/OnlineModelSaveLoadTest.java
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.classification;
+
+import org.apache.flink.api.common.restartstrategy.RestartStrategies;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.ml.classification.logisticregression.LogisticRegressionModel;
+import org.apache.flink.ml.classification.logisticregression.LogisticRegressionModelData;
+import org.apache.flink.ml.linalg.DenseVector;
+import org.apache.flink.ml.linalg.Vectors;
+import org.apache.flink.streaming.api.environment.ExecutionCheckpointingOptions;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.Schema;
+import org.apache.flink.table.api.Table;
+import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
+import org.apache.flink.types.Row;
+
+import org.apache.commons.collections.IteratorUtils;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.apache.flink.ml.util.ReadWriteUtils.loadModelData;
+
+/** Tests online LogisticRegression model save and load. */
+public class OnlineModelSaveLoadTest {
+    @Rule public final TemporaryFolder tempFolder = new TemporaryFolder();
+
+    StreamTableEnvironment tEnv;
+    Schema modelSchema = Schema.newBuilder().column("f0", DataTypes.of(DenseVector.class)).build();
+    Schema dataSchema =
+            Schema.newBuilder()
+                    .column("f0", DataTypes.of(Double.class))
+                    .column("f1", DataTypes.of(DenseVector.class))
+                    .build();
+
+    private static final List<Row> modelData =
+            new ArrayList<>(
+                    Arrays.asList(
+                            Row.of(Vectors.dense(2.0, 4.5, 3.0)),
+                            Row.of(Vectors.dense(2.1, 4.6, 3.1)),
+                            Row.of(Vectors.dense(20.1, 5.6, 3.1)),
+                            Row.of(Vectors.dense(2.1, 4.7, 3.1))));
+
+    private static final List<Row> validData =
+            new ArrayList<>(
+                    Arrays.asList(
+                            Row.of(1.0, Vectors.dense(1.0, 3.5, -4.0)),
+                            Row.of(0.0, Vectors.dense(1.1, -8.6, 3.3))));
+
+    @Test
+    public void saveAndLoadOnlineModel() throws Exception {
+        Configuration config = new Configuration();
+        config.set(ExecutionCheckpointingOptions.ENABLE_CHECKPOINTS_AFTER_TASKS_FINISH, true);
+        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(config);
+        env.enableCheckpointing(100);
+        env.setRestartStrategy(RestartStrategies.noRestart());
+        tEnv = StreamTableEnvironment.create(env);
+        env.setParallelism(1);
+
+        String tmpPath = tempFolder.newFolder().getAbsolutePath();
+
+        /* Constructs online LogisticRegression model. */
+        Table lrModelStream =
+                tEnv.fromDataStream(env.fromCollection(modelData), modelSchema).as("coefficient");
+        LogisticRegressionModel lr = new LogisticRegressionModel();
+        /* Saves online model to given path (tmpPath). */
+        lr.setModelData(lrModelStream);
+        lr.save(tmpPath);
+        env.execute();
+
+        /* Constructs validated data table. */
+        Table validDataTable =
+                tEnv.fromDataStream(env.fromCollection(validData), dataSchema).as("label, vec");
+
+        Process proc = Runtime.getRuntime().exec("ls " + tmpPath + "/data");
+        BufferedReader bufferedReader =
+                new BufferedReader(new InputStreamReader(proc.getInputStream()));
+
+        /* Loads every LogisticRegression model in model path and validates it. */
+        String modelVersion;
+        while ((modelVersion = bufferedReader.readLine()) != null) {
+            if (!"metadata".equals(modelVersion)) {
+                LogisticRegressionModel lrModel =
+                        new LogisticRegressionModel().setFeaturesCol("vec");
+                Table modelData =
+                        tEnv.fromDataStream(
+                                        loadModelData(
+                                                env,
+                                                tmpPath,
+                                                new LogisticRegressionModelData.ModelDataDecoder(),
+                                                modelVersion))
+                                .as("label, vec");

Review comment:
       The validated data has feature(vec) and label. I will check the prediction result  agree with given label.

##########
File path: flink-ml-lib/src/test/java/org/apache/flink/ml/classification/OnlineModelSaveLoadTest.java
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.classification;
+
+import org.apache.flink.api.common.restartstrategy.RestartStrategies;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.ml.classification.logisticregression.LogisticRegressionModel;
+import org.apache.flink.ml.classification.logisticregression.LogisticRegressionModelData;
+import org.apache.flink.ml.linalg.DenseVector;
+import org.apache.flink.ml.linalg.Vectors;
+import org.apache.flink.streaming.api.environment.ExecutionCheckpointingOptions;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.Schema;
+import org.apache.flink.table.api.Table;
+import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
+import org.apache.flink.types.Row;
+
+import org.apache.commons.collections.IteratorUtils;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.apache.flink.ml.util.ReadWriteUtils.loadModelData;
+
+/** Tests online LogisticRegression model save and load. */
+public class OnlineModelSaveLoadTest {
+    @Rule public final TemporaryFolder tempFolder = new TemporaryFolder();
+
+    StreamTableEnvironment tEnv;
+    Schema modelSchema = Schema.newBuilder().column("f0", DataTypes.of(DenseVector.class)).build();
+    Schema dataSchema =
+            Schema.newBuilder()
+                    .column("f0", DataTypes.of(Double.class))
+                    .column("f1", DataTypes.of(DenseVector.class))
+                    .build();
+
+    private static final List<Row> modelData =
+            new ArrayList<>(
+                    Arrays.asList(
+                            Row.of(Vectors.dense(2.0, 4.5, 3.0)),
+                            Row.of(Vectors.dense(2.1, 4.6, 3.1)),
+                            Row.of(Vectors.dense(20.1, 5.6, 3.1)),
+                            Row.of(Vectors.dense(2.1, 4.7, 3.1))));
+
+    private static final List<Row> validData =
+            new ArrayList<>(
+                    Arrays.asList(
+                            Row.of(1.0, Vectors.dense(1.0, 3.5, -4.0)),
+                            Row.of(0.0, Vectors.dense(1.1, -8.6, 3.3))));
+
+    @Test
+    public void saveAndLoadOnlineModel() throws Exception {
+        Configuration config = new Configuration();
+        config.set(ExecutionCheckpointingOptions.ENABLE_CHECKPOINTS_AFTER_TASKS_FINISH, true);
+        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(config);
+        env.enableCheckpointing(100);
+        env.setRestartStrategy(RestartStrategies.noRestart());
+        tEnv = StreamTableEnvironment.create(env);
+        env.setParallelism(1);
+
+        String tmpPath = tempFolder.newFolder().getAbsolutePath();
+
+        /* Constructs online LogisticRegression model. */
+        Table lrModelStream =
+                tEnv.fromDataStream(env.fromCollection(modelData), modelSchema).as("coefficient");
+        LogisticRegressionModel lr = new LogisticRegressionModel();
+        /* Saves online model to given path (tmpPath). */
+        lr.setModelData(lrModelStream);
+        lr.save(tmpPath);
+        env.execute();
+
+        /* Constructs validated data table. */
+        Table validDataTable =
+                tEnv.fromDataStream(env.fromCollection(validData), dataSchema).as("label, vec");
+
+        Process proc = Runtime.getRuntime().exec("ls " + tmpPath + "/data");
+        BufferedReader bufferedReader =
+                new BufferedReader(new InputStreamReader(proc.getInputStream()));
+
+        /* Loads every LogisticRegression model in model path and validates it. */
+        String modelVersion;
+        while ((modelVersion = bufferedReader.readLine()) != null) {
+            if (!"metadata".equals(modelVersion)) {
+                LogisticRegressionModel lrModel =

Review comment:
       OK 




-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink-ml] zhipeng93 closed pull request #60: [FLINK-26205] Support Online Model Save in FlinkML

Posted by GitBox <gi...@apache.org>.
zhipeng93 closed pull request #60:
URL: https://github.com/apache/flink-ml/pull/60


   


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink-ml] zhipeng93 commented on a change in pull request #60: [FLINK-26205] Support Online Model Save in FlinkML

Posted by GitBox <gi...@apache.org>.
zhipeng93 commented on a change in pull request #60:
URL: https://github.com/apache/flink-ml/pull/60#discussion_r810726491



##########
File path: flink-ml-core/src/main/java/org/apache/flink/ml/util/ReadWriteUtils.java
##########
@@ -401,6 +383,19 @@ public static void updateExistingParams(Stage<?> stage, Map<Param<?>, Object> pa
         }
     }
 
+    /** Returns a subdirectory of the given path for saving/loading model data. */
+    private static String getDataPath(String path) {
+        return Paths.get(path, "data").toString();
+    }
+
+    /** Assigns model version for every model data when sinking to files. */
+    public static class ModelVersionAssigner<T> extends BasePathBucketAssigner<T> {

Review comment:
       nits: public --> private

##########
File path: flink-ml-core/src/main/java/org/apache/flink/ml/util/ReadWriteUtils.java
##########
@@ -401,6 +383,19 @@ public static void updateExistingParams(Stage<?> stage, Map<Param<?>, Object> pa
         }
     }
 
+    /** Returns a subdirectory of the given path for saving/loading model data. */
+    private static String getDataPath(String path) {
+        return Paths.get(path, "data").toString();
+    }
+
+    /** Assigns model version for every model data when sinking to files. */
+    public static class ModelVersionAssigner<T> extends BasePathBucketAssigner<T> {
+        @Override
+        public String getBucketId(T element, Context context) {
+            return String.valueOf(System.nanoTime());

Review comment:
       Can we make `modelVersionAssiginer` independent of execution time? 
   If model data contains multiple streams and we use the current version assigner(with timestamp as the version), we may not be able to associate the model data from different streams. 

##########
File path: flink-ml-lib/src/test/java/org/apache/flink/ml/classification/OnlineModelSaveLoadTest.java
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.classification;
+
+import org.apache.flink.api.common.restartstrategy.RestartStrategies;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.ml.classification.logisticregression.LogisticRegressionModel;
+import org.apache.flink.ml.classification.logisticregression.LogisticRegressionModelData;
+import org.apache.flink.ml.linalg.DenseVector;
+import org.apache.flink.ml.linalg.Vectors;
+import org.apache.flink.streaming.api.environment.ExecutionCheckpointingOptions;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.Schema;
+import org.apache.flink.table.api.Table;
+import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
+import org.apache.flink.types.Row;
+
+import org.apache.commons.collections.IteratorUtils;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.apache.flink.ml.util.ReadWriteUtils.loadModelData;
+
+/** Tests online LogisticRegression model save and load. */
+public class OnlineModelSaveLoadTest {
+    @Rule public final TemporaryFolder tempFolder = new TemporaryFolder();
+
+    StreamTableEnvironment tEnv;
+    Schema modelSchema = Schema.newBuilder().column("f0", DataTypes.of(DenseVector.class)).build();
+    Schema dataSchema =
+            Schema.newBuilder()
+                    .column("f0", DataTypes.of(Double.class))
+                    .column("f1", DataTypes.of(DenseVector.class))
+                    .build();
+
+    private static final List<Row> modelData =
+            new ArrayList<>(
+                    Arrays.asList(
+                            Row.of(Vectors.dense(2.0, 4.5, 3.0)),
+                            Row.of(Vectors.dense(2.1, 4.6, 3.1)),
+                            Row.of(Vectors.dense(20.1, 5.6, 3.1)),
+                            Row.of(Vectors.dense(2.1, 4.7, 3.1))));
+
+    private static final List<Row> validData =
+            new ArrayList<>(
+                    Arrays.asList(
+                            Row.of(1.0, Vectors.dense(1.0, 3.5, -4.0)),
+                            Row.of(0.0, Vectors.dense(1.1, -8.6, 3.3))));
+
+    @Test
+    public void saveAndLoadOnlineModel() throws Exception {
+        Configuration config = new Configuration();
+        config.set(ExecutionCheckpointingOptions.ENABLE_CHECKPOINTS_AFTER_TASKS_FINISH, true);
+        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(config);
+        env.enableCheckpointing(100);
+        env.setRestartStrategy(RestartStrategies.noRestart());
+        tEnv = StreamTableEnvironment.create(env);
+        env.setParallelism(1);
+
+        String tmpPath = tempFolder.newFolder().getAbsolutePath();
+
+        /* Constructs online LogisticRegression model. */
+        Table lrModelStream =
+                tEnv.fromDataStream(env.fromCollection(modelData), modelSchema).as("coefficient");
+        LogisticRegressionModel lr = new LogisticRegressionModel();
+        /* Saves online model to given path (tmpPath). */
+        lr.setModelData(lrModelStream);
+        lr.save(tmpPath);
+        env.execute();
+
+        /* Constructs validated data table. */
+        Table validDataTable =
+                tEnv.fromDataStream(env.fromCollection(validData), dataSchema).as("label, vec");
+
+        Process proc = Runtime.getRuntime().exec("ls " + tmpPath + "/data");
+        BufferedReader bufferedReader =
+                new BufferedReader(new InputStreamReader(proc.getInputStream()));
+
+        /* Loads every LogisticRegression model in model path and validates it. */
+        String modelVersion;
+        while ((modelVersion = bufferedReader.readLine()) != null) {
+            if (!"metadata".equals(modelVersion)) {
+                LogisticRegressionModel lrModel =

Review comment:
       nits: `LogisticRegressionModel lrModel =..` could be outside of the loop.

##########
File path: flink-ml-core/src/main/java/org/apache/flink/ml/util/ReadWriteUtils.java
##########
@@ -431,8 +426,37 @@ public static void updateExistingParams(Stage<?> stage, Map<Param<?>, Object> pa
      */
     public static <T> DataStream<T> loadModelData(
             StreamExecutionEnvironment env, String path, SimpleStreamFormat<T> modelDecoder) {
+        String[] fileNames = new File(path).list();
+        org.apache.flink.core.fs.Path modelPath = null;
+        for (String fileName : fileNames) {
+            if (new File(path + "/" + fileName).isDirectory()) {
+                modelPath = new org.apache.flink.core.fs.Path(path + "/" + fileName);
+            }
+        }
+        Source<T, ?, ?> source = FileSource.forRecordStreamFormat(modelDecoder, modelPath).build();

Review comment:
       Should we still use ".../data/" as the default model data path?
   
   If there is a directory that is not ".../data/", can the test case still work?

##########
File path: flink-ml-core/src/main/java/org/apache/flink/ml/util/ReadWriteUtils.java
##########
@@ -431,8 +426,37 @@ public static void updateExistingParams(Stage<?> stage, Map<Param<?>, Object> pa
      */
     public static <T> DataStream<T> loadModelData(
             StreamExecutionEnvironment env, String path, SimpleStreamFormat<T> modelDecoder) {
+        String[] fileNames = new File(path).list();
+        org.apache.flink.core.fs.Path modelPath = null;
+        for (String fileName : fileNames) {
+            if (new File(path + "/" + fileName).isDirectory()) {
+                modelPath = new org.apache.flink.core.fs.Path(path + "/" + fileName);
+            }
+        }
+        Source<T, ?, ?> source = FileSource.forRecordStreamFormat(modelDecoder, modelPath).build();
+        return env.fromSource(source, WatermarkStrategy.noWatermarks(), "modelData");
+    }
+
+    /**
+     * Loads the model data from the given path which has more than one model.

Review comment:
       Can you update the java doc and explain why do we need this function here?

##########
File path: flink-ml-lib/src/test/java/org/apache/flink/ml/classification/OnlineModelSaveLoadTest.java
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.classification;
+
+import org.apache.flink.api.common.restartstrategy.RestartStrategies;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.ml.classification.logisticregression.LogisticRegressionModel;
+import org.apache.flink.ml.classification.logisticregression.LogisticRegressionModelData;
+import org.apache.flink.ml.linalg.DenseVector;
+import org.apache.flink.ml.linalg.Vectors;
+import org.apache.flink.streaming.api.environment.ExecutionCheckpointingOptions;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.Schema;
+import org.apache.flink.table.api.Table;
+import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
+import org.apache.flink.types.Row;
+
+import org.apache.commons.collections.IteratorUtils;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.apache.flink.ml.util.ReadWriteUtils.loadModelData;
+
+/** Tests online LogisticRegression model save and load. */
+public class OnlineModelSaveLoadTest {
+    @Rule public final TemporaryFolder tempFolder = new TemporaryFolder();
+
+    StreamTableEnvironment tEnv;
+    Schema modelSchema = Schema.newBuilder().column("f0", DataTypes.of(DenseVector.class)).build();
+    Schema dataSchema =
+            Schema.newBuilder()
+                    .column("f0", DataTypes.of(Double.class))
+                    .column("f1", DataTypes.of(DenseVector.class))
+                    .build();
+
+    private static final List<Row> modelData =
+            new ArrayList<>(
+                    Arrays.asList(
+                            Row.of(Vectors.dense(2.0, 4.5, 3.0)),
+                            Row.of(Vectors.dense(2.1, 4.6, 3.1)),
+                            Row.of(Vectors.dense(20.1, 5.6, 3.1)),
+                            Row.of(Vectors.dense(2.1, 4.7, 3.1))));
+
+    private static final List<Row> validData =
+            new ArrayList<>(
+                    Arrays.asList(
+                            Row.of(1.0, Vectors.dense(1.0, 3.5, -4.0)),
+                            Row.of(0.0, Vectors.dense(1.1, -8.6, 3.3))));
+
+    @Test
+    public void saveAndLoadOnlineModel() throws Exception {
+        Configuration config = new Configuration();
+        config.set(ExecutionCheckpointingOptions.ENABLE_CHECKPOINTS_AFTER_TASKS_FINISH, true);
+        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(config);
+        env.enableCheckpointing(100);
+        env.setRestartStrategy(RestartStrategies.noRestart());
+        tEnv = StreamTableEnvironment.create(env);
+        env.setParallelism(1);
+
+        String tmpPath = tempFolder.newFolder().getAbsolutePath();
+
+        /* Constructs online LogisticRegression model. */
+        Table lrModelStream =
+                tEnv.fromDataStream(env.fromCollection(modelData), modelSchema).as("coefficient");
+        LogisticRegressionModel lr = new LogisticRegressionModel();
+        /* Saves online model to given path (tmpPath). */
+        lr.setModelData(lrModelStream);
+        lr.save(tmpPath);
+        env.execute();
+
+        /* Constructs validated data table. */
+        Table validDataTable =
+                tEnv.fromDataStream(env.fromCollection(validData), dataSchema).as("label, vec");
+
+        Process proc = Runtime.getRuntime().exec("ls " + tmpPath + "/data");
+        BufferedReader bufferedReader =
+                new BufferedReader(new InputStreamReader(proc.getInputStream()));
+
+        /* Loads every LogisticRegression model in model path and validates it. */
+        String modelVersion;
+        while ((modelVersion = bufferedReader.readLine()) != null) {

Review comment:
       Can we also hava a test case that loads all of the model data in a single data stream?

##########
File path: flink-ml-lib/src/test/java/org/apache/flink/ml/classification/OnlineModelSaveLoadTest.java
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.classification;
+
+import org.apache.flink.api.common.restartstrategy.RestartStrategies;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.ml.classification.logisticregression.LogisticRegressionModel;
+import org.apache.flink.ml.classification.logisticregression.LogisticRegressionModelData;
+import org.apache.flink.ml.linalg.DenseVector;
+import org.apache.flink.ml.linalg.Vectors;
+import org.apache.flink.streaming.api.environment.ExecutionCheckpointingOptions;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.Schema;
+import org.apache.flink.table.api.Table;
+import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
+import org.apache.flink.types.Row;
+
+import org.apache.commons.collections.IteratorUtils;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.apache.flink.ml.util.ReadWriteUtils.loadModelData;
+
+/** Tests online LogisticRegression model save and load. */
+public class OnlineModelSaveLoadTest {
+    @Rule public final TemporaryFolder tempFolder = new TemporaryFolder();
+
+    StreamTableEnvironment tEnv;
+    Schema modelSchema = Schema.newBuilder().column("f0", DataTypes.of(DenseVector.class)).build();
+    Schema dataSchema =
+            Schema.newBuilder()
+                    .column("f0", DataTypes.of(Double.class))
+                    .column("f1", DataTypes.of(DenseVector.class))
+                    .build();
+
+    private static final List<Row> modelData =
+            new ArrayList<>(
+                    Arrays.asList(
+                            Row.of(Vectors.dense(2.0, 4.5, 3.0)),
+                            Row.of(Vectors.dense(2.1, 4.6, 3.1)),
+                            Row.of(Vectors.dense(20.1, 5.6, 3.1)),
+                            Row.of(Vectors.dense(2.1, 4.7, 3.1))));
+
+    private static final List<Row> validData =
+            new ArrayList<>(
+                    Arrays.asList(
+                            Row.of(1.0, Vectors.dense(1.0, 3.5, -4.0)),
+                            Row.of(0.0, Vectors.dense(1.1, -8.6, 3.3))));
+
+    @Test
+    public void saveAndLoadOnlineModel() throws Exception {
+        Configuration config = new Configuration();

Review comment:
       It would be better to extract the common logic here in `Before` function, same as we did in other test cases.

##########
File path: flink-ml-lib/src/test/java/org/apache/flink/ml/classification/OnlineModelSaveLoadTest.java
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.classification;
+
+import org.apache.flink.api.common.restartstrategy.RestartStrategies;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.ml.classification.logisticregression.LogisticRegressionModel;
+import org.apache.flink.ml.classification.logisticregression.LogisticRegressionModelData;
+import org.apache.flink.ml.linalg.DenseVector;
+import org.apache.flink.ml.linalg.Vectors;
+import org.apache.flink.streaming.api.environment.ExecutionCheckpointingOptions;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.Schema;
+import org.apache.flink.table.api.Table;
+import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
+import org.apache.flink.types.Row;
+
+import org.apache.commons.collections.IteratorUtils;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.apache.flink.ml.util.ReadWriteUtils.loadModelData;
+
+/** Tests online LogisticRegression model save and load. */
+public class OnlineModelSaveLoadTest {
+    @Rule public final TemporaryFolder tempFolder = new TemporaryFolder();
+
+    StreamTableEnvironment tEnv;
+    Schema modelSchema = Schema.newBuilder().column("f0", DataTypes.of(DenseVector.class)).build();
+    Schema dataSchema =
+            Schema.newBuilder()
+                    .column("f0", DataTypes.of(Double.class))
+                    .column("f1", DataTypes.of(DenseVector.class))
+                    .build();
+
+    private static final List<Row> modelData =
+            new ArrayList<>(
+                    Arrays.asList(
+                            Row.of(Vectors.dense(2.0, 4.5, 3.0)),
+                            Row.of(Vectors.dense(2.1, 4.6, 3.1)),
+                            Row.of(Vectors.dense(20.1, 5.6, 3.1)),
+                            Row.of(Vectors.dense(2.1, 4.7, 3.1))));
+
+    private static final List<Row> validData =
+            new ArrayList<>(
+                    Arrays.asList(
+                            Row.of(1.0, Vectors.dense(1.0, 3.5, -4.0)),
+                            Row.of(0.0, Vectors.dense(1.1, -8.6, 3.3))));
+
+    @Test
+    public void saveAndLoadOnlineModel() throws Exception {
+        Configuration config = new Configuration();
+        config.set(ExecutionCheckpointingOptions.ENABLE_CHECKPOINTS_AFTER_TASKS_FINISH, true);
+        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(config);
+        env.enableCheckpointing(100);
+        env.setRestartStrategy(RestartStrategies.noRestart());
+        tEnv = StreamTableEnvironment.create(env);
+        env.setParallelism(1);
+
+        String tmpPath = tempFolder.newFolder().getAbsolutePath();
+
+        /* Constructs online LogisticRegression model. */
+        Table lrModelStream =
+                tEnv.fromDataStream(env.fromCollection(modelData), modelSchema).as("coefficient");
+        LogisticRegressionModel lr = new LogisticRegressionModel();
+        /* Saves online model to given path (tmpPath). */
+        lr.setModelData(lrModelStream);
+        lr.save(tmpPath);
+        env.execute();
+
+        /* Constructs validated data table. */
+        Table validDataTable =
+                tEnv.fromDataStream(env.fromCollection(validData), dataSchema).as("label, vec");
+
+        Process proc = Runtime.getRuntime().exec("ls " + tmpPath + "/data");
+        BufferedReader bufferedReader =
+                new BufferedReader(new InputStreamReader(proc.getInputStream()));
+
+        /* Loads every LogisticRegression model in model path and validates it. */
+        String modelVersion;
+        while ((modelVersion = bufferedReader.readLine()) != null) {
+            if (!"metadata".equals(modelVersion)) {
+                LogisticRegressionModel lrModel =
+                        new LogisticRegressionModel().setFeaturesCol("vec");
+                Table modelData =
+                        tEnv.fromDataStream(
+                                        loadModelData(
+                                                env,
+                                                tmpPath,
+                                                new LogisticRegressionModelData.ModelDataDecoder(),
+                                                modelVersion))
+                                .as("label, vec");

Review comment:
       Why do you convert model data as `label, vec`?




-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink-ml] yunfengzhou-hub commented on pull request #60: [FLINK-26205] Support Online Model Save in FlinkML

Posted by GitBox <gi...@apache.org>.
yunfengzhou-hub commented on pull request #60:
URL: https://github.com/apache/flink-ml/pull/60#issuecomment-1046377495


   Thanks for the PR! I think it's a crucial feature for Flink ML.
   
   I suppose this PR also wants to solve the problem raised in [this email](https://lists.apache.org/thread/2cs3g872lbyzqyjh4xjkn52fhko4mo0y). In this email an exception was thrown when an unbounded stream was fed to an Estimator, but the test cases introduced by this PR have only covered the bounded situations. It might be better if we could add test cases that corresponds to the conditions described in the email.


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org