phoenix-dev mailing list archives

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

             Summary: 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


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