Skip to content

Conversation

@bharathv
Copy link
Contributor

This patch adds new SQL grammar like following

  • SHOW SCHEMAS [like '']
  • SHOW TABLES [IN ] [like '<pattern']

Example invocations:

  • show schemas
  • show scemas like 'SYS%'
  • show tables
  • show tables in SYSTEM
  • show tables in SYSTEM like 'CAT%'

The current way of fetching this information is by using
!tables and !schemas via sqlline JDBC support but that is
not flexible enough for the end users to add more fitlers.
This approach is more inline with what other databases do.

Added test coverage in parser tests and core e2e tests.

@bharathv
Copy link
Contributor Author

@vincentpoon FYI.

@yanxinyi
Copy link
Contributor

yanxinyi commented Nov 1, 2019

+1 from my side.

public void testShowTablesMultiTenant() throws Exception {
// Each tenant should only be able list tables corresponding to their TENANT_ID
String tenantId2 = "T_" + generateUniqueName();
String secondTenantConnectionURL = PHOENIX_JDBC_TENANT_SPECIFIC_URL.replace(TENANT_ID, tenantId2);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: more than 100 char per line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

@gjacoby126 gjacoby126 left a comment

Choose a reason for hiding this comment

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

+1. (Sorry for the long wait!) When you get the chance, please rebase and fix the one tiny style nit around while loops.

try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
Set<String> tables = new HashSet<>();
ResultSet rs = conn.prepareStatement("show tables").executeQuery();
while (rs.next()) tables.add(rs.getString("TABLE_NAME"));
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: please put loop body in brackets.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

try (Connection conn = DriverManager.getConnection(secondTenantConnectionURL, props)) {
Set<String> tables = new HashSet<>();
ResultSet rs = conn.prepareStatement("show tables").executeQuery();
while (rs.next()) tables.add(rs.getString("TABLE_NAME"));
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto for loop in brackets

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor Author

@bharathv bharathv left a comment

Choose a reason for hiding this comment

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

Addressed the comments, thanks for taking a look.

public void testShowTablesMultiTenant() throws Exception {
// Each tenant should only be able list tables corresponding to their TENANT_ID
String tenantId2 = "T_" + generateUniqueName();
String secondTenantConnectionURL = PHOENIX_JDBC_TENANT_SPECIFIC_URL.replace(TENANT_ID, tenantId2);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
Set<String> tables = new HashSet<>();
ResultSet rs = conn.prepareStatement("show tables").executeQuery();
while (rs.next()) tables.add(rs.getString("TABLE_NAME"));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

try (Connection conn = DriverManager.getConnection(secondTenantConnectionURL, props)) {
Set<String> tables = new HashSet<>();
ResultSet rs = conn.prepareStatement("show tables").executeQuery();
while (rs.next()) tables.add(rs.getString("TABLE_NAME"));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor Author

@bharathv bharathv left a comment

Choose a reason for hiding this comment

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

Attached a patch to the jira to kick-off a pre-commit build. It looks like it doesn't happen automatically on PRs.

Copy link
Member

@liuml07 liuml07 left a comment

Choose a reason for hiding this comment

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

Nice feature. But I don't have enough context to be +1. Thanks,

}

@Override
public boolean equals(Object other) {
Copy link
Member

Choose a reason for hiding this comment

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

Since you are overriding equals, I would say let's also do the hashCode(). Same to ShowTablesStatement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if thats of much use, but I still added it.

Copy link
Member

@liuml07 liuml07 May 7, 2020

Choose a reason for hiding this comment

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

You want to check Effective Java item 11?

If this class is an exception, we at least should put a comment saying why overriding equals() here does not need to override hasCode().

*/
public class ShowSchemasStatement extends ShowStatement {
@Nullable
private String schemaPattern;
Copy link
Member

Choose a reason for hiding this comment

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

final so this class is immutable. Not sure if we need it to be immutable today, but it's nice when we need it someday in future. Same to ShowTablesStatement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


public void toSQL(ColumnResolver resolver, StringBuilder buf) {
Preconditions.checkNotNull(buf);
buf.append("SHOW SCHEMAS ");
Copy link
Member

Choose a reason for hiding this comment

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

	buf.append("SHOW SCHEMAS ");
        if (schemaPattern != null) {
            buf.append("LIKE ");

to

	buf.append("SHOW SCHEMAS");
        if (schemaPattern != null) {
            buf.append(" LIKE ");

Not sure if this makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


@Override
public int hashCode() {
return Objects.hash(targetSchema, dbPattern);
Copy link
Contributor

@gjacoby126 gjacoby126 May 7, 2020

Choose a reason for hiding this comment

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

nit: the Java standard says that if two objects are equal, they have to have the same hash code (https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html) but here we judge equality purely by targetSchema and hashCode by both targetSchema and dbPattern.

Copy link
Contributor

Choose a reason for hiding this comment

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

After that I think this is ready for me to commit unless anyone else has any comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was an oversight on my part, fixed.

@liuml07
Copy link
Member

liuml07 commented May 7, 2020

looks good to me based on Geoffrey's comment. Thanks for updating

This patch adds new SQL grammar like following

- SHOW SCHEMAS [like '<pattern>']
- SHOW TABLES [IN <schema>] [like '<pattern']

Example invocations:

- show schemas
- show scemas like 'SYS%'
- show tables
- show tables in SYSTEM
- show tables in SYSTEM like 'CAT%'

The current way of fetching this information is by using
!tables and !schemas via sqlline JDBC support but that is
not flexible enough for the end users to add more fitlers.
This approach is more inline with what other databases do.

Added test coverage in parser tests and core e2e tests.
@gjacoby126 gjacoby126 merged commit 116b9bd into apache:master May 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants