forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-12311][python] Add base python framework and Add Scan, Project…
…ion, and Filter operator support This closes apache#8267 make travis tests green fix documents, refine shell file name and optimize program logic. Adjust the code examples in python documents to be consistent with scala documents. Refactor flink-python project structure, remove java file from flink-python package. delete unnecessary dependency and plugins.
- Loading branch information
1 parent
4e505c6
commit a09bd4c
Showing
33 changed files
with
1,651 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
flink-core/src/main/java/org/apache/flink/api/python/PythonGatewayServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.api.python; | ||
|
||
import py4j.GatewayServer; | ||
|
||
import java.io.DataOutputStream; | ||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.net.InetAddress; | ||
|
||
/** | ||
* The Py4j Gateway Server provides RPC service for user's python process. | ||
*/ | ||
public class PythonGatewayServer { | ||
|
||
/** | ||
* <p> | ||
* Main method to start a local GatewayServer on a ephemeral port. | ||
* It tells python side via a file. | ||
* | ||
* See: py4j.GatewayServer.main() | ||
* </p> | ||
*/ | ||
public static void main(String[] args) throws IOException { | ||
InetAddress localhost = InetAddress.getLoopbackAddress(); | ||
GatewayServer gatewayServer = new GatewayServer.GatewayServerBuilder() | ||
.javaPort(0) | ||
.javaAddress(localhost) | ||
.build(); | ||
gatewayServer.start(); | ||
|
||
int boundPort = gatewayServer.getListeningPort(); | ||
if (boundPort == -1) { | ||
System.out.println("GatewayServer failed to bind; exiting"); | ||
System.exit(1); | ||
} | ||
|
||
// Tells python side the port of our java rpc server | ||
String handshakeFilePath = System.getenv("_PYFLINK_CONN_INFO_PATH"); | ||
File handshakeFile = new File(handshakeFilePath); | ||
if (handshakeFile.createNewFile()) { | ||
FileOutputStream fileOutputStream = new FileOutputStream(handshakeFile); | ||
DataOutputStream stream = new DataOutputStream(fileOutputStream); | ||
stream.writeInt(boundPort); | ||
stream.close(); | ||
fileOutputStream.close(); | ||
} else { | ||
System.out.println("Can't create handshake file: " + handshakeFilePath + ", now exit..."); | ||
return; | ||
} | ||
|
||
// Exit on EOF or broken pipe. This ensures that the server dies | ||
// if its parent program dies. | ||
while (System.in.read() != -1) { | ||
// Do nothing | ||
} | ||
gatewayServer.shutdown(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
flink-dist/src/main/flink-bin/bin/pyflink-gateway-server.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/env bash | ||
################################################################################ | ||
# 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. | ||
################################################################################ | ||
|
||
# ===================================================================== | ||
bin=`dirname "$0"` | ||
bin=`cd "$bin"; pwd` | ||
|
||
. "$bin"/config.sh | ||
|
||
if [ "$FLINK_IDENT_STRING" = "" ]; then | ||
FLINK_IDENT_STRING="$USER" | ||
fi | ||
|
||
FLINK_CLASSPATH=`constructFlinkClassPath` | ||
|
||
ARGS=() | ||
|
||
while [[ $# -gt 0 ]] | ||
do | ||
key="$1" | ||
case $key in | ||
-c|--class) | ||
DRIVER=$2 | ||
shift | ||
shift | ||
;; | ||
*) | ||
ARGS+=("$1") | ||
shift | ||
;; | ||
esac | ||
done | ||
|
||
log=$FLINK_LOG_DIR/flink-$FLINK_IDENT_STRING-client-$HOSTNAME.log | ||
log_setting=(-Dlog.file="$log" -Dlog4j.configuration=file:"$FLINK_CONF_DIR"/log4j-cli.properties -Dlogback.configurationFile=file:"$FLINK_CONF_DIR"/logback.xml) | ||
|
||
TABLE_JAR_PATH=`echo "$FLINK_ROOT_DIR"/opt/flink-table*.jar` | ||
exec $JAVA_RUN $JVM_ARGS "${log_setting[@]}" -cp ${FLINK_CLASSPATH}:${TABLE_JAR_PATH} ${DRIVER} ${ARGS[@]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
flink-dist/src/main/resources/META-INF/licenses/LICENSE.py4j
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Copyright (c) 2009-2018, Barthelemy Dagenais and individual contributors. All | ||
rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
- Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
- Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
- The name of the author may not be used to endorse or promote products | ||
derived from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Oops, something went wrong.