|
15 | 15 | # See the License for the specific language governing permissions and |
16 | 16 | # limitations under the License. |
17 | 17 | ################################################################################ |
18 | | - |
19 | | -import os |
20 | | -import shutil |
21 | | -import subprocess |
22 | | -import tempfile |
23 | | -import unittest |
24 | | -import urllib.request |
25 | | - |
26 | | -from pypaimon.py4j import constants, Catalog |
27 | | -from xml.etree import ElementTree |
28 | | - |
29 | | - |
30 | | -def _setup_hadoop_bundle_jar(hadoop_dir): |
31 | | - url = 'https://repo.maven.apache.org/maven2/org/apache/flink/' \ |
32 | | - 'flink-shaded-hadoop-2-uber/2.8.3-10.0/flink-shaded-hadoop-2-uber-2.8.3-10.0.jar' |
33 | | - |
34 | | - response = urllib.request.urlopen(url) |
35 | | - if not os.path.exists(hadoop_dir): |
36 | | - os.mkdir(hadoop_dir) |
37 | | - |
38 | | - jar_path = os.path.join(hadoop_dir, "bundled-hadoop.jar") |
39 | | - with open(jar_path, 'wb') as file: |
40 | | - file.write(response.read()) |
41 | | - |
42 | | - os.environ[constants.PYPAIMON_HADOOP_CLASSPATH] = jar_path |
43 | | - |
44 | | - |
45 | | -def _setup_bridge_jar(bridge_dir): |
46 | | - java_bridge_module = _find_java_bridge_module() |
47 | | - subprocess.run( |
48 | | - ["mvn", "clean", "package"], |
49 | | - cwd=java_bridge_module, |
50 | | - stdout=subprocess.PIPE, |
51 | | - stderr=subprocess.PIPE |
52 | | - ) |
53 | | - |
54 | | - if not os.path.exists(bridge_dir): |
55 | | - os.mkdir(bridge_dir) |
56 | | - |
57 | | - jar_path = os.path.join(bridge_dir, "paimon-python-java-bridge.jar") |
58 | | - shutil.copy( |
59 | | - os.path.join(java_bridge_module, 'target/{}-{}.jar' |
60 | | - .format('paimon-python-java-bridge', _extract_bridge_version())), |
61 | | - jar_path |
62 | | - ) |
63 | | - |
64 | | - os.environ[constants.PYPAIMON_JAVA_CLASSPATH] = jar_path |
65 | | - |
66 | | - |
67 | | -def _extract_bridge_version(): |
68 | | - pom_path = os.path.join(_find_java_bridge_module(), 'pom.xml') |
69 | | - return ElementTree.parse(pom_path).getroot().find( |
70 | | - 'POM:version', |
71 | | - namespaces={ |
72 | | - 'POM': 'http://maven.apache.org/POM/4.0.0' |
73 | | - }).text |
74 | | - |
75 | | - |
76 | | -def _find_java_bridge_module(): |
77 | | - this_dir = os.path.abspath(os.path.dirname(__file__)) |
78 | | - project_dir = os.path.dirname(os.path.dirname(os.path.dirname(this_dir))) |
79 | | - return os.path.join(project_dir, "paimon-python-java-bridge") |
80 | | - |
81 | | - |
82 | | - |
0 commit comments