Skip to content

Commit 2f91bcf

Browse files
PySpark Reg Test Updates (apache#1262) (apache#29)
* PySpark Reg Test Updates * Nits --------- Co-authored-by: Travis Bowen <122238243+travis-bowen@users.noreply.github.com>
1 parent 03714b7 commit 2f91bcf

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

regtests/t_pyspark/src/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ def aws_bucket_base_location_prefix():
8484
"""
8585
default_val = 'polaris_test'
8686
bucket_prefix = os.getenv('AWS_BUCKET_BASE_LOCATION_PREFIX', default_val)
87-
return default_val if bucket_prefix == '' else bucket_prefix
87+
# Add random string to prefix to prevent base location overlaps
88+
return f"{default_val if bucket_prefix == '' else bucket_prefix}_{str(uuid.uuid4())[:5]}"
8889

8990
@pytest.fixture
9091
def catalog_client(polaris_catalog_url):

regtests/t_pyspark/src/test_spark_sql_s3_with_privileges.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ def test_spark_credentials(root_client, snowflake_catalog, polaris_catalog_url,
293293
polaris_url=polaris_catalog_url) as spark:
294294
spark.sql(f'USE {snowflake_catalog.name}')
295295
spark.sql('USE db1.schema')
296-
spark.sql('DROP TABLE iceberg_table')
296+
spark.sql('DROP TABLE iceberg_table PURGE')
297297
spark.sql(f'USE {snowflake_catalog.name}')
298298
spark.sql('DROP NAMESPACE db1.schema')
299299
spark.sql('DROP NAMESPACE db1')
@@ -359,6 +359,14 @@ def test_spark_creates_table_in_custom_namespace_dir(root_client, snowflake_cata
359359
entries = spark.sql(
360360
f"SELECT file FROM db1.schema.table_in_custom_namespace_location.metadata_log_entries").collect()
361361
assert namespace_location in entries[0][0]
362+
try:
363+
assert spark.sql("SELECT * FROM table_in_custom_namespace_location").count() == 0
364+
# check the metadata and assert the custom namespace location is used
365+
entries = spark.sql(
366+
f"SELECT file FROM db1.schema.table_in_custom_namespace_location.metadata_log_entries").collect()
367+
assert namespace_location in entries[0][0]
368+
finally:
369+
spark.sql('DROP TABLE table_in_custom_namespace_location PURGE')
362370

363371

364372
@pytest.mark.skipif(os.environ.get('AWS_TEST_ENABLED', 'False').lower() != 'true',
@@ -388,6 +396,7 @@ def test_spark_can_create_table_in_custom_allowed_dir(root_client, snowflake_cat
388396
spark.sql('USE db1.schema')
389397
# this is supported because it is inside of the custom namespace location
390398
spark.sql(f"CREATE TABLE iceberg_table_outside_namespace (col1 int, col2 string) LOCATION '{table_location}'")
399+
spark.sql("drop table iceberg_table_outside_namespace PURGE")
391400

392401

393402
@pytest.mark.skipif(os.environ.get('AWS_TEST_ENABLED', 'False').lower() != 'true',
@@ -421,6 +430,7 @@ def test_spark_cannot_create_view_overlapping_table(root_client, snowflake_catal
421430
pytest.fail("Expected to fail when creating table outside of namespace directory")
422431
except Py4JJavaError as e:
423432
assert "conflicts with existing table or namespace at location" in e.java_exception.getMessage()
433+
spark.sql("drop table my_iceberg_table PURGE")
424434

425435

426436
@pytest.mark.skipif(os.environ.get('AWS_TEST_ENABLED', 'False').lower() != 'true',
@@ -789,6 +799,7 @@ def test_spark_credentials_can_create_views(snowflake_catalog, polaris_catalog_u
789799
view_records = spark.sql(f"SELECT * FROM {table_name}_view").collect()
790800
assert len(view_records) == 6
791801
assert view_records[5][0] == 'changed string'
802+
spark.sql(f"drop table {table_name} PURGE")
792803

793804

794805
@pytest.mark.skipif(os.environ.get('AWS_TEST_ENABLED', 'False').lower() != 'true',
@@ -876,8 +887,8 @@ def test_spark_credentials_s3_direct_with_write(root_client, snowflake_catalog,
876887
polaris_url=polaris_catalog_url) as spark:
877888
spark.sql(f'USE {snowflake_catalog.name}')
878889
spark.sql('USE db1.schema')
879-
spark.sql('DROP TABLE iceberg_table')
880-
spark.sql('DROP TABLE iceberg_table_2')
890+
spark.sql('DROP TABLE iceberg_table PURGE')
891+
spark.sql('DROP TABLE iceberg_table_2 PURGE')
881892
spark.sql(f'USE {snowflake_catalog.name}')
882893
spark.sql('DROP NAMESPACE db1.schema')
883894
spark.sql('DROP NAMESPACE db1')
@@ -1134,6 +1145,8 @@ def test_spark_ctas(snowflake_catalog, polaris_catalog_url, snowman):
11341145

11351146
# Run CTAS
11361147
spark.sql(f"CREATE TABLE {table_name}_t2 AS SELECT * FROM {table_name}_t1")
1148+
spark.sql(f"drop table {table_name}_t1 PURGE")
1149+
spark.sql(f"drop table {table_name}_t2 PURGE")
11371150

11381151

11391152
def create_catalog_role(api, catalog, role_name):

0 commit comments

Comments
 (0)