Skip to content
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

[task #8917] Implement information_schema.schemata #8993

Merged
merged 1 commit into from
Jan 28, 2024

Conversation

Tangruilin
Copy link
Contributor

Which issue does this PR close?

Closes #8917 .

Rationale for this change

What changes are included in this PR?

There are some in infomation_schema.rs

Are these changes tested?

Yes

Are there any user-facing changes?

There will be a new table named schemata, users can select * from information_schema.schemata; to get info in it

@github-actions github-actions bot added the core Core DataFusion crate label Jan 25, 2024
@Tangruilin
Copy link
Contributor Author

The datafusion_cli test
image

@Tangruilin
Copy link
Contributor Author

@JanKaul
Hey! this is the draft, you can review this PR.
The column default_character_set_catalog default_character_set_schema default_character_set_name and sql_path Applies to a feature not available refer to https://www.postgresql.org/docs/current/infoschema-schemata.html. Maybe you can give some suggestion if we need to have them. Now they are null

@Tangruilin Tangruilin force-pushed the task#8917 branch 2 times, most recently from 0d3a573 to 6785b69 Compare January 25, 2024 11:35
@github-actions github-actions bot added the sqllogictest SQL Logic Tests (.slt) label Jan 25, 2024
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Tangruilin

I think CI is failing due to the changes in datafusion/sqllogictest/test_files/aggregates_topk.slt

Which is due to #8845

Copy link
Contributor

@JanKaul JanKaul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! Thanks for the effort.

If I understand correctly the default_character_set_catalog, default_character_set_schema, default_character_set_name, sql_path columns are not required. So null is okay.

Comment on lines 137 to 143
let schema_owner = match std::env::var("USER") {
Ok(user) => user,
Err(_) => match std::env::var("USERNAME") {
Ok(user) => user,
Err(_) => "".to_owned(),
},
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really sure about using the environment variables for the schema owner. I guess datafusion doesn't really have the concept of an user and therefore an owner. However, this is a required column and should somehow have a value. Similar to the default catalog we could use "datafusion" here.

@alamb what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I get the System User from environment variables, which is same as postgresql.

Maybe you will have some good suggestions? It seems that datafusion do not have a user

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree pulling from the environment is not consistent with how the rest of DataFusion works. I think the owner should come from the SchemaProvider

However there is no notion of owner on SchemaProvider now

Thus, I suggest either:

  1. Leaving owner NULL for now
  2. Add a function to the SchemaProvider to optionally provide a an owner

For example

trait SchemaProvider {
  // return the "schema owner" of known,  reported in `information_schema.schemata`
  // Returns `None` by default
  fn owner_name(&self) -> Option<&str> {
    None
  }

}

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Tangruilin and @JanKaul -- would it be possible to add a test that actually selects values from information_schema.schemata in datafusion/sqllogictest/test_files/information_schema.slt (to test the values)?

Comment on lines 137 to 143
let schema_owner = match std::env::var("USER") {
Ok(user) => user,
Err(_) => match std::env::var("USERNAME") {
Ok(user) => user,
Err(_) => "".to_owned(),
},
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree pulling from the environment is not consistent with how the rest of DataFusion works. I think the owner should come from the SchemaProvider

However there is no notion of owner on SchemaProvider now

Thus, I suggest either:

  1. Leaving owner NULL for now
  2. Add a function to the SchemaProvider to optionally provide a an owner

For example

trait SchemaProvider {
  // return the "schema owner" of known,  reported in `information_schema.schemata`
  // Returns `None` by default
  fn owner_name(&self) -> Option<&str> {
    None
  }

}

@Tangruilin
Copy link
Contributor Author

Thanks @Tangruilin and @JanKaul -- would it be possible to add a test that actually selects values from information_schema.schemata in datafusion/sqllogictest/test_files/information_schema.slt (to test the values)?

I will try this

@alamb
Copy link
Contributor

alamb commented Jan 27, 2024

How is this PR going? I think it just needs

  1. Remove the use of environment variables
  2. A query test (in information_schema.slt)

@Tangruilin
Copy link
Contributor Author

How is this PR going? I think it just needs

  1. Remove the use of environment variables
  2. A query test (in information_schema.slt)

I will submit a new PR later or tomorrow

@Tangruilin
Copy link
Contributor Author

How is this PR going? I think it just needs

  1. Remove the use of environment variables
  2. A query test (in information_schema.slt)

I have done that ~~~

Copy link
Contributor

@JanKaul JanKaul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thank you for working on it.

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me -- thank you @Tangruilin and @JanKaul -- I had some small comment suggestions but I don't think they are needed to merge this PR (they can be done as a follow on PR or never)

Thanks again!

@@ -34,6 +34,11 @@ use crate::error::{DataFusionError, Result};
/// [`CatalogProvider`]: super::CatalogProvider
#[async_trait]
pub trait SchemaProvider: Sync + Send {
/// Returns the owner of the Schema, default is None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Returns the owner of the Schema, default is None
/// Returns the owner of the Schema, default is None. This value is reported
/// as part of `information_tables.schemata`

Some(owner) => self.schema_owner.append_value(owner),
None => self.schema_owner.append_null(),
}
// refer to https://www.postgresql.org/docs/current/infoschema-schemata.html, these rows are Applies to a feature not available
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// refer to https://www.postgresql.org/docs/current/infoschema-schemata.html, these rows are Applies to a feature not available
// refer to https://www.postgresql.org/docs/current/infoschema-schemata.html,
// these rows apply to a feature that is not implemented in DataFusion

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can merge it, and i will submit a PR tomorrow to fix these.

Now it is 12:30 here, i may sleep, so sorry ~~~

@alamb
Copy link
Contributor

alamb commented Jan 27, 2024

Now it is 12:30 here, i may sleep, so sorry ~~~

Yes, no worries, go to 💤 !! We can wait until tomorrow there is no need for you to lose sleep or to rush in the PR

It is part of being a distributed community

Signed-off-by: tangruilin <tang.ruilin@foxmail.com>
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again @Tangruilin ❤️

@alamb alamb merged commit a668abf into apache:main Jan 28, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core DataFusion crate sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement information_schema.schemata
3 participants