|
1 | 1 | from pathlib import PurePosixPath |
2 | | - |
3 | 2 | from exasol_bucketfs_utils_python.bucket_config import BucketConfig |
4 | 3 | from exasol_bucketfs_utils_python.bucketfs_config import BucketFSConfig |
5 | 4 | from exasol_bucketfs_utils_python.bucketfs_connection_config import BucketFSConnectionConfig |
6 | | - |
7 | 5 | from exasol_bucketfs_utils_python.bucketfs_location import BucketFSLocation |
8 | 6 | import pytest |
9 | 7 | import textwrap |
10 | | -from tests.test_load_fs_file_from_udf import delete_testfile_from_bucketfs, upload_testfile_to_bucketfs |
| 8 | +from tests.integration_tests.with_db.test_load_fs_file_from_udf import delete_testfile_from_bucketfs, upload_testfile_to_bucketfs |
11 | 9 | # TODO replace upload_testfile_to_BucketFS once missing funcs in BucketFSLocation are implemented |
12 | 10 |
|
13 | 11 |
|
14 | | -def test_upload_download_string_from_different_instance(): |
15 | | - connection_config = BucketFSConnectionConfig(host="localhost", port=6666, user="w", pwd="write", is_https=False) |
16 | | - bucketfs_config = BucketFSConfig("bfsdefault", connection_config=connection_config) |
17 | | - bucket_config = BucketConfig(bucket_name="default", bucketfs_config=bucketfs_config) |
18 | | - bucket_base_path = PurePosixPath("test_up_down_str") |
19 | | - bucketfs_location_upload = BucketFSLocation(bucket_config, bucket_base_path) |
20 | | - bucketfs_location_download = BucketFSLocation(bucket_config, bucket_base_path) |
21 | | - bucket_file_path = "test_file.txt" |
22 | | - test_string = "test_string" |
23 | | - bucketfs_location_upload.upload_string_to_bucketfs(bucket_file_path, test_string) |
24 | | - result = bucketfs_location_download.download_from_bucketfs_to_string(bucket_file_path) |
25 | | - assert result == test_string |
26 | | - delete_testfile_from_bucketfs(file_path=str(bucket_base_path) + "/" + bucket_file_path, |
27 | | - bucket_config=bucketfs_location_upload.bucket_config) |
28 | | - |
29 | | - |
30 | | -class TestValue: |
31 | | - __test__ = False |
32 | | - |
33 | | - def __init__(self, value: str): |
34 | | - self.value = value |
35 | 12 |
|
36 | | - def __eq__(self, other): |
37 | | - return self.value == self.value |
| 13 | +def test_generate_bucket_udf_path_with_db( |
| 14 | + upload_language_container, pyexasol_connection): |
38 | 15 |
|
| 16 | + connection_config = BucketFSConnectionConfig( |
| 17 | + host="localhost", port=6666, user="w", pwd="write", is_https=False) |
| 18 | + bucketfs_config = BucketFSConfig( |
| 19 | + connection_config=connection_config, bucketfs_name="bfsdefault") |
| 20 | + bucket_config = BucketConfig( |
| 21 | + bucket_name="default", bucketfs_config=bucketfs_config) |
| 22 | + bucketfs_location = BucketFSLocation(bucket_config, "") |
39 | 23 |
|
40 | | -def test_upload_download_obj_from_different_instance(): |
41 | | - connection_config = BucketFSConnectionConfig(host="localhost", port=6666, user="w", pwd="write", is_https=False) |
42 | | - bucketfs_config = BucketFSConfig("bfsdefault", connection_config=connection_config) |
43 | | - bucket_config = BucketConfig(bucket_name="default", bucketfs_config=bucketfs_config) |
44 | | - bucket_base_path = PurePosixPath("test_up_down_obj") |
45 | | - bucketfs_location_upload = BucketFSLocation(bucket_config, bucket_base_path) |
46 | | - bucketfs_location_download = BucketFSLocation(bucket_config, bucket_base_path) |
47 | 24 | bucket_file_path = "test_file.txt" |
48 | | - test_value = TestValue("test_string") |
49 | | - bucketfs_location_upload.upload_object_to_bucketfs_via_joblib(test_value, bucket_file_path) |
50 | | - result = bucketfs_location_download.download_object_from_bucketfs_via_joblib(bucket_file_path) |
51 | | - assert result == test_value |
52 | | - delete_testfile_from_bucketfs(file_path=str(bucket_base_path) + "/" + bucket_file_path, |
53 | | - bucket_config=bucketfs_location_upload.bucket_config) |
| 25 | + test_string = "test_string" |
| 26 | + bucketfs_location.upload_string_to_bucketfs(bucket_file_path, test_string) |
| 27 | + |
| 28 | + target_schema = "TARGET_SCHEMA" |
| 29 | + try: |
| 30 | + # access file from udf |
| 31 | + udf_name = "AccessFileInBucketFSFromUDF" |
| 32 | + pyexasol_connection.execute( |
| 33 | + f"CREATE SCHEMA IF NOT EXISTS {target_schema};") |
| 34 | + pyexasol_connection.execute( |
| 35 | + f"OPEN SCHEMA {target_schema};") |
| 36 | + udf_sql = textwrap.dedent(f""" |
| 37 | + CREATE OR REPLACE PYTHON3_BFSUP SET SCRIPT {target_schema}."{udf_name}"( |
| 38 | + "path_in_bucket" VARCHAR(20000)) |
| 39 | + RETURNS BOOLEAN |
| 40 | + AS |
| 41 | + from exasol_bucketfs_utils_python.bucket_config import BucketConfig |
| 42 | + from exasol_bucketfs_utils_python.bucketfs_connection_config import BucketFSConnectionConfig |
| 43 | + from exasol_bucketfs_utils_python.bucketfs_config import BucketFSConfig |
| 44 | + from exasol_bucketfs_utils_python.bucketfs_location import BucketFSLocation |
| 45 | + from pathlib import PurePosixPath, Path |
| 46 | + |
| 47 | + bucket_name = "default" |
| 48 | + bucketfs_name = "bfsdefault" |
| 49 | + def get_bucket_config(): |
| 50 | + connection_config = BucketFSConnectionConfig(host="localhost", |
| 51 | + port=6666, |
| 52 | + user="r", pwd="read", |
| 53 | + is_https=False) |
| 54 | + bucketfs_config = BucketFSConfig(bucketfs_name, connection_config=connection_config) |
| 55 | + return BucketConfig(bucket_name, bucketfs_config) |
| 56 | + |
| 57 | + def run(ctx): |
| 58 | + path_in_bucket = ctx.path_in_bucket |
| 59 | + bucket_config = get_bucket_config() |
| 60 | + bucketfs_location = BucketFSLocation(bucket_config, "") |
| 61 | + file_path = bucketfs_location.generate_bucket_udf_path(path_in_bucket) |
| 62 | + |
| 63 | + return Path(file_path).exists() |
| 64 | + """) |
| 65 | + pyexasol_connection.execute(udf_sql) |
| 66 | + result = pyexasol_connection.execute( |
| 67 | + f"""select {target_schema}."{udf_name}"('{bucket_file_path}')""").fetchall() |
| 68 | + print(result) |
| 69 | + assert result[0][0] |
| 70 | + finally: |
| 71 | + delete_testfile_from_bucketfs(file_path=bucket_file_path, |
| 72 | + bucket_config=bucketfs_location.bucket_config) |
| 73 | + pyexasol_connection.execute(f"DROP SCHEMA IF EXISTS {target_schema} CASCADE;") |
54 | 74 |
|
55 | 75 |
|
56 | 76 | @pytest.mark.usefixtures("upload_language_container", |
@@ -228,6 +248,7 @@ def run(ctx): |
228 | 248 | bucket_config=bucketfs_location_read.bucket_config) |
229 | 249 | pyexasol_connection.execute(f"DROP SCHEMA IF EXISTS {target_schema} CASCADE;") |
230 | 250 |
|
| 251 | + |
231 | 252 | def test_read_files_to_fileobj_from_bucketfs_inside_udf(upload_language_container, pyexasol_connection): |
232 | 253 | connection_config = BucketFSConnectionConfig(host="localhost", port=6666, user="w", pwd="write", is_https=False) |
233 | 254 | bucketfs_config = BucketFSConfig("bfsdefault", connection_config=connection_config) |
|
0 commit comments