You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pig.apache.org by "Pradeep Kamath (JIRA)" <ji...@apache.org> on 2009/10/10 04:24:31 UTC

[jira] Created: (PIG-1014) Pig should convert COUNT(relation) to COUNT_STAR(relation) so that all records are counted without considering nullness of the fields in the records

Pig should convert COUNT(relation) to COUNT_STAR(relation) so that all records are counted without considering nullness of the fields in the records
----------------------------------------------------------------------------------------------------------------------------------------------------

                 Key: PIG-1014
                 URL: https://issues.apache.org/jira/browse/PIG-1014
             Project: Pig
          Issue Type: Bug
    Affects Versions: 0.4.0
            Reporter: Pradeep Kamath




-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PIG-1014) Pig should convert COUNT(relation) to COUNT_STAR(relation) so that all records are counted without considering nullness of the fields in the records

Posted by "Santhosh Srinivasan (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PIG-1014?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12764368#action_12764368 ] 

Santhosh Srinivasan commented on PIG-1014:
------------------------------------------

When the semantics of COUNT was changed, I thought this was communicated with the users. What is the intention of this jira?

> Pig should convert COUNT(relation) to COUNT_STAR(relation) so that all records are counted without considering nullness of the fields in the records
> ----------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: PIG-1014
>                 URL: https://issues.apache.org/jira/browse/PIG-1014
>             Project: Pig
>          Issue Type: Bug
>    Affects Versions: 0.4.0
>            Reporter: Pradeep Kamath
>


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PIG-1014) Pig should convert COUNT(relation) to COUNT_STAR(relation) so that all records are counted without considering nullness of the fields in the records

Posted by "Santhosh Srinivasan (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PIG-1014?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12764792#action_12764792 ] 

Santhosh Srinivasan commented on PIG-1014:
------------------------------------------

If the user wants to count without nulls then the user should use COUNT_STAR. One of the philosophies of Pig has been to allow users to do exactly what they want. Here, we are violating that philosophy and secondly we are second guessing the user's intention.

> Pig should convert COUNT(relation) to COUNT_STAR(relation) so that all records are counted without considering nullness of the fields in the records
> ----------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: PIG-1014
>                 URL: https://issues.apache.org/jira/browse/PIG-1014
>             Project: Pig
>          Issue Type: Bug
>    Affects Versions: 0.4.0
>            Reporter: Pradeep Kamath
>


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PIG-1014) Pig should convert COUNT(relation) to COUNT_STAR(relation) so that all records are counted without considering nullness of the fields in the records

Posted by "Pradeep Kamath (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PIG-1014?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12765658#action_12765658 ] 

Pradeep Kamath commented on PIG-1014:
-------------------------------------

To achieve 1. above, we would translate COUNT( A ) to COUNT_STAR( A ) during job compilation. Since 3. above has multiple options and does not seem to be a prevalent use case (SQL does not support it), another option is to disable it - thoughts?

> Pig should convert COUNT(relation) to COUNT_STAR(relation) so that all records are counted without considering nullness of the fields in the records
> ----------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: PIG-1014
>                 URL: https://issues.apache.org/jira/browse/PIG-1014
>             Project: Pig
>          Issue Type: Bug
>    Affects Versions: 0.4.0
>            Reporter: Pradeep Kamath
>


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PIG-1014) Pig should convert COUNT(relation) to COUNT_STAR(relation) so that all records are counted without considering nullness of the fields in the records

Posted by "Santhosh Srinivasan (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PIG-1014?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12765779#action_12765779 ] 

Santhosh Srinivasan commented on PIG-1014:
------------------------------------------

Another option is to change the implementation of COUNT to reflect the proposed semantics. If the underlying UDF is changed then the user should be notified via an information message. If the user checks the explain output then (s)he will notice COUNT_STAR and will be confused.

> Pig should convert COUNT(relation) to COUNT_STAR(relation) so that all records are counted without considering nullness of the fields in the records
> ----------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: PIG-1014
>                 URL: https://issues.apache.org/jira/browse/PIG-1014
>             Project: Pig
>          Issue Type: Bug
>    Affects Versions: 0.4.0
>            Reporter: Pradeep Kamath
>


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PIG-1014) Pig should convert COUNT(relation) to COUNT_STAR(relation) so that all records are counted without considering nullness of the fields in the records

Posted by "Pradeep Kamath (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PIG-1014?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12765192#action_12765192 ] 

Pradeep Kamath commented on PIG-1014:
-------------------------------------

The issue I see is with the implementation of COUNT today. It looks at only the first field in the bag and counts only non null values towards the result. This can lead to mysterious results. Consider a relation (A) with two fields with the following contents:
{noformat}
1 2
3 4
null 6
7 null
null null
{noformat}

If we have the following snippet:
{code}
B = group A all;
C = foreach B generate COUNT(A);
{code}

