[
https://issues.apache.org/jira/browse/PHOENIX-1641?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14308259#comment-14308259
]
James Taylor commented on PHOENIX-1641:
---------------------------------------
As [~tdsilva] found out, ALTER TABLE ADD IF NOT EXIST doesn't add *any* of the
columns if *any* of them already exist (see PHOENIX-1614). So instead of adding
all the columns, we'll need to add from 1 to 3 of them conditionally, depending
on what the current timestamp is of the SYSTEM.CATALOG table.
Something like:
{code}
try {
metaConnection.createStatement().executeUpdate(
QueryConstants.CREATE_TABLE_METADATA);
} catch (NewerTableAlreadyExistsException ignore) {
// Ignore, as this will happen if the
SYSTEM.CATALOG already exists at this fixed timestamp.
// A TableAlreadyExistsException is not thrown,
since the table only exists *after* this fixed timestamp.
} catch (TableAlreadyExistsException e) {
long currentTimestamp =
e.getTable().getTimestamp();
// We know that we always need to add the
STORE_NULLS column for 4.3 release
String columnsToAdd =
PhoenixDatabaseMetaData.STORE_NULLS + " " + PBoolean.INSTANCE.getSqlTypeName();
if (currentTimestamp <=
theSysTableTimeStampWhenIndexDisableTimestampWasAdded) {
columnsToAdd += ", " +
PhoenixDatabaseMetaData.INDEX_DISABLE_TIMESTAMP + " " +
PLong.INSTANCE.getSqlTypeName();
}
if (currentTimestamp <=
theSysTableTimeStampWhenIndexTypeWasAdded) {
columnsToAdd += ", " +
PhoenixDatabaseMetaData.INDEX_TYPE + " " +
PUnsignedTinyint.INSTANCE.getSqlTypeName();
}
// This will occur if we have an older
SYSTEM.CATALOG and we need to update it to include
// any new columns we've added.
metaConnection =
addColumnsIfNotExists(metaConnection,
PhoenixDatabaseMetaData.SYSTEM_CATALOG,
MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP,
columnsToAdd);
}
{code}
Just look back at the history for MetaDataProtocol.java in the github mirror
for 4.0 to see what the value of MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP
was when INDEX_TYPE and INDEX_DISABLE_TIMESTAMP where added to the
SYSTEM.CATALOG table.
> Add back the upgrade code in ConnectionQueryServicesImpl
> --------------------------------------------------------
>
> Key: PHOENIX-1641
> URL: https://issues.apache.org/jira/browse/PHOENIX-1641
> Project: Phoenix
> Issue Type: Bug
> Reporter: Samarth Jain
> Assignee: Samarth Jain
> Fix For: 5.0.0, 4.3
>
> Attachments: PHOENIX-1641.patch
>
>
> The code got removed in the commit:
> https://github.com/apache/phoenix/commit/58c80a1857659962d695bc8e5fe22b4e401b7f0a
>
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)