-
Greetings! Can anyone give me an example of how should I use the
If this expression is not appropriate, how could I assert a FK constraint? Thanks in advance!! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Data Prepfrom cuallee import Check, CheckLevel
from pyspark.sql import SparkSession, Row, DataFrame
spark = SparkSession.builder.getOrCreate()
data = [
Row(country="Brazil", color="green", population=214e6),
Row(country="Mexico", color="white", population=126e6),
Row(country="China", color="red", population=1.4e9),
]
df = spark.createDataFrame(data)
df.show(truncate=False) DataFrame
Checkcheck = Check(CheckLevel.WARNING, "Satisfies")
check.satisfies("color", "(color like 'green') AND (population > 2000000)")
check.validate(df).show() Result
Only one row matches the predicate of About FKI personally haven't thought about the use of data2 = [
Row(country="Brazil", continent="America"),
Row(country="Slovenia", continent="Europe"),
]
df2 = spark.createDataFrame(data2)
df2.show() Second Dataframe
FK Checkcheck = Check(CheckLevel.ERROR, "ForeignKey")
check.is_complete("continent")
check.validate(df.join(df2, "country", how="left")).show() Final Result
As you can see, there is only one row that matches the integrity predicate. Hope it helps @FShinoda . Success! |
Beta Was this translation helpful? Give feedback.
-
Could a foreign key validation be created? Something like a has_fk? Does it make sense to add this to the project? @canimus |
Beta Was this translation helpful? Give feedback.
-
Hi @maltzsama considering a |
Beta Was this translation helpful? Give feedback.
Data Prep
DataFrame
Check