The answer is 3 which was arrived at only by considering record 1, record 2 and record 4 since the other records have null in the first position. Ironically though record 4 has null in the second position that does not prevent it from being not counted. So the result being based on the null-ness of just the first field seems somewhat arbitrary. My concern is that most users would not know that the result was arrived at *after* dropping records which had null in the first field even though they did not specify COUNT(A.$0).  Status Quo means we equate COUNT(A) to COUNT(A.$0) which is also not apparent to users.

> Pig should convert COUNT(relation) to COUNT_STAR(relation) so that all records are counted without considering nullness of the fields in the records
> ----------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: PIG-1014
>                 URL: https://issues.apache.org/jira/browse/PIG-1014
>             Project: Pig
>          Issue Type: Bug
>    Affects Versions: 0.4.0
>            Reporter: Pradeep Kamath
>


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PIG-1014) Pig should convert COUNT(relation) to COUNT_STAR(relation) so that all records are counted without considering nullness of the fields in the records

Posted by "Santhosh Srinivasan (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PIG-1014?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12765357#action_12765357 ] 

Santhosh Srinivasan commented on PIG-1014:
------------------------------------------

After a discussion with Pradeep who also graciously ran SQL queries to verify semantics, we have the following proposal:

The semantics of COUNT could be defined as:

1. COUNT( A ) is equivalent to COUNT( A.* ) and the result of COUNT( A ) will count null tuples in the relation
2. COUNT( A.$0) will not count null tuples in the relation

3. COUNT(A.($0, $1)) is equivalent to COUNT( A1.* ) where A1 is the relation containing tuples with two columns and will exhibit the behavior of statement 1

OR 

3. COUNT(A.($0, $1)) is equivalent to COUNT( A1.* ) where A1 is the relation containing tuples with two columns and will exhibit the behavior of statement 2

Point 3 needs more discussion.

Comments/thoughts/suggestions/anything else welcome.


> Pig should convert COUNT(relation) to COUNT_STAR(relation) so that all records are counted without considering nullness of the fields in the records
> ----------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: PIG-1014
>                 URL: https://issues.apache.org/jira/browse/PIG-1014
>             Project: Pig
>          Issue Type: Bug
>    Affects Versions: 0.4.0
>            Reporter: Pradeep Kamath
>


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PIG-1014) Pig should convert COUNT(relation) to COUNT_STAR(relation) so that all records are counted without considering nullness of the fields in the records

Posted by "Pradeep Kamath (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PIG-1014?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12765241#action_12765241 ] 

Pradeep Kamath commented on PIG-1014:
-------------------------------------

Here are the options we have in my mind:
1) status Quo which is confusing - so not quite an option
2) We disallow anything other than counting a single column with COUNT - So COUNT(A), COUNT(A.*), COUNT(A.($0,$1)) all would throw an error saying COUNT does not support this - I this case would COUNT_STAR be the suggestion to users? It would seem so for COUNT(A) and COUNT(A.*) not so sure for COUNT(A.($0,$1))
3) Same as 2) but instead of throwing an error, the parser replaces COUNT with COUNT_STAR - here again we need to decide what we should do with COUNT(A.($0,$1))
4) Change COUNT to look at all fields in the bag and only if all fields are null not count that towards the result - In this case, COUNT(A) and COUNT_STAR(A) will not give same results but we could document this.


> Pig should convert COUNT(relation) to COUNT_STAR(relation) so that all records are counted without considering nullness of the fields in the records
> ----------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: PIG-1014
>                 URL: https://issues.apache.org/jira/browse/PIG-1014
>             Project: Pig
>          Issue Type: Bug
>    Affects Versions: 0.4.0
>            Reporter: Pradeep Kamath
>


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PIG-1014) Pig should convert COUNT(relation) to COUNT_STAR(relation) so that all records are counted without considering nullness of the fields in the records

Posted by "Santhosh Srinivasan (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PIG-1014?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12765194#action_12765194 ] 

Santhosh Srinivasan commented on PIG-1014:
------------------------------------------

Essentially, Pradeep is pointing out an issue in the implementation of COUNT. If that is the case then COUNT has to be fixed or the semantics of COUNT has to be documented to explain the current implementation. I would vote for fixing COUNT to have the correct semantics.

> Pig should convert COUNT(relation) to COUNT_STAR(relation) so that all records are counted without considering nullness of the fields in the records
> ----------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: PIG-1014
>                 URL: https://issues.apache.org/jira/browse/PIG-1014
>             Project: Pig
>          Issue Type: Bug
>    Affects Versions: 0.4.0
>            Reporter: Pradeep Kamath
>


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PIG-1014) Pig should convert COUNT(relation) to COUNT_STAR(relation) so that all records are counted without considering nullness of the fields in the records

Posted by "Pradeep Kamath (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PIG-1014?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12764755#action_12764755 ] 

Pradeep Kamath commented on PIG-1014:
-------------------------------------

The jira is to track if it is possible to automatically convert a COUNT(relation) in the script to COUNT_STAR(relation) in the plan so that nullness of the fields in the records is not considered while returning the count. For example if a relation (A) has two fields and there is the following script snippet:
{noformat}
B = group A by $0;
C = foreach B generate group, COUNT(A);
{noformat}
This is equivalent to a count(*) after grouping on the first column in SQL. Per SQL semantics, COUNT(*) counts all records for the group without regard to the nullness of the individual fields. This behavior is achieved through COUNT_STAR built -in in pig. However COUNT built-in in pig is meant for counting a bag with a single column  (for example COUNT(A.$0)  above).  So the implementation in COUNT checks if the first field in the bag is null or not and only counts non null values. In the above script if the first column in the bag is null for any record, it does not get counted which would not be the same as the expected result for COUNT(*) in SQL. So if the compilation phase in pig can detect that the COUNT is being performed on a whole relation (rather than an individual column), it can replace the COUNT with COUNT_STAR and achieve the desired result.

> Pig should convert COUNT(relation) to COUNT_STAR(relation) so that all records are counted without considering nullness of the fields in the records
> ----------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: PIG-1014
>                 URL: https://issues.apache.org/jira/browse/PIG-1014
>             Project: Pig
>          Issue Type: Bug
>    Affects Versions: 0.4.0
>            Reporter: Pradeep Kamath
>


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PIG-1014) Pig should convert COUNT(relation) to COUNT_STAR(relation) so that all records are counted without considering nullness of the fields in the records

Posted by "Alan Gates (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PIG-1014?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12765136#action_12765136 ] 

Alan Gates commented on PIG-1014:
---------------------------------

I think I agree with Santhosh here.  While it may be unfortunate that our syntax makes it difficult to match the rather strange semantics of COUNT(x) vs COUNT(*) in SQL, I'm not sure trying to make a distinct between COUNT(A) and COUNT(A.$0) is the right solution.  This will not be obvious at all to users.  If anything, the right way to do this would be COUNT(A.*), but I'm not sure even about that.

> Pig should convert COUNT(relation) to COUNT_STAR(relation) so that all records are counted without considering nullness of the fields in the records
> ----------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: PIG-1014
>                 URL: https://issues.apache.org/jira/browse/PIG-1014
>             Project: Pig
>          Issue Type: Bug
>    Affects Versions: 0.4.0
>            Reporter: Pradeep Kamath
>


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PIG-1014) Pig should convert COUNT(relation) to COUNT_STAR(relation) so that all records are counted without considering nullness of the fields in the records

Posted by "Santhosh Srinivasan (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PIG-1014?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12764771#action_12764771 ] 

Santhosh Srinivasan commented on PIG-1014:
------------------------------------------

Is Pig trying to guess the user's intent? What if the user wanted to do count without nulls ?

> Pig should convert COUNT(relation) to COUNT_STAR(relation) so that all records are counted without considering nullness of the fields in the records
> ----------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: PIG-1014
>                 URL: https://issues.apache.org/jira/browse/PIG-1014
>             Project: Pig
>          Issue Type: Bug
>    Affects Versions: 0.4.0
>            Reporter: Pradeep Kamath
>


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PIG-1014) Pig should convert COUNT(relation) to COUNT_STAR(relation) so that all records are counted without considering nullness of the fields in the records

Posted by "Dmitriy V. Ryaboy (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PIG-1014?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12764780#action_12764780 ] 

Dmitriy V. Ryaboy commented on PIG-1014:
----------------------------------------

Santosh -- if the user wanted to do a "count without nulls in the first field" then she should COUNT(A.$0).  I think Pradeep's suggestion causes least surprise to the end user (at least, that's the behaviour I would have expected had I not seen this ticket). 

> Pig should convert COUNT(relation) to COUNT_STAR(relation) so that all records are counted without considering nullness of the fields in the records
> ----------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: PIG-1014
>                 URL: https://issues.apache.org/jira/browse/PIG-1014
>             Project: Pig
>          Issue Type: Bug
>    Affects Versions: 0.4.0
>            Reporter: Pradeep Kamath
>


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PIG-1014) Pig should convert COUNT(relation) to COUNT_STAR(relation) so that all records are counted without considering nullness of the fields in the records

Posted by "Dmitriy V. Ryaboy (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PIG-1014?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12766069#action_12766069 ] 

Dmitriy V. Ryaboy commented on PIG-1014:
----------------------------------------

A link that talks about some of the more "interesting" behaviors of NULL in SQL: http://thoughts.j-davis.com/2009/08/02/what-is-the-deal-with-nulls/

The difference between COUNT and COUNT_STAR is that COUNT_STAR counts nulls. I think this ticket boils down to the question, "what do we consider a null tuple?".  At the moment, we consider A.$0 to determine whether the tuple is null; that doesn't seem right, and surprises users. We have two options that both make sense -- a null tuple is a tuple in which all fields are null, or a null tuple is a tuple which is completely null (ie, doesn't even have any fields).  I am in favor of the first definition, which is a superset of the second.

> Pig should convert COUNT(relation) to COUNT_STAR(relation) so that all records are counted without considering nullness of the fields in the records
> ----------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: PIG-1014
>                 URL: https://issues.apache.org/jira/browse/PIG-1014
>             Project: Pig
>          Issue Type: Bug
>    Affects Versions: 0.4.0
>            Reporter: Pradeep Kamath
>


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.