Class PrimaryKey
Object
org.apache.spark.sql.connector.catalog.constraints.PrimaryKey
- All Implemented Interfaces:
Constraint
A PRIMARY KEY constraint.
A PRIMARY KEY constraint specifies ore or more columns as a primary key. Such constraint is
satisfied if and only if no two rows in a table have the same non-null values in the primary
key columns and none of the values in the specified column or columns are NULL.
A table can have at most one primary key.
Spark doesn't enforce PRIMARY KEY constraints but leverages them for query optimization. Each
constraint is either valid (the existing data is guaranteed to satisfy the constraint), invalid
(some records violate the constraint), or unvalidated (the validity is unknown). If the validity
is unknown, Spark will check Constraint.rely() to see whether the constraint is believed to be
true and can be used for query optimization.
- Since:
- 4.1.0
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface org.apache.spark.sql.connector.catalog.constraints.Constraint
Constraint.ValidationStatus -
Method Summary
Modifier and TypeMethodDescriptioncolumns()Returns the columns that comprise the primary key.booleanenforced()Indicates whether this constraint is actively enforced.booleaninthashCode()name()Returns the name of this constraint.booleanrely()Indicates whether this constraint is assumed to hold true if the validity is unknown.toDDL()Returns the definition of this constraint in the DDL format.Returns the constraint description for DESCRIBE TABLE output, excluding the constraint name (shown separately).toString()Indicates whether the existing data in the table satisfies this constraint.
-
Method Details
-
columns
Returns the columns that comprise the primary key. -
equals
-
hashCode
public int hashCode() -
name
Description copied from interface:ConstraintReturns the name of this constraint.- Specified by:
namein interfaceConstraint
-
enforced
public boolean enforced()Description copied from interface:ConstraintIndicates whether this constraint is actively enforced. If enforced, data modifications that violate the constraint fail with a constraint violation error.- Specified by:
enforcedin interfaceConstraint
-
validationStatus
Description copied from interface:ConstraintIndicates whether the existing data in the table satisfies this constraint. The constraint can be valid (the data is guaranteed to satisfy the constraint), invalid (some records violate the constraint), or unvalidated (the validity is unknown). The validation status is usually managed by the system and can't be modified by the user.- Specified by:
validationStatusin interfaceConstraint
-
rely
public boolean rely()Description copied from interface:ConstraintIndicates whether this constraint is assumed to hold true if the validity is unknown. Unlike the validation status, this flag is usually provided by the user as a hint to the system.- Specified by:
relyin interfaceConstraint
-
toDDL
Description copied from interface:ConstraintReturns the definition of this constraint in the DDL format.- Specified by:
toDDLin interfaceConstraint
-
toDescription
Description copied from interface:ConstraintReturns the constraint description for DESCRIBE TABLE output, excluding the constraint name (shown separately).- Specified by:
toDescriptionin interfaceConstraint
-
toString
-