[ 
https://issues.apache.org/jira/browse/PHOENIX-2999?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15362893#comment-15362893
 ] 

James Taylor commented on PHOENIX-2999:
---------------------------------------

Looking good, [~an...@apache.org]. Thanks for the updates. A couple of 
questions/comments:
- You don't need to store every tenantID in a Map here. That's what we're 
trying to avoid, as there could be an unlimited number of them. Instead, in the 
loop below, just store the current tenantID and only when it changes (and when 
you exit the loop), call the upgrade code for that tenantID. I think storing 
the view names in a Set is ok, but not ideal either. It's potentially unlimited 
as well, but in practice there's probably a small enough number of them (per 
tenant).
{code}
+    public static Map<String,Set<String>> getTenantViewNames(PhoenixConnection 
conn, String phsyicalTable) throws SQLException {
+        HashMap<String,Set<String>> tenantViews=new 
HashMap<String,Set<String>>();
         PreparedStatement preparedStatment = 
conn.prepareStatement(GET_VIEWS_QUERY);
-        preparedStatment.setString(1, SchemaUtil.normalizeIdentifier(table));
+        preparedStatment.setString(1, 
SchemaUtil.normalizeIdentifier(phsyicalTable));
         ResultSet rs = preparedStatment.executeQuery();
+        String tenantId=null;
         while (rs.next()) {
-            viewNames.add(SchemaUtil.getTableName(rs.getString(1), 
rs.getString(2)));
+            tenantId=rs.getString(1);
+            Set<String> viewNames=tenantViews.get(tenantId);
+            if(viewNames==null){
+                viewNames  = new HashSet<String>();
+                tenantViews.put(tenantId, viewNames);
+            }
+            viewNames.add(SchemaUtil.getTableName(rs.getString(2), 
rs.getString(3)));
         }
-        return viewNames;
+        return tenantViews;
     }
{code}
- Not sure I understand this change, but it looks suspect. Was there a bug here 
before?
{code}
     private static final String DELETE_LINK = "DELETE FROM " + 
SYSTEM_CATALOG_SCHEMA + "." + SYSTEM_CATALOG_TABLE
-            + " WHERE " + COLUMN_FAMILY + "=? AND " + LINK_TYPE + " = " + 
LinkType.PHYSICAL_TABLE.getSerializedValue();
+            + " WHERE (" + TABLE_SCHEM + "=? OR (" + TABLE_SCHEM + " IS NULL 
AND ? IS NULL)) AND " + TABLE_NAME + "=? AND " + COLUMN_FAMILY + "=? AND " + 
LINK_TYPE + " = " + LinkType.PHYSICAL_TABLE.getSerializedValue();
{code}
- In the updateLink upgrade code, are you upgrading the link row for every 
view? If that's the case, you perhaps can just set the TABLE_TYPE column there 
and then you won't need to check for TABLE_TYPE IS NULL in the GET_VIEWS_QUERY. 
If not, not a big deal.

> Upgrading Multi-tenant table to map with namespace using upgradeUtil
> --------------------------------------------------------------------
>
>                 Key: PHOENIX-2999
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-2999
>             Project: Phoenix
>          Issue Type: Bug
>    Affects Versions: 4.8.0
>            Reporter: Ankit Singhal
>            Assignee: Ankit Singhal
>            Priority: Critical
>             Fix For: 4.8.0
>
>         Attachments: PHOENIX-2999.patch, PHOENIX-2999_v1.patch, 
> PHOENIX-2999_v2.patch, PHOENIX-2999_v3.patch, PHOENIX-2999_v4.patch, 
> PHOENIX-2999_v5.patch
>
>
> currently upgradeUtil doesn't handle multi-tenant table with tenant views 
> properly.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to