Uploaded image for project: 'Pig'
  1. Pig
  2. PIG-2828

Handle nulls in DataType.compare

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 0.12.0
    • None
    • None
    • Reviewed

    Description

      While using TOP, and if the DataBag contains null value to compare, it will generate the following exception:

      Caused by: java.lang.NullPointerException
      at org.apache.pig.data.DataType.compare(DataType.java:427)
      at org.apache.pig.builtin.TOP$TupleComparator.compare(TOP.java:97)
      at org.apache.pig.builtin.TOP$TupleComparator.compare(TOP.java:1)
      at java.util.PriorityQueue.siftUpUsingComparator(PriorityQueue.java:649)
      at java.util.PriorityQueue.siftUp(PriorityQueue.java:627)
      at java.util.PriorityQueue.offer(PriorityQueue.java:329)
      at java.util.PriorityQueue.add(PriorityQueue.java:306)
      at org.apache.pig.builtin.TOP.updateTop(TOP.java:141)
      at org.apache.pig.builtin.TOP.exec(TOP.java:116)

      code: (TOP.java, starts with line 91)
      Object field1 = o1.get(fieldNum);
      Object field2 = o2.get(fieldNum);
      if (!typeFound)

      { datatype = DataType.findType(field1); typeFound = true; }

      return DataType.compare(field1, field2, datatype, datatype);

      The reason is that if the typeFound is true , and the dataType is not null, and field1 is null, the script failed.
      So we need to judge the field1 whether is null.

      Attachments

        1. test.patch
          1.0 kB
          Haitao Yao
        2. PIG-2828-format.patch
          2 kB
          Aniket Namadeo Mokashi
        3. PIG-2828.patch
          2 kB
          Aniket Namadeo Mokashi
        4. DataType.patch
          0.6 kB
          Haitao Yao

        Issue Links

          Activity

            People

              aniket486 Aniket Namadeo Mokashi
              haitao.yao Haitao Yao
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: