from __future__ import annotations
import uuid
def test_schema_qualified_table_resolution(spark) -> None:
schema = "test_schema_resolution"
table = f"test_table_{uuid.uuid4().hex[:8]}"
spark.sql(f"DROP SCHEMA IF EXISTS {schema} CASCADE")
spark.sql(f"CREATE SCHEMA IF NOT EXISTS {schema}")
data = [{"id": 1, "name": "a"}]
df = spark.createDataFrame(data, ["id", "name"])
df.write.mode("overwrite").saveAsTable(f"{schema}.{table}")
result = spark.table(f"{schema}.{table}")
assert result.count() == 1
row = result.collect()[0]
assert row["id"] == 1
assert row["name"] == "a"
def test_schema_qualified_table_append_then_read(spark) -> None:
schema = "test_schema_append"
table = f"test_table_{uuid.uuid4().hex[:8]}"
spark.sql(f"DROP SCHEMA IF EXISTS {schema} CASCADE")
spark.sql(f"CREATE SCHEMA IF NOT EXISTS {schema}")
df1 = spark.createDataFrame([{"id": 1, "name": "x"}], ["id", "name"])
df1.write.mode("overwrite").saveAsTable(f"{schema}.{table}")
df2 = spark.createDataFrame([{"id": 2, "name": "y"}], ["id", "name"])
df2.write.mode("append").saveAsTable(f"{schema}.{table}")
result = spark.table(f"{schema}.{table}")
assert result.count() == 2