Uh oh!
There was an error while loading. Please reload this page.
PHOENIX-6518 Implement SHOW CREATE TABLE SQL command - #1271
Conversation
| assertTrue(rs.getString(1).contains(ddl)); | ||
| } | ||
| @Ignore |
There was a problem hiding this comment.
| Assert.assertEquals(createTableStmt, result.toUpperCase()); | ||
| } | ||
| // @Ignore |
There was a problem hiding this comment.
Created https://issues.apache.org/jira/browse/PHOENIX-6519 for this
| public class ShowCreateStatementIT extends ParallelStatsDisabledIT { | ||
| @Test | ||
| public void testDescribebasic() throws Exception { |
| ResultSet rs = conn.createStatement().executeQuery("SHOW CREATE STATEMENT " + tableName ); | ||
| assertTrue(rs.next()); | ||
| System.out.println(ddl); |
| ResultSet rs = conn.createStatement().executeQuery("SHOW CREATE STATEMENT \"" + tableName + "\""); | ||
| assertTrue(rs.next()); | ||
| System.out.println(ddl); |
| ResultSet rs = conn.createStatement().executeQuery("SHOW CREATE STATEMENT " + tableFullName + ""); | ||
| assertTrue(rs.next()); | ||
| System.out.println(ddl); |
| } | ||
| } | ||
| private static class ExecutableShowCreateTablesStatement extends ShowCreateTablesStatement |
There was a problem hiding this comment.
class names don't match the command name
| import org.apache.phoenix.jdbc.PhoenixStatement; | ||
| /** | ||
| * Parent class for all SHOW statements. SHOW SCHEMAS, SHOW TABLES etc. |
| import java.util.Objects; | ||
| /** | ||
| * ParseNode implementation for DESCRIBE tablename. |
| if(tableName.getSchemaName() != null) { | ||
| if (tableName.isSchemaNameCaseSensitive()) { | ||
| buf.append("\""); | ||
| } | ||
| buf.append(tableName.getSchemaName()); | ||
| if (tableName.isSchemaNameCaseSensitive()) { | ||
| buf.append("\""); | ||
| } | ||
| buf.append("."); | ||
| } | ||
| if (tableName.isTableNameCaseSensitive()) { | ||
| buf.append("\""); | ||
| } | ||
| buf.append(tableName.getTableName()); | ||
| if (tableName.isTableNameCaseSensitive()) { | ||
| buf.append("\""); | ||
| } |
There was a problem hiding this comment.
Pretty sure we have a helper function already for this.
There was a problem hiding this comment.
I updated this to use the SchemaUtil.getEscapedTableName, its not exactly the same but works.
| throw new SQLException(e.getMessage()); | ||
| } | ||
| String stmtType; |
There was a problem hiding this comment.
Not sure we need to adjust the column name.
"CREATE STATEMENT" is probably enough.
| import static org.apache.phoenix.schema.SchemaSynthesisProcessor.ENTITY_NAME_IN_BASE_AND_ALTER_DDL_DON_T_MATCH; | ||
| import static org.apache.phoenix.schema.SchemaSynthesisProcessor.UNSUPPORTED_DDL_EXCEPTION; | ||
| import static org.apache.phoenix.schematool.SchemaSynthesisProcessor.ENTITY_NAME_IN_BASE_AND_ALTER_DDL_DON_T_MATCH; |
There was a problem hiding this comment.
Not sure about the "schematool" package name.
Perhaps "schemaextract" or "sema.generate" or similar would be more descriptive.
There was a problem hiding this comment.
In this package there are the files I moved from phoenix-tools module.
It has the SchemaSynthesis functionality as well not only the schema extraction.
stoty
commented
Jul 22, 2021
💔 -1 overall
This message was automatically generated. |
stoty
commented
Jul 22, 2021
💔 -1 overall
This message was automatically generated. |
| // Parse a describe statement. SHOW CREATE STATEMENT tablename ... | ||
| show_create_statement_node returns [ShowCreateStatement ret] | ||
| : SHOW CREATE STATEMENT tablename=from_table_name { $ret = factory.showCreateStatement(tablename); } |
There was a problem hiding this comment.
Can we make it "SHOW CREATE TABLE" than "SHOW CREATE STATEMENT" to adhere to other databases like mysql.
https://dev.mysql.com/doc/refman/8.0/en/show-create-table.html
https://docs.databricks.com/sql/language-manual/sql-ref-syntax-aux-show-create-table.html
https://prestodb.io/docs/current/sql/show-create-table.html
There was a problem hiding this comment.
Would be better to support to get the statements for index as well as views also. May be another JIRA.
There was a problem hiding this comment.
This from_table_name can be actually a view or index table as well.
phoenix/phoenix-core/src/main/antlr3/PhoenixSQL.g
Line 1129 in 9b76bd5
It is already working for views and for indexes as well. I added some tests to be sure. Istvan was in the favour of naming this SHOW CREATE STATEMENT as it works for views and indexes as well.
In case we chose to rename it to SHOW CREATE TABLE, should it work for views and indexes as well or Do you think those should be separate commands?
There was a problem hiding this comment.
bq.In case we chose to rename it to SHOW CREATE TABLE, should it work for views and indexes as well or Do you think those should be separate commands?
Same should work for table,index and views as well instead of separate commands.
stoty
commented
Jul 28, 2021
💔 -1 overall
This message was automatically generated. |
stoty
commented
Jul 28, 2021
💔 -1 overall
This message was automatically generated. |
stoty
commented
Jul 29, 2021
Don't forget to change the statement name in the ticket and commit message as well. |
Change-Id: I2b8f693a94e1b9fee1e54ef09d2a28569de7a669
No description provided.