Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 7F5C4200BB1 for ; Thu, 3 Nov 2016 19:02:01 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 7E03C160AE5; Thu, 3 Nov 2016 18:02:01 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id C59ED160AFF for ; Thu, 3 Nov 2016 19:02:00 +0100 (CET) Received: (qmail 56563 invoked by uid 500); 3 Nov 2016 18:01:59 -0000 Mailing-List: contact dev-help@phoenix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@phoenix.apache.org Delivered-To: mailing list dev@phoenix.apache.org Received: (qmail 56253 invoked by uid 99); 3 Nov 2016 18:01:59 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Nov 2016 18:01:59 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id 9EE452C1F5A for ; Thu, 3 Nov 2016 18:01:59 +0000 (UTC) Date: Thu, 3 Nov 2016 18:01:59 +0000 (UTC) From: "James Taylor (JIRA)" To: dev@phoenix.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (PHOENIX-3437) Calcite allows CURRENT VALUE to be called on a sequence which has not yet been used MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Thu, 03 Nov 2016 18:02:01 -0000 [ 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 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)