dianfu commented on a change in pull request #13491:
URL: https://github.com/apache/flink/pull/13491#discussion_r495565821



##########
File path: flink-python/pyflink/table/table_environment.py
##########
@@ -1770,11 +1771,19 @@ def from_data_stream(self, data_stream: DataStream, 
fields: List[str] = None) ->
                        of the Table
         :return: The converted Table.
         """
-        if fields is not None:
-            j_table = self._j_tenv.fromDataStream(data_stream._j_data_stream, 
fields)
-        else:
+        j_table = None
+        if len(fields) == 0:
             j_table = self._j_tenv.fromDataStream(data_stream._j_data_stream)
-        return Table(j_table=j_table, t_env=self._j_tenv)
+        elif len(fields) == 1 and isinstance(fields[0], str):
+            j_table = self._j_tenv.fromDataStream(data_stream._j_data_stream, 
fields[0])
+        elif len(fields) > 0 and \
+                [isinstance(f, Expression) for f in fields] == [True] * 
len(fields):

Review comment:
       what about `all(isinstance(f, Expression) for f in fields)`

##########
File path: flink-python/pyflink/table/table_environment.py
##########
@@ -1770,11 +1771,19 @@ def from_data_stream(self, data_stream: DataStream, 
fields: List[str] = None) ->
                        of the Table
         :return: The converted Table.
         """
-        if fields is not None:
-            j_table = self._j_tenv.fromDataStream(data_stream._j_data_stream, 
fields)
-        else:
+        j_table = None
+        if len(fields) == 0:
             j_table = self._j_tenv.fromDataStream(data_stream._j_data_stream)
-        return Table(j_table=j_table, t_env=self._j_tenv)
+        elif len(fields) == 1 and isinstance(fields[0], str):
+            j_table = self._j_tenv.fromDataStream(data_stream._j_data_stream, 
fields[0])
+        elif len(fields) > 0 and \
+                [isinstance(f, Expression) for f in fields] == [True] * 
len(fields):
+            gateway = get_gateway()
+            j_table = self._j_tenv.fromDataStream(data_stream._j_data_stream,
+                                                  
to_jarray(gateway.jvm.Expression,

Review comment:
       can use to_expression_jarray

##########
File path: flink-python/pyflink/table/table_environment.py
##########
@@ -1770,11 +1771,19 @@ def from_data_stream(self, data_stream: DataStream, 
fields: List[str] = None) ->
                        of the Table
         :return: The converted Table.
         """
-        if fields is not None:
-            j_table = self._j_tenv.fromDataStream(data_stream._j_data_stream, 
fields)
-        else:
+        j_table = None
+        if len(fields) == 0:
             j_table = self._j_tenv.fromDataStream(data_stream._j_data_stream)
-        return Table(j_table=j_table, t_env=self._j_tenv)
+        elif len(fields) == 1 and isinstance(fields[0], str):
+            j_table = self._j_tenv.fromDataStream(data_stream._j_data_stream, 
fields[0])
+        elif len(fields) > 0 and \
+                [isinstance(f, Expression) for f in fields] == [True] * 
len(fields):
+            gateway = get_gateway()
+            j_table = self._j_tenv.fromDataStream(data_stream._j_data_stream,
+                                                  
to_jarray(gateway.jvm.Expression,
+                                                            
[_get_java_expression(f)
+                                                             for f in fields]))
+        return None if j_table is None else Table(j_table=j_table, t_env=self)

Review comment:
       I agree with @HuangXingBo, could refer to Table.select as an example.




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

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


Reply via email to