mustafasrepo commented on code in PR #7040:
URL: https://github.com/apache/arrow-datafusion/pull/7040#discussion_r1270846585
##########
datafusion/core/src/datasource/default_table_source.rs:
##########
@@ -52,6 +54,11 @@ impl TableSource for DefaultTableSource {
self.table_provider.schema()
}
+ /// Get a reference to primary key indices, if a primary key exists.
+ fn primary_keys(&self) -> Option<&[usize]> {
Review Comment:
> Would it be possible to make this API more general? Specifically, there
are several kinds of keys that a table might have so special casing primary key
will make supporting others harder in the future
>
> Single column primary key
>
> ```sql
> create table t (
> x int primary key,
> y int,
> z int)
> ```
>
> Unique (like primary key, but can be null)
>
> ```sql
> create table t (
> x int unique,
> y int,
> z int)
> ```
>
> Multi column primary key
>
> ```sql
> create table t (
> x int,
> y int,
> z int,
> primary key (x, y)
> )
> ```
>
> Foreign key:
>
> ```sql
> create table t (
> x int,
> y int,
> z int,
> foreign key (x) references other_table(a)
> )
> ```
>
> Perhaps we could make it this more general someting like
>
> ```rust
> pub enum Constraints {
> // columns together form a primary key (are unique and not null)
> PrimaryKey(Vec<usize>),
> // columns together form a unique key
> Unique(Vec<usize>),
> // More constraint types to come as we add additional support
> }
> ```
>
> fn constraints(&self) -> Vec { ... }
Thanks @alamb for your feedback. Other than this suggestion, I have
implemented all of your suggestions. With, your suggestions functional
dependencies are now better encapsulated. Most of functionality is moved to the
methods.
`FunctionalDependecies` now has a method `new_from_primary_keys`. All of the
mapping between primary key and functioanal dependency occur, with this method.
Hopefully, when we change this API, changing `new_from_primary_keys` and doing
necessary mapping will be enough. If it is OK with you, I can change this API
in following PRs.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]