Uh oh!
There was an error while loading. Please reload this page.
PHOENIX-6457 - Optionally store schema version string in SYSTEM.CATALOG - #1216
Conversation
stoty
commented
Apr 30, 2021
💔 -1 overall
This message was automatically generated. |
| import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_INDEX_ID_DATA_TYPE; | ||
| import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_STATEMENT; | ||
| import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_TYPE; | ||
| import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.*; |
There was a problem hiding this comment.
Oops, thought I'd fixed all those before pushing. Fixed and repushed.
| } | ||
| if (schemaVersion == null) { | ||
| tableUpsert.setNull(34, Types.VARCHAR); |
There was a problem hiding this comment.
Or should have a default starting schema version?
There was a problem hiding this comment.
I'd considered it but decided against the idea because I didn't want to proscribe a particular versioning scheme...the idea is that a particular organization can choose their own version stamps (and that they don't have to if they don't want to, hence default null)
| String alterViewSql = "ALTER VIEW " + viewFullName + " SET SCHEMA_VERSION='" + newVersion + "'"; | ||
| conn.createStatement().execute(alterViewSql); | ||
| PTable view2 = PhoenixRuntime.getTableNoCache(conn, viewFullName); | ||
| assertEquals(newVersion, view2.getSchemaVersion()); |
There was a problem hiding this comment.
should we assert on changes on datatable schema version as well?
There was a problem hiding this comment.
There's not meant to be any cascade behavior here...what changes should I assert on? Just that that the base table didn't change? I could do that.
| throws Exception { | ||
| final String dataTableFullName = SchemaUtil.getTableName(schemaName, tableName); | ||
| String ddl = | ||
| "CREATE TABLE " + dataTableFullName + " (\n" + "ID1 VARCHAR(15) NOT NULL,\n" |
There was a problem hiding this comment.
If there are any changes on the table schema like new column addition or drop of an existing column, how would the schema version be updated? I am thinking phoenix should increment the version or we need to enhance the alter DDL to include schema version also in the statement. If the former, schema version format should be fixed just like sequence number.
There was a problem hiding this comment.
It appears there's a rule in Phoenix grammar which prevents setting table level properties (like schema version) while adding a column, which means that when adding a column you'd need a separate ALTER TABLE SET SCHEMA_VERSION statement. Not ideal, but I was trying to avoid large changes in the plumbing.
There was a problem hiding this comment.
If I support changing Storage format or Column encoding, we will need to do alter table set schema again right? I think it will be good to invest in plumbing this change.
There was a problem hiding this comment.
@gokceni - wouldn't those be table properties as well? Should be able to do in one statement.
There was a problem hiding this comment.
Good to have a follow-up Jira in that case. I feel ALTER ADD/DROP should implicitly increment the schema_version. If every org/customer decides the schema_version format by themselves, this will be difficult. WDYT?
There was a problem hiding this comment.
I disagree that schema version should auto-increment. First, because an auto-incrementing int sequence already exists (see PTable.getSequenceNumber, which gets incremented by DDL statements), and second, because that's not really what this feature is meant to do.
The purpose of SCHEMA_VERSION is that it's a string which is relevant to a particular client application or applications and its release numbering.
Say application Foo has quarterly releases "Q1-2021", "Q1-2021.1", "Q2-2021", and so on. It creates tables A, B, and C as part of Q1-2021, makes a table property change to table B during Q1-2021.1, and then adds 2 more tables D and E and 1 column to an existing table C in Q2-2021.
At this point the schema versions are:
A: Q1-2021
B: Q1-2021.1
C: Q2-2021 (assuming there was a separate statement to update schema version after adding the column)
D: Q2-2021
E: Q2-2021
From this, the application Foo can check for each table that its schema version is the version that it expects (or not) and take action accordingly. An application running Q1-2021 can still interpret queries / messages against Table A, but might want to reject ones from tables B through E, because they're from newer schemas that it has no knowledge of.
There was a problem hiding this comment.
As @swaroopak points out, it's a pain to have to do the extra ALTER TABLE SET SCHEMA_VERSION statement after doing an add/drop column, so it would be nice if we could update this property as part of doing the add or drop column. I'll see if I can figure out the cause of why the existing restriction is there, and if it can be easily set aside.
There was a problem hiding this comment.
Thanks for the explanation. This makes sense
| } | ||
| @Test | ||
| public void testCreateIndexSchemaVersion() throws Exception { |
There was a problem hiding this comment.
How will the select statements behave? They need to be schema version aware at least implicitly.
There was a problem hiding this comment.
Not sure I understand this point...
There was a problem hiding this comment.
Let's say I drop the column and schema version changes from v1 to v1.1. Currently, the phoenix will use v1.1 when processing a select * . can we add a test for that?
And is there a way I can query with old schema_version?
There was a problem hiding this comment.
Phoenix won't really "use" a schema version at all during a select. To be precise, when it grabs the PTable to be able to interpret the query results, the schema version will be in the PTable, but it's not really used by the query logic.
The point of schema version is to allow:
- Applications to check to see if a table, view or index is compatible with a particular version of their schema
- In the future, when we have change streaming from Phoenix, messages will be annotated with the schema version so consumers of the message will be able to check to see if they can interpret the message (i.e, it's compatible with a particular version of a consuming application) or not.
| throws Exception { | ||
| final String dataTableFullName = SchemaUtil.getTableName(schemaName, tableName); | ||
| String ddl = | ||
| "CREATE TABLE " + dataTableFullName + " (\n" + "ID1 VARCHAR(15) NOT NULL,\n" |
There was a problem hiding this comment.
If I support changing Storage format or Column encoding, we will need to do alter table set schema again right? I think it will be good to invest in plumbing this change.
| public static final long MIN_SYSTEM_TABLE_TIMESTAMP_4_15_0 = MIN_TABLE_TIMESTAMP + 29; | ||
| public static final long MIN_SYSTEM_TABLE_TIMESTAMP_4_16_0 = MIN_TABLE_TIMESTAMP + 33; | ||
| public static final long MIN_SYSTEM_TABLE_TIMESTAMP_4_17_0 = MIN_TABLE_TIMESTAMP + 34; | ||
| public static final long MIN_SYSTEM_TABLE_TIMESTAMP_4_17_0 = MIN_TABLE_TIMESTAMP + 35; |
There was a problem hiding this comment.
Each syscat column needs an individual timestamp, and 33 was 4.16 + 1 for Physical table name, +1 for schema version
stoty
commented
May 4, 2021
💔 -1 overall
This message was automatically generated. |
swaroopak
left a comment
There was a problem hiding this comment.
Thank you for addressing the comments and answering questions. +1, LGTM
…OG (#1216) * PHOENIX-6457 - Optionally store schema version string in SYSTEM.CATALOG
No description provided.