phoenix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Samarth Jain (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (PHOENIX-4265) NPE when hinting index on table with ROW_TIMESTAMP
Date Mon, 02 Oct 2017 23:16:00 GMT

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

Samarth Jain commented on PHOENIX-4265:
---------------------------------------

The below test repro's the NPE. 
{code}
@Test
    public void testIndexHintOnTableWithRowTimestamp() throws Exception {
        Connection conn = DriverManager.getConnection(getUrl());
        try {
            conn.createStatement().execute("CREATE IMMUTABLE TABLE t1 (k1 TIMESTAMP not null,
k2 bigint not null, v bigint, constraint pk primary key (k1 row_timestamp,k2 )) SALT_BUCKETS
= 9");
            conn.createStatement().execute("CREATE INDEX idx ON t1 (v)");
            PreparedStatement stmt = conn.prepareStatement("UPSERT INTO t1 VALUES (?, ?, ?)
");
            stmt.setTimestamp(1, new Timestamp(1000));
            stmt.setLong(2, 1000);
            stmt.setLong(3, 1000);
            stmt.executeUpdate();
            stmt.setTimestamp(1, new Timestamp(2000));
            stmt.setLong(2, 1000);
            stmt.setLong(3, 5);
            stmt.executeUpdate();
            stmt.setTimestamp(1, new Timestamp(3000));
            stmt.setLong(2, 1000);
            stmt.setLong(3, 5);
            stmt.executeUpdate();
            stmt.setTimestamp(1, new Timestamp(4000));
            stmt.setLong(2, 1000);
            stmt.setLong(3, 5);
            stmt.executeUpdate();
            stmt.setTimestamp(1, new Timestamp(5000));
            stmt.setLong(2, 1000);
            stmt.setLong(3, 10);
            stmt.executeUpdate();
            stmt.setTimestamp(1, new Timestamp(6000));
            stmt.setLong(2, 1000);
            stmt.setLong(3, 20);
            stmt.executeUpdate();
            conn.commit();
            ResultSet rs = conn.createStatement().executeQuery("SELECT /*+ INDEX(T1 IDX) */
* FROM T1 WHERE v = 5");
            rs.next();
        } finally {
            conn.close();
        }
    }
{code}

The issue is that the codec for PTimestamp is null. 
{code}
protected PTimestamp(String sqlTypeName, int sqlType, int ordinal) {
        super(sqlTypeName, sqlType, java.sql.Timestamp.class, null, ordinal);
    }

    private PTimestamp() {
        super("TIMESTAMP", Types.TIMESTAMP, java.sql.Timestamp.class,
                null, 9);
    }
{code}

[~jamestaylor] - should it be PUnsignedInt.INSTANCE.getCodec()? Is it ok for any PDataType
to have null codec?

> NPE when hinting index on table with ROW_TIMESTAMP
> --------------------------------------------------
>
>                 Key: PHOENIX-4265
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-4265
>             Project: Phoenix
>          Issue Type: Improvement
>            Reporter: James Taylor
>
> See email discussion here: https://lists.apache.org/thread.html/d87a508e5b4e2fc6b7110d861b71209d2385adaecd0152b790ee00e9@%3Cuser.phoenix.apache.org%3E
> I'm not able to repro with this unit test:
> {code}
>     @Test
>     public void testIndexHintOnTableWithRowTimestamp() throws Exception {
>         Connection conn = DriverManager.getConnection(getUrl());
>         try {
>             conn.createStatement().execute("CREATE IMMUTABLE TABLE t1 (k1 TIMESTAMP not
null, k2 bigint not null, v bigint, constraint pk primary key (k1 row_timestamp,k2 ))");
>             conn.createStatement().execute("CREATE INDEX idx ON t1 (v)");
>             conn.createStatement().execute("SELECT /*+ INDEX(T1 IDX) */ K1,K2,V FROM
t1 WHERE v = 5");
>         } finally {
>             conn.close();
>         }
>     }
> {code}
> FYI, due to the inability to keep an index in sync when there's a ROW_TIMESTAMP column,
as of 4.12 we're disallowing the creation of mutable secondary indexes when a table has a
ROW_TIMESTAMP column. Usually, since the timestamp is part of the row key, the data table
can be declared IMMUTABLE. In this case, the index would still be allowed.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message