Github user twdsilva commented on a diff in the pull request:

    https://github.com/apache/phoenix/pull/355#discussion_r224635037
  
    --- Diff: 
phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java ---
    @@ -1298,7 +1284,322 @@ public void testAddingColumnsToTablesAndViews() 
throws Exception {
                 assertSequenceNumber(schemaName, viewName, 
PTable.INITIAL_SEQ_NUM + 1);
             }
         }
    -   
    +
    +
    +    @Test
    +    public void testModifyingRowTimestampColumnNotAllowedViaAlterTable() 
throws Exception {
    +        try (Connection conn = DriverManager.getConnection(getUrl())) {
    +            conn.createStatement().execute("CREATE TABLE " + 
dataTableFullName +
    +                    " (PK1 DATE NOT NULL, PK2 VARCHAR NOT NULL, KV1 
VARCHAR CONSTRAINT PK PRIMARY KEY(PK1 ROW_TIMESTAMP, PK2)) " + tableDDLOptions);
    +            try {
    +                conn.createStatement().execute("ALTER TABLE " + 
dataTableFullName + " modify PK1 BIGINT");
    +                fail("Altering table to modify a row_timestamp column 
should fail");
    +            } catch (SQLException e) {
    +                
assertEquals(SQLExceptionCode.DISALLOW_MODIFY_TIMESTAMP_OR_PK_COLUMN.getErrorCode(),
 e.getErrorCode());
    +            }
    +            conn.close();
    +        }
    +    }
    +
    +    @Test
    +    public void testModifyingPKColumnNotAllowedViaAlterTable() throws 
Exception {
    +        try (Connection conn = DriverManager.getConnection(getUrl())) {
    +            conn.createStatement().execute("CREATE TABLE " + 
dataTableFullName +
    +                    " (PK1 DATE NOT NULL PRIMARY KEY, PK2 VARCHAR , KV1 
VARCHAR) " + tableDDLOptions);
    +            try {
    +                conn.createStatement().execute("ALTER TABLE " + 
dataTableFullName + " modify PK1 BIGINT");
    +                fail("Altering table to modify a PK column should fail");
    +            } catch (SQLException e) {
    +                
assertEquals(SQLExceptionCode.DISALLOW_MODIFY_TIMESTAMP_OR_PK_COLUMN.getErrorCode(),
 e.getErrorCode());
    +            }
    +            conn.close();
    +        }
    +    }
    +
    +    @Test
    +    public void testQueryAfterModifiedColumn() throws Exception {
    +        Properties props = new Properties();
    +        String tableName = generateUniqueName();
    +        String indexName = "IDX_" + tableName;
    +        try (Connection conn = DriverManager.getConnection(getUrl(), 
props)) {
    +            conn.setAutoCommit(true);
    +            conn.createStatement().execute("CREATE TABLE " + tableName
    +                    + " (a VARCHAR(5), b VARCHAR(5), CONSTRAINT PK PRIMARY 
KEY (a))");
    +            conn.createStatement().execute("CREATE INDEX " + indexName + " 
ON " + tableName + " (b)");
    +            conn.createStatement().execute("UPSERT INTO " + tableName + " 
Values('a','12345')");
    +            conn.createStatement().execute("UPSERT INTO " + tableName + " 
Values('b','13555')");
    +            conn.createStatement().execute("UPSERT INTO " + tableName + " 
Values('c','13666')");
    +            conn.commit();
    +            conn.createStatement().execute("ALTER TABLE " + tableName + " 
modify b VARCHAR(2)");
    +            conn.createStatement().execute("UPSERT INTO " + tableName + " 
Values('d','13')");
    +
    +            {
    +                ResultSet rs = conn.createStatement().executeQuery("SELECT 
/*+ NO_INDEX*/ b from " + tableName + " WHERE b='13'");
    +                assertTrue(rs.next());
    +                assertEquals("13", rs.getString(1));
    +            }
    +
    +            {
    +                ResultSet rs = conn.createStatement().executeQuery("SELECT 
/*+ NO_INDEX*/ b from " + tableName + " WHERE b='13555'");
    +                assertTrue(rs.next());
    +                assertEquals("13555", rs.getString(1));
    --- End diff --
    
    Since we don't modify existings data, when we decrease the length of a 
VARCHAR column its possible that the string returned is of length larger than 
expected. I don't think we should allow this to happen. We should support 
*only* increasing the length and not support decreasing the length of a column.


---

Reply via email to