[jira] [Updated] (PHOENIX-1409) Allow ALTER TABLE SET command to update HTableDescriptor and HColumnDescriptor properties

Thu, 08 Jan 2015 20:31:41 -0800

     [ 
https://issues.apache.org/jira/browse/PHOENIX-1409?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Samarth Jain updated PHOENIX-1409:
----------------------------------
    Attachment: PHOENIX-1409-v6.patch

Good catches [~aliciashu]. I have added more test cases around the following 
two issues that you discovered:
1) Setting property wasn't working correctly when the table had only PK columns 
(i.e. PTable.getColumnFamilies() returns empty)
2) ALTER TABLE T ADD CF.COL SET IN_MEMORY should only set the property only for 
column family CF and not all the column families for the the table. 

Your change for 1) though would not have worked when there was an explicit 
default column family specified for the table. See 
testSetHColumnPropertyForTableWithOnlyPKCols. 

I also removed the need for tracking new column families separately (which was 
added as part of my v3 patch). 

{code}
+                if (existingColumnFamilies.isEmpty() && 
newColumnFamiliesToBeAdded.isEmpty() && !commonFamilyProps.isEmpty()) {
+                       
allFamiliesProps.put(QueryConstants.DEFAULT_COLUMN_FAMILY, commonFamilyProps);
+                }
{code}
is now :
{code}
if (table.getColumnFamilies().isEmpty() && columnDefs.size() == 0 && 
!commonFamilyProps.isEmpty()) {
                        
allFamiliesProps.put(Bytes.toString(table.getDefaultFamilyName() == null ? 
QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES : 
table.getDefaultFamilyName().getBytes() ), commonFamilyProps);
                }
                
{code}


I noticed that for other tests there was some overlap between the tests you and 
I wrote. I merged our test cases and removed the ones that were testing the 
same thing.

Also, a few of your tests were catching exceptions when they shouldn't be. For 
ex:
{code}
+       @Test
+       public void testMultipleProperties() throws Exception {
+               Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+               Connection conn = DriverManager.getConnection(getUrl(), props);
+               conn.setAutoCommit(false);
+
+               try {
+                       conn.createStatement()
+                       .execute(
+                                       "CREATE TABLE test_multi_table "
+                                                       + "  (a_string varchar 
not null, col1 integer, cf1.col2 integer, col3 integer , cf2.col4 integer "
+                                                       + "  CONSTRAINT pk 
PRIMARY KEY (a_string)) immutable_rows=true , SALT_BUCKETS=3 ");
+
+                       String ddl = "Alter table test_multi_table set 
COMPACTION_ENABLED=TRUE, IMMUTABLE_ROWS=false";
+                       conn.createStatement().execute(ddl);
+
+                       try (HBaseAdmin admin = 
conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
+                               HTableDescriptor tableDesc = 
admin.getTableDescriptor(Bytes.toBytes("TEST_MULTI_TABLE"));
+                               assertTrue(tableDesc.isCompactionEnabled());
+                               HColumnDescriptor[] columnFamilies = 
tableDesc.getColumnFamilies();
+                               assertEquals(3, columnFamilies.length);
+                               assertEquals("0", 
columnFamilies[0].getNameAsString());
+                               assertEquals("CF1", 
columnFamilies[1].getNameAsString());
+                               assertEquals("CF2", 
columnFamilies[2].getNameAsString());
+                               assertImmutableRows(conn,"TEST_MULTI_TABLE", 
false);
+                       } catch (SQLException e) {
+                               
assertEquals(SQLExceptionCode.COLUMN_FAMILY_NOT_ALLOWED_TABLE_PROPERTY.getErrorCode(),
 e.getErrorCode());
+                       }       
+               } finally {
+                       conn.close();
+               }
+       }
{code}

You shouldn't be catching that SQLException. In fact, the exception code you 
are looking for will never be thrown by the code in the try-with-resources 
block. 

As part of this patch I also made the change of disallowing setting table level 
properties when you are adding columns. This includes TTL as well. 

So now ALTER TABLE ADD COL SET COMPACTION_ENABLED=false fails. And so does 
ALTER TABLE ADD COL SET TTL=1000.

[~jamestaylor] - please review. 


> Allow ALTER TABLE <table> SET command to update HTableDescriptor and 
> HColumnDescriptor properties
> -------------------------------------------------------------------------------------------------
>
>                 Key: PHOENIX-1409
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-1409
>             Project: Phoenix
>          Issue Type: Improvement
>    Affects Versions: 4.2
>            Reporter: James Taylor
>            Assignee: Alicia Ying Shu
>         Attachments: PHOENIX-1409-v3.patch, PHOENIX-1409-v6.patch, 
> Phoenix-1409-v1.patch, Phoenix-1409-v4-2.patch, Phoenix-1409-v4.patch, 
> Phoenix-1409-v5.patch, Phoenix-1409.patch, WIP.patch, phoenix-1409-v2.patch
>
>
> Once PHOENIX-1408 is fixed, we should allow HTableDescriptor and 
> HColumnDescriptor properties through the ALTER TABLE <table> SET command. 
> It'd just be a matter of passing these properties through the existing 
> methods, as we support this for CREATE TABLE.



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

Reply via email to