You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by "Greg Wittel (JIRA)" <ji...@apache.org> on 2011/03/04 00:24:36 UTC

[jira] Created: (HBASE-3599) Result constructor assumes input is already sorted

Result constructor assumes input is already sorted
--------------------------------------------------

                 Key: HBASE-3599
                 URL: https://issues.apache.org/jira/browse/HBASE-3599
             Project: HBase
          Issue Type: Bug
    Affects Versions: 0.90.0
            Reporter: Greg Wittel
            Priority: Minor


The Result(List<KeyValue>) and Result(KeyValue[]) constructor assume that the input is already sorted (HBASE-3073, HBASE-2753).  This works for normal use cases, but not for hand constructed Result objects (e.g. unit tests).

I encountered this when upgrading to 0.90 that some unit tests now failed due to this.  One fix is to add some documentation on the constructors that says the input MUST be sorted.  The other would be to explicitly sort the items (not so desirable).




-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (HBASE-3599) Result constructor assumes input is already sorted

Posted by "stack (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HBASE-3599?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13002766#comment-13002766 ] 

stack commented on HBASE-3599:
------------------------------

Both look good.  First looks cleaner to me.

> Result constructor assumes input is already sorted
> --------------------------------------------------
>
>                 Key: HBASE-3599
>                 URL: https://issues.apache.org/jira/browse/HBASE-3599
>             Project: HBase
>          Issue Type: Bug
>    Affects Versions: 0.90.0
>            Reporter: Greg Wittel
>            Priority: Minor
>
> The Result(List<KeyValue>) and Result(KeyValue[]) constructor assume that the input is already sorted (HBASE-3073, HBASE-2753).  This works for normal use cases, but not for hand constructed Result objects (e.g. unit tests).
> I encountered this when upgrading to 0.90 that some unit tests now failed due to this.  One fix is to add some documentation on the constructors that says the input MUST be sorted.  The other would be to explicitly sort the items (not so desirable).

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (HBASE-3599) Result constructor assumes input is already sorted

Posted by "Greg Wittel (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HBASE-3599?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13002318#comment-13002318 ] 

Greg Wittel commented on HBASE-3599:
------------------------------------

Sample Test:

{code}
@Test
public void testResultUnsotedInput() {
    List<KeyValue> inlist = new ArrayList<KeyValue>();
    byte[] rk = Bytes.toBytes("rowkey");
    byte[] fam = Bytes.toBytes("myfamily");
    inlist.add(
        new KeyValue(rk, fam, Bytes.toBytes("key1"), Bytes.toBytes(1))
    );
    inlist.add(
        new KeyValue(rk, fam, Bytes.toBytes("key2"), Bytes.toBytes(1))
    );
    inlist.add(
        new KeyValue(rk, fam, Bytes.toBytes("key103"), Bytes.toBytes(1))
    );
    //Collections.sort(inlist, KeyValue.COMPARATOR);
    Result res = new Result(inlist);
    assertTrue(res.containsColumn(fam, Bytes.toBytes("key103")));
}
{code}

> Result constructor assumes input is already sorted
> --------------------------------------------------
>
>                 Key: HBASE-3599
>                 URL: https://issues.apache.org/jira/browse/HBASE-3599
>             Project: HBase
>          Issue Type: Bug
>    Affects Versions: 0.90.0
>            Reporter: Greg Wittel
>            Priority: Minor
>
> The Result(List<KeyValue>) and Result(KeyValue[]) constructor assume that the input is already sorted (HBASE-3073, HBASE-2753).  This works for normal use cases, but not for hand constructed Result objects (e.g. unit tests).
> I encountered this when upgrading to 0.90 that some unit tests now failed due to this.  One fix is to add some documentation on the constructors that says the input MUST be sorted.  The other would be to explicitly sort the items (not so desirable).

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (HBASE-3599) Result constructor assumes input is already sorted

Posted by "stack (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HBASE-3599?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13002329#comment-13002329 ] 

stack commented on HBASE-3599:
------------------------------

Good one Greg.

Yeah, we should javadoc assumption that input is sorted.

We used to have this in the Result API:

{code}
  /**
   * Returns a sorted array of KeyValues in this Result.
   * <p>
   * Note: Sorting is done in place, so the backing array will be sorted
   * after calling this method.
   * @return sorted array of KeyValues
   */
  public KeyValue[] sorted() {
    if (isEmpty()) {
      return null;
    }
    Arrays.sort(kvs, (Comparator<KeyValue>)KeyValue.COMPARATOR);
    return kvs;
  }   
{code}

.. but removed it.

We could put back a sort method for use in the unit test scenario you describe above?

> Result constructor assumes input is already sorted
> --------------------------------------------------
>
>                 Key: HBASE-3599
>                 URL: https://issues.apache.org/jira/browse/HBASE-3599
>             Project: HBase
>          Issue Type: Bug
>    Affects Versions: 0.90.0
>            Reporter: Greg Wittel
>            Priority: Minor
>
> The Result(List<KeyValue>) and Result(KeyValue[]) constructor assume that the input is already sorted (HBASE-3073, HBASE-2753).  This works for normal use cases, but not for hand constructed Result objects (e.g. unit tests).
> I encountered this when upgrading to 0.90 that some unit tests now failed due to this.  One fix is to add some documentation on the constructors that says the input MUST be sorted.  The other would be to explicitly sort the items (not so desirable).

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (HBASE-3599) Result constructor assumes input is already sorted

Posted by "Greg Wittel (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HBASE-3599?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13002721#comment-13002721 ] 

Greg Wittel commented on HBASE-3599:
------------------------------------

In addition to the doc changes, I think a helper method might be useful.  This would also be useful in case  the expected sorting ever changes.  Depending on the API style you want a few ways might include:

{code}
// (1) Static creator method on Result class that sorts input lists/arrays
Result r = Result.createSorted(unsortedlist);

// (2) Static sort(KeyValue[]/List<KeyValue>) method on KeyValue class
Result r = new Result(KeyValue.sort(mylist...))
{code}

> Result constructor assumes input is already sorted
> --------------------------------------------------
>
>                 Key: HBASE-3599
>                 URL: https://issues.apache.org/jira/browse/HBASE-3599
>             Project: HBase
>          Issue Type: Bug
>    Affects Versions: 0.90.0
>            Reporter: Greg Wittel
>            Priority: Minor
>
> The Result(List<KeyValue>) and Result(KeyValue[]) constructor assume that the input is already sorted (HBASE-3073, HBASE-2753).  This works for normal use cases, but not for hand constructed Result objects (e.g. unit tests).
> I encountered this when upgrading to 0.90 that some unit tests now failed due to this.  One fix is to add some documentation on the constructors that says the input MUST be sorted.  The other would be to explicitly sort the items (not so desirable).

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira