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/11/16 01:27:25 UTC

[GitHub] [flink-ml] jiangxin369 commented on a diff in pull request #175: [FLINK-29602] Add Transformer for SQLTransformer

jiangxin369 commented on code in PR #175:
URL: https://github.com/apache/flink-ml/pull/175#discussion_r1022554843


##########
flink-ml-lib/src/main/java/org/apache/flink/ml/feature/sqltransformer/SQLTransformer.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.sqltransformer;
+
+import org.apache.flink.ml.api.Transformer;
+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.table.api.Table;
+import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
+import org.apache.flink.table.api.internal.TableImpl;
+import org.apache.flink.util.Preconditions;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * SQLTransformer implements the transformations that are defined by SQL statement.
+ *
+ * <p>Currently only query operations are supported. These operations would have a SQL syntax like
+ * "SELECT ... FROM __THIS__ ...", where "__THIS__" represents the underlying table of the input
+ * table.

Review Comment:
   How about `These operations should have a SQL syntax like "SELECT ... FROM __THIS__ ...", where "__THIS__" represents the input table and cannot be modified.`.



##########
docs/content/docs/operators/feature/sqltransformer.md:
##########
@@ -0,0 +1,133 @@
+---
+title: "SQLTransformer"
+weight: 1
+type: docs
+aliases:
+- /operators/feature/sqltransformer.html
+---
+
+<!--
+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.
+-->
+
+## SQLTransformer
+
+SQLTransformer implements the transformations that are defined by SQL statement.
+
+Currently only query operations are supported. These operations would have a SQL
+syntax like `"SELECT ... FROM __THIS__ ..."`, where `"__THIS__"` represents the
+underlying table of the input table.
+
+The select clause specifies the fields, constants, and expressions to display in
+the output, it can be any select clause that Flink SQL supports. Users can also
+use Flink SQL built-in function and UDFs to operate on these selected columns.
+
+### Parameters
+
+| Key       | Default | Type   | Required | Description    |
+|:----------|:--------|:-------|:---------|:---------------|
+| statement | `null`  | String | yes      | SQL statement. |
+
+### Examples
+
+{{< tabs examples >}}
+
+{{< tab "Java">}}
+
+```java
+package org.apache.flink.ml.examples.feature;

Review Comment:
   Could you remove the package importing to keep the same style as other documents?



##########
flink-ml-lib/src/main/java/org/apache/flink/ml/feature/sqltransformer/SQLTransformerParams.java:
##########
@@ -0,0 +1,40 @@
+/*
+ * 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.sqltransformer;
+
+import org.apache.flink.ml.param.Param;
+import org.apache.flink.ml.param.StringParam;
+import org.apache.flink.ml.param.WithParams;
+
+/**
+ * Params for {@link SQLTransformer}.
+ *
+ * @param <T> The class type of this instance.
+ */
+public interface SQLTransformerParams<T> extends WithParams<T> {
+    Param<String> STATEMENT = new StringParam("statement", "SQL statement.", null);
+
+    default String getStatement() {
+        return get(STATEMENT);
+    }
+
+    default T setStatement(String value) {
+        return set(STATEMENT, value);
+    }

Review Comment:
   How about adding a ParamValidator to check if the table name is `__THIS__`?



##########
flink-ml-python/pyflink/ml/lib/feature/tests/test_sqltransformer.py:
##########
@@ -0,0 +1,67 @@
+################################################################################
+#  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.
+################################################################################
+
+from pyflink.common import Types, Row
+
+from pyflink.ml.lib.feature.sqltransformer import SQLTransformer
+from pyflink.ml.tests.test_utils import PyFlinkMLTestCase
+
+
+class SQLTransformerTest(PyFlinkMLTestCase):
+    def setUp(self):
+        super(SQLTransformerTest, self).setUp()
+        self.input_table = self.t_env.from_data_stream(
+            self.env.from_collection([
+                (0, 1.0, 3.0),
+                (2, 2.0, 5.0),
+            ],
+                type_info=Types.ROW_NAMED(
+                    ['id', 'v1', 'v2'],
+                    [Types.INT(), Types.DOUBLE(), Types.DOUBLE()])))
+        self.expected_output = [
+            (0, 1.0, 3.0, 4.0, 3.0),
+            (2, 2.0, 5.0, 7.0, 10.0)
+        ]
+
+    def test_param(self):
+        sql_transformer = SQLTransformer()
+        self.assertEqual(None, sql_transformer.statement)

Review Comment:
   ```suggestion
           self.assertIsNone(sql_transformer.statement)
   ```



-- 
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