-
Notifications
You must be signed in to change notification settings - Fork 1k
PHOENIX-5543: Implement SHOW TABLES/SCHEMAS sql commands #606
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
Conversation
|
@vincentpoon FYI. |
phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java
Outdated
Show resolved
Hide resolved
phoenix-core/src/it/java/org/apache/phoenix/end2end/TenantSpecificTablesDDLIT.java
Outdated
Show resolved
Hide resolved
|
+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); |
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.
nit: more than 100 char per line
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.
Done.
gjacoby126
left a comment
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.
+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")); |
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.
nit: please put loop body in brackets.
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.
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")); |
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.
ditto for loop in brackets
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.
Done.
bharathv
left a comment
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.
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); |
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.
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")); |
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.
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")); |
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.
Done.
bharathv
left a comment
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.
Attached a patch to the jira to kick-off a pre-commit build. It looks like it doesn't happen automatically on PRs.
liuml07
left a comment
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.
Nice feature. But I don't have enough context to be +1. Thanks,
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object other) { |
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.
Since you are overriding equals, I would say let's also do the hashCode(). Same to ShowTablesStatement.
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.
Not sure if thats of much use, but I still added it.
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.
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; |
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.
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.
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.
Done.
|
|
||
| public void toSQL(ColumnResolver resolver, StringBuilder buf) { | ||
| Preconditions.checkNotNull(buf); | ||
| buf.append("SHOW SCHEMAS "); |
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.
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.
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.
Done.
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(targetSchema, dbPattern); |
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.
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.
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.
After that I think this is ready for me to commit unless anyone else has any comments.
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.
That was an oversight on my part, fixed.
|
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.
This patch adds new SQL grammar like following
Example invocations:
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.