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

Add support for SHOW CREATE SCHEMA #24356

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

agrawalreetika
Copy link
Member

@agrawalreetika agrawalreetika commented Jan 13, 2025

Description

Add support for SHOW CREATE SCHEMA

  • Add SQL Support for SHOW CREATE SCHEMA
  • Add support for SHOW CREATE SCHEMA in hive & iceberg connector

Motivation and Context

There was no way to check schema properties. So this SQL support will provide a way to check properties like location for schema

Impact

SQL support for SHOW CREATE SCHEMA from a schema :

presto> SHOW CREATE SCHEMA hive.sf1;
                  Create Schema
    -----------------------------------------
     CREATE SCHEMA hive.sf1
     WITH (
        location = 'hdfs://localhost:9000/user/hive/warehouse/sf1.db'
     )
    (1 row)

Test Plan

Contributor checklist

  • Please make sure your submission complies with our contributing guide, in particular code style and commit standards.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.

Release Notes

Please follow release notes guidelines and fill in the release notes below.

== RELEASE NOTES ==

General Changes
* Add DDL SQL support for ``SHOW CREATE SCHEMA``. :pr:`24356`

@agrawalreetika agrawalreetika self-assigned this Jan 13, 2025
@prestodb-ci prestodb-ci added the from:IBM PR from IBM label Jan 13, 2025
@prestodb-ci prestodb-ci requested review from a team, bibith4 and ShahimSharafudeen and removed request for a team January 13, 2025 19:57
Copy link

github-actions bot commented Jan 13, 2025

Codenotify: Notifying subscribers in CODENOTIFY files for diff b511e7a...dd9494c.

Notify File(s)
@aditi-pandit presto-parser/src/main/antlr4/com/facebook/presto/sql/parser/SqlBase.g4
@elharo presto-parser/src/main/antlr4/com/facebook/presto/sql/parser/SqlBase.g4
@kaikalur presto-parser/src/main/antlr4/com/facebook/presto/sql/parser/SqlBase.g4
@rschlussel presto-parser/src/main/antlr4/com/facebook/presto/sql/parser/SqlBase.g4

steveburnett
steveburnett previously approved these changes Jan 13, 2025
Copy link
Contributor

@steveburnett steveburnett left a comment

Choose a reason for hiding this comment

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

Thanks! Pull branch, local doc build, everything looks good.

@steveburnett
Copy link
Contributor

Thanks for the release note! A couple of nits.

== RELEASE NOTES ==

General Changes
* Add DDL SQL support for ``SHOW CREATE SCHEMA``. :pr:`24356`

Copy link
Contributor

@ZacBlanco ZacBlanco left a comment

Choose a reason for hiding this comment

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

one minor nit. Otherwise, could we add some negative tests for the case a user specifies only a catalog or a table directly and verify that the query fails?

}

Map<String, Object> properties = metadata.getSchemaProperties(session, catalogSchemaName);
Map<String, PropertyMetadata<?>> allTableProperties = metadata.getSchemaPropertyManager().getAllProperties().get(getConnectorIdOrThrow(session, metadata, catalogSchemaName.getCatalogName()));
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: allSchemaProperties?

Copy link
Member

@hantangwangd hantangwangd left a comment

Choose a reason for hiding this comment

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

Thanks for this change. One little problem and one point for discussing, otherwise looks good to me.

Comment on lines +588 to +602
if (node.getType() == SCHEMA) {
CatalogSchemaName catalogSchemaName = createCatalogSchemaName(session, node, Optional.of(node.getName()));
if (!metadataResolver.schemaExists(catalogSchemaName)) {
throw new SemanticException(MISSING_SCHEMA, node, "Schema '%s' does not exist", catalogSchemaName);
}

Map<String, Object> properties = metadata.getSchemaProperties(session, catalogSchemaName);
Map<String, PropertyMetadata<?>> allSchemaProperties = metadata.getSchemaPropertyManager().getAllProperties().get(getConnectorIdOrThrow(session, metadata, catalogSchemaName.getCatalogName()));
List<Property> propertyNodes = buildProperties(objectName, Optional.empty(), INVALID_SCHEMA_PROPERTY, properties, allSchemaProperties);
CreateSchema createSchema = new CreateSchema(
node.getName(),
false,
propertyNodes);
return singleValueQuery("Create Schema", formatSql(createSchema, Optional.of(parameters)).trim());
}
Copy link
Member

Choose a reason for hiding this comment

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

Is it better to put this code at the beginning of the method? As far as I can see, createQualifiedObjectName(session, node, node.getName()) will fail when we just provide catalogname.schemaname in a session which do not set default catalog and schema. So, if we connector the database without set a default schema, then executing the following statements:

show create schema hive.default;

We will fail with the following message: Catalog must be specified when session catalog is not set.

Moreover, when executing show create schema, there is no need to execute getView(...) and getMaterializedView(...) firstly.

Comment on lines +44 to +50

public static Map<String, Object> getDatabaseProperties(Database database)
{
ImmutableMap.Builder<String, Object> result = ImmutableMap.builder();
database.getLocation().ifPresent(location -> result.put(LOCATION_PROPERTY, location));
return result.build();
}
Copy link
Member

Choose a reason for hiding this comment

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

Do you think it makes sense to move this class to presto-hive-metastore? Seems it's more like a concept of HMS.

Copy link
Member Author

@agrawalreetika agrawalreetika Jan 20, 2025

Choose a reason for hiding this comment

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

I think that's a good idea. Let me refactor it in different PR and then I can rebase this one
#24401

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
from:IBM PR from IBM
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants