phoenix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Taylor (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (PHOENIX-3437) Calcite allows CURRENT VALUE to be called on a sequence which has not yet been used
Date Thu, 03 Nov 2016 18:01:59 GMT

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

James Taylor commented on PHOENIX-3437:
---------------------------------------

The way Phoenix detects this error condition is by the absence of a sequence value in the
map it manages in ConnectionQueryServicesImpl here:
{code}
    @Override
    public long currentSequenceValue(SequenceKey sequenceKey, long timestamp) throws SQLException
{
        Sequence sequence = sequenceMap.get(sequenceKey);
        if (sequence == null) {
            throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_CALL_CURRENT_BEFORE_NEXT_VALUE)
            .setSchemaName(sequenceKey.getSchemaName()).setTableName(sequenceKey.getSequenceName())
            .build().buildException();
        }
{code}

I suspect that call to ConnectionQueryServices.validateSequences(List<SequenceAllocation>
sequenceAllocations, long timestamp, long[] values, SQLException[] exceptions, Sequence.ValueOp
action) might not be using the right enum for action. It should use Sequence.ValueOp.VALIDATE_SEQUENCE.
To track this down, you'd want to find out why/when the sequenceMap is being populated. You
could potentially compare against standalone Phoenix's execution path.


> Calcite allows CURRENT VALUE to be called on a sequence which has not yet been used
> -----------------------------------------------------------------------------------
>
>                 Key: PHOENIX-3437
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-3437
>             Project: Phoenix
>          Issue Type: Sub-task
>            Reporter: Eric Lomore
>            Assignee: Eric Lomore
>
> Calcite currently returns 0 for a sequence that has CURRENT VALUE called on it before
NEXT VALUE is ever called.
> To demonstrate, this sample integration test passes.
> {code}
>         connection.createStatement().execute("CREATE SEQUENCE IF NOT EXISTS seq0 START
WITH 1 INCREMENT BY 1");
>         start(false, 1000f).sql("select CURRENT VALUE FOR seq0, c0 from (values (1),
(1)) as t(c0)")
>                 .explainIs("PhoenixToEnumerableConverter\n" +
>                         "  PhoenixClientProject(EXPR$0=[CURRENT_VALUE('\"SEQ0\"')], C0=[$0])\n"
+
>                         "    PhoenixValues(tuples=[[{ 1 }, { 1 }]])\n")
>                 .resultIs(0, new Object[][]{
>                         {0L, 1},
>                         {0L, 1}})
>                 .close();
> {code}
> But Phoenix's intended behaviour is for this to throw an exception.
> {{SequenceIT.java}}
> {code}
>     @Test
>     public void testCurrentValueFor() throws Exception {
>         ResultSet rs;
>         nextConnection();
>         conn.createStatement().execute("CREATE SEQUENCE used.nowhere START WITH 2 INCREMENT
BY 4");
>         nextConnection();
>         try {
>             rs = conn.createStatement().executeQuery("SELECT CURRENT VALUE FOR used.nowhere
FROM SYSTEM.\"SEQUENCE\"");
>             rs.next();
>             fail();
>         } catch (SQLException e) {
>             assertEquals(SQLExceptionCode.CANNOT_CALL_CURRENT_BEFORE_NEXT_VALUE.getErrorCode(),
e.getErrorCode());
>             assertTrue(e.getNextException()==null);
>         }
>         
>         rs = conn.createStatement().executeQuery("SELECT NEXT VALUE FOR used.nowhere
FROM SYSTEM.\"SEQUENCE\"");
>         assertTrue(rs.next());
>         assertEquals(2, rs.getInt(1));
>         rs = conn.createStatement().executeQuery("SELECT CURRENT VALUE FOR used.nowhere
FROM SYSTEM.\"SEQUENCE\"");
>         assertTrue(rs.next());
>         assertEquals(2, rs.getInt(1));
> 	}
> {code}



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

Mime
View raw message