phoenix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Loknath Priyatham Teja Singamsetty (JIRA)" <>
Subject [jira] [Created] (PHOENIX-3867) nth_value returns valid values for non-existing rows
Date Thu, 18 May 2017 12:47:05 GMT
Loknath Priyatham Teja Singamsetty  created PHOENIX-3867:

             Summary: nth_value returns valid values for non-existing rows 
                 Key: PHOENIX-3867
             Project: Phoenix
          Issue Type: Bug
    Affects Versions: 4.10.0
            Reporter: Loknath Priyatham Teja Singamsetty 
            Assignee: Loknath Priyatham Teja Singamsetty 
             Fix For: 4.11.0

Assume a table with two rows as follows:

id, page_id, date, value
2, 8 , 1 , 7
3, 8 , 2,  9 

Fetch 3rd most recent value of page_id 3 should not return any values. However,
succeeds and rs.getInt(1) returns 0 and the assertion fails. Below is the test case depicting
the same. 

a) From sqline, the 3rd nth_value is returned as null
b) When programatically accessed, it is coming as 0

Test Case:

    public void nonExistingNthRowTestWithGroupBy() throws Exception {
        Connection conn = DriverManager.getConnection(getUrl());

        String nthValue = generateUniqueName();
        String ddl = "CREATE TABLE IF NOT EXISTS " + nthValue + " "
                + "(id INTEGER NOT NULL PRIMARY KEY, page_id UNSIGNED_LONG,"
                + " dates INTEGER, val INTEGER)";

            "UPSERT INTO " + nthValue + " (id, page_id, dates, val) VALUES (2, 8, 1, 7)");
            "UPSERT INTO " + nthValue + " (id, page_id, dates, val) VALUES (3, 8, 2, 9)");

        ResultSet rs = conn.createStatement().executeQuery(
            "SELECT NTH_VALUE(val, 3) WITHIN GROUP (ORDER BY dates DESC) FROM " + nthValue
                + " GROUP BY page_id");

        assertEquals(rs.getInt(1), 4);

Root Cause:
The underlying issue seems to be with the way NTH_Value aggregation is done by the aggregator.
The client aggregator is first populated with the top 'n' rows (if present) and during the never gets evaluated in BaseGroupedAggregatingResultIterator to see if the
nth row is actually present or not. Once the succeeds, retrieving the value
from the result set using the row projector triggers the client aggregators evaluate() method
as part of schema.toBytes(..) which is defaulting to 0 for empty row if it is int when programmatically

This message was sent by Atlassian JIRA

View raw message