-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DDL for Table Constraints #20384
DDL for Table Constraints #20384
Conversation
60e835c
to
5e11c18
Compare
9791f60
to
2b6e3a7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few random comments. Main question was about the grammar for the constraint specification.
presto-parser/src/main/antlr4/com/facebook/presto/sql/parser/SqlBase.g4
Outdated
Show resolved
Hide resolved
presto-spi/src/main/java/com/facebook/presto/spi/constraints/TableConstraint.java
Outdated
Show resolved
Hide resolved
presto-spi/src/main/java/com/facebook/presto/spi/connector/ConnectorMetadata.java
Outdated
Show resolved
Hide resolved
presto-parser/src/main/java/com/facebook/presto/sql/tree/AddConstraint.java
Show resolved
Hide resolved
presto-spi/src/main/java/com/facebook/presto/spi/constraints/TableConstraint.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM overall, still taking a look at some tests/other nits.
A thought I had - IMO this may be a good time to define table constraints for the TPCH and TPCDS tables, so that we can have another sample implementation that dev's can examine and play around with.
This would be very helpful to see the impact of adding constraints to plan shapes
@@ -30,6 +30,7 @@ | |||
import com.facebook.presto.spi.PrestoException; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a unit test similar to testCreateWithNotNullColumns
that asserts that adding a new table constraint get's reflected in the ConnectorTableMetadata for supported connectors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also include some negative tests
- Multiple PRIMARY KEYs
- Duplicate UNIQUE keys for the same named/unnamed constraint
These will be parsed by the parser, but since these are semantically incorrect, we should fail them in the CreateTableTask
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have left almost all semantic checking to the connector(s) or catalog service. It is impossible to detect all cases of semantic errors and different systems have their own rules for handling these. E.g. some systems require a globally unique name for primary keys, while others do not.
It may be possible to catch some of the common, universal errors early and return, but I'm not sure whether that is worth it. I could be convinced otherwise
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should have at least the logically impossible cases (such as multiple PKs) covered in presto-main. For others, lets pick a connector (say HMS) and put some negative tests there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added some additional error checks here that basically validate whether the create table statement is internally consistent. I am reluctant to make these more exhaustive since they would include additional overhead of communicating with the remote catalog
presto-parser/src/test/java/com/facebook/presto/sql/parser/TestSqlParser.java
Outdated
Show resolved
Hide resolved
presto-parser/src/main/java/com/facebook/presto/sql/tree/CreateTable.java
Outdated
Show resolved
Hide resolved
2b6e3a7
to
cfdc2b5
Compare
7549c29
to
babfdee
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! (docs)
040e860
to
e329df2
Compare
Codenotify: Notifying subscribers in CODENOTIFY files for diff dccb5a4...1860a8d.
|
Added - thanks for catching this |
6408333
to
20558f0
Compare
Suggested revision of release note entry based on my possibly incomplete understanding of this PR and the release note guidelines:
Let me know if this accurately describes your work here! Also and unrelated: pulled branch today and made a new local build to recheck the docs, everything looks good. Thanks for the doc! |
@tdcmeehan - Any other feedback? |
LGTM. Any final thoughts @mlyublena @feilong-liu ? |
20558f0
to
be89267
Compare
be89267
presto-parser/src/main/antlr4/com/facebook/presto/sql/parser/SqlBase.g4
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! (docs)
Pull updated branch, new local build, everything looks good. Thanks for the doc!
Impose ordering on table columns in constraint to conform with Hive spec
Supported in the Hive connector for Hive/HMS version >= 2.1.0 ALTER TABLE DROP CONSTRAINT constraint_name
Supported in the Hive connector for Hive/HMS version >= 2.1.0 ALTER TABLE table_name ADD CONSTRAINT constraint_name UNIQUE/PRIMARY KEY (cols...)
Supported in the Hive connector for Hive/HMS version >= 2.1.0 CREATE TABLE table_name (column_definition, ..., CONSTRAINT constraint_name UNIQUE/PRIMAY KEY (column_name, ...), ...)
1860a8d
be89267
to
1860a8d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! (docs)
Pull updated branch, new local build.
Introduces table constraints to Presto (Primary Key and Unique)(#20034). Support for other types of constraints will follow.
This PR Implements
== RELEASE NOTES ==
General Changes
Hive Connector Changes