phoenix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (PHOENIX-1639) Enhance function/expression index tests
Date Sat, 14 Feb 2015 00:42:12 GMT

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

ASF GitHub Bot commented on PHOENIX-1639:
-----------------------------------------

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

    https://github.com/apache/phoenix/pull/36#discussion_r24708956
  
    --- Diff: phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexExpressionIT.java
---
    @@ -193,52 +197,79 @@ protected void helpTestCreateAndUpdate(boolean mutable, boolean
localIndex) thro
                 verifyResult(rs, 3);
                 verifyResult(rs, 4);
     
    -            // update the first row
    -            upsert = "UPSERT INTO "
    +            conn.createStatement().execute("DROP INDEX IDX ON " + fullDataTableName);
    +        } finally {
    +            conn.close();
    +        }
    +    }
    +    
    +    @Test
    +    public void testMutableIndexUpdate() throws Exception {
    +    	helpTestUpdate(false);
    +    }
    +
    +    @Test
    +    public void testMutableLocalIndexUpdate() throws Exception {
    +    	helpTestUpdate(true);
    +    }
    +    
    +    protected void helpTestUpdate(boolean localIndex) throws Exception {
    +        String dataTableName = MUTABLE_INDEX_DATA_TABLE;
    +        String fullDataTableName = INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR
+ dataTableName;
    +        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    +        Connection conn = DriverManager.getConnection(getUrl(), props);
    +        try {
    +            conn.setAutoCommit(false);
    +            populateDataTable(conn, dataTableName);
    +
    +            // create an expression index
    +            String ddl = "CREATE "
    +                    + (localIndex ? "LOCAL" : "")
    +                    + " INDEX IDX ON "
    +                    + fullDataTableName
    +                    + " ((UPPER(varchar_pk) || '_' || UPPER(char_pk) || '_' || UPPER(varchar_col1)
|| '_' || UPPER(char_col2)),"
    +                    + " (decimal_pk+int_pk+decimal_col2+int_col1)," + " date_pk+1, date1+1,
date2+1 )"
    +                    + " INCLUDE (long_col1, long_col2)";
    +            PreparedStatement stmt = conn.prepareStatement(ddl);
    +            stmt.execute();
    +
    +            // update index pk column and covered column
    +            String upsert = "UPSERT INTO "
                         + fullDataTableName
    -                    + "(varchar_pk, char_pk, int_pk, long_pk, decimal_pk, date_pk, a.varchar_col1)
VALUES(?, ?, ?, ?, ?, ?, ?)";
    +                    + "(varchar_pk, char_pk, int_pk, long_pk, decimal_pk, date_pk, varchar_col1,
long_col1) VALUES(?, ?, ?, ?, ?, ?, ?, ?)";
     
                 stmt = conn.prepareStatement(upsert);
                 stmt.setString(1, "varchar1");
                 stmt.setString(2, "char1");
                 stmt.setInt(3, 1);
                 stmt.setLong(4, 1l);
    -            stmt.setBigDecimal(5, new BigDecimal(1.0));
    +            stmt.setBigDecimal(5, new BigDecimal(0.5));
                 stmt.setDate(6, DateUtil.parseDate("2015-01-01 00:00:00"));
                 stmt.setString(7, "a.varchar_updated");
    +            stmt.setLong(8, 101);
                 stmt.executeUpdate();
                 conn.commit();
     
                 // verify only one row was updated in the data table
    -            String selectSql = "UPPER(varchar_pk) || '_' || UPPER(char_pk) || '_' ||
UPPER(varchar_col1) || '_' || UPPER(char_col2) from "
    +            String selectSql = "UPPER(varchar_pk) || '_' || UPPER(char_pk) || '_' ||
UPPER(varchar_col1) || '_' || UPPER(char_col2), long_col1 from "
                         + fullDataTableName;
    -            rs = conn.createStatement().executeQuery("SELECT /*+ NO_INDEX */ " + selectSql);
    +            ResultSet rs = conn.createStatement().executeQuery("SELECT /*+ NO_INDEX */
" + selectSql);
                 assertTrue(rs.next());
                 assertEquals("VARCHAR1_CHAR1 _A.VARCHAR_UPDATED_B.CHAR1   ", rs.getString(1));
    +            assertEquals(101, rs.getLong(2));
                 assertTrue(rs.next());
                 assertEquals("VARCHAR2_CHAR2 _A.VARCHAR2_B.CHAR2   ", rs.getString(1));
    -            assertTrue(rs.next());
    -            assertEquals("VARCHAR3_CHAR3 _A.VARCHAR3_B.CHAR3   ", rs.getString(1));
    -            assertTrue(rs.next());
    -            assertEquals("VARCHAR4_CHAR4 _A.VARCHAR4_B.CHAR4   ", rs.getString(1));
    +            assertEquals(2, rs.getLong(2));
                 assertFalse(rs.next());
     
                 // verify that the rows in the index table are also updated
                 rs = conn.createStatement().executeQuery("SELECT " + selectSql);
                 assertTrue(rs.next());
    -            // if the data table is immutable, the index table will have one more
    -            // row
    -            if (!mutable) {
    --- End diff --
    
    This doesn't make sense for immutable indexes, as we are not supposed to mutate existing
rows, so I modified this test to only test mutable indexes.


> Enhance function/expression index tests
> ---------------------------------------
>
>                 Key: PHOENIX-1639
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-1639
>             Project: Phoenix
>          Issue Type: Test
>            Reporter: Thomas D'Silva
>            Assignee: Thomas D'Silva
>
> Add tests for views, negative scenarios, sort order of expression. 



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

Mime
View raw message