Package org.apache.crunch.types.writable

Examples of org.apache.crunch.types.writable.TupleWritable


    conf.set(CRUNCH_ORDERING_PROPERTY, Joiner.on(",").join(ordering));
  }

  @Override
  public int compare(WritableComparable a, WritableComparable b) {
    TupleWritable ta = (TupleWritable) a;
    TupleWritable tb = (TupleWritable) b;
    for (int index = 0; index < columnOrders.length; index++) {
      int order = 1;
      if (columnOrders[index].order() == Order.ASCENDING) {
        order = 1;
      } else if (columnOrders[index].order() == Order.DESCENDING) {
        order = -1;
      } else { // ignore
        continue;
      }
      if (!ta.has(index) && !tb.has(index)) {
        continue;
      } else if (ta.has(index) && !tb.has(index)) {
        return order;
      } else if (!ta.has(index) && tb.has(index)) {
        return -order;
      } else {
        BytesWritable v1 = ta.get(index);
        BytesWritable v2 = tb.get(index);
        if (v1 != v2 && (v1 != null && !v1.equals(v2))) {
          try {
            w1[index].readFields(new DataInputStream(new ByteArrayInputStream(v1.getBytes())));
            w2[index].readFields(new DataInputStream(new ByteArrayInputStream(v2.getBytes())));
          } catch (IOException e) {
View Full Code Here


  @Test
  public void testGetPartition() {
    IntWritable intWritable = new IntWritable(3);
    BytesWritable bw = new BytesWritable(WritableUtils.toByteArray(intWritable));
    TupleWritable key = new TupleWritable(new BytesWritable[] { bw });
    assertEquals(1, tupleWritableParitioner.getPartition(key, NullWritable.get(), 5));
    assertEquals(0, tupleWritableParitioner.getPartition(key, NullWritable.get(), 2));
  }
View Full Code Here

  @Test
  public void testGetPartition() {
    IntWritable intWritable = new IntWritable(3);
    BytesWritable bw = new BytesWritable(WritableUtils.toByteArray(intWritable));
    TupleWritable key = new TupleWritable(new Writable[] { bw });
    assertEquals(2, tupleWritableParitioner.getPartition(key, NullWritable.get(), 5));
    assertEquals(0, tupleWritableParitioner.getPartition(key, NullWritable.get(), 2));
  }
View Full Code Here

  @Test
  public void testGetPartition() {
    IntWritable intWritable = new IntWritable(3);
    BytesWritable bw = new BytesWritable(WritableUtils.toByteArray(intWritable));
    TupleWritable key = new TupleWritable(new Writable[] { bw });
    assertEquals(1, tupleWritableParitioner.getPartition(key, NullWritable.get(), 5));
    assertEquals(0, tupleWritableParitioner.getPartition(key, NullWritable.get(), 2));
  }
View Full Code Here

    conf.set(CRUNCH_ORDERING_PROPERTY, Joiner.on(",").join(ordering));
  }

  @Override
  public int compare(WritableComparable a, WritableComparable b) {
    TupleWritable ta = (TupleWritable) a;
    TupleWritable tb = (TupleWritable) b;
    for (int index = 0; index < columnOrders.length; index++) {
      int order = 1;
      if (columnOrders[index].order() == Order.ASCENDING) {
        order = 1;
      } else if (columnOrders[index].order() == Order.DESCENDING) {
        order = -1;
      } else { // ignore
        continue;
      }
      if (!ta.has(index) && !tb.has(index)) {
        continue;
      } else if (ta.has(index) && !tb.has(index)) {
        return order;
      } else if (!ta.has(index) && tb.has(index)) {
        return -order;
      } else {
        Writable v1 = ta.get(index);
        Writable v2 = tb.get(index);
        if (v1 != v2 && (v1 != null && !v1.equals(v2))) {
          if (v1 instanceof WritableComparable && v2 instanceof WritableComparable) {
            int cmp = ((WritableComparable) v1).compareTo((WritableComparable) v2);
            if (cmp != 0) {
              return order * cmp;
 
View Full Code Here

        })));
  }

  @Override
  public int compare(WritableComparable a, WritableComparable b) {
    TupleWritable ta = (TupleWritable) a;
    TupleWritable tb = (TupleWritable) b;
    for (int index = 0; index < columnOrders.length; index++) {
      int order = 1;
      if (columnOrders[index].order() == Order.ASCENDING) {
        order = 1;
      } else if (columnOrders[index].order() == Order.DESCENDING) {
        order = -1;
      } else { // ignore
        continue;
      }
      if (!ta.has(index) && !tb.has(index)) {
        continue;
      } else if (ta.has(index) && !tb.has(index)) {
        return order;
      } else if (!ta.has(index) && tb.has(index)) {
        return -order;
      } else {
        Writable v1 = ta.get(index);
        Writable v2 = tb.get(index);
        if (v1 != v2 && (v1 != null && !v1.equals(v2))) {
          if (v1 instanceof WritableComparable && v2 instanceof WritableComparable) {
            int cmp = ((WritableComparable) v1).compareTo((WritableComparable) v2);
            if (cmp != 0) {
              return order * cmp;
 
View Full Code Here

  }

  @Test
  public void testGetPartition() {
    IntWritable intWritable = new IntWritable(3);
    TupleWritable key = new TupleWritable(new Writable[] { intWritable });
    assertEquals(3, tupleWritableParitioner.getPartition(key, NullWritable.get(), 5));
    assertEquals(1, tupleWritableParitioner.getPartition(key, NullWritable.get(), 2));
  }
View Full Code Here

  public void testGetPartition_NegativeHashValue() {
    IntWritable intWritable = new IntWritable(-3);
    // Sanity check, if this doesn't work then the premise of this test is wrong
    assertEquals(-3, intWritable.hashCode());

    TupleWritable key = new TupleWritable(new Writable[] { intWritable });
    assertEquals(3, tupleWritableParitioner.getPartition(key, NullWritable.get(), 5));
    assertEquals(1, tupleWritableParitioner.getPartition(key, NullWritable.get(), 2));
  }
View Full Code Here

  public void testGetPartition_IntegerMinValue() {
    IntWritable intWritable = new IntWritable(Integer.MIN_VALUE);
    // Sanity check, if this doesn't work then the premise of this test is wrong
    assertEquals(Integer.MIN_VALUE, intWritable.hashCode());

    TupleWritable key = new TupleWritable(new Writable[] { intWritable });
    assertEquals(0, tupleWritableParitioner.getPartition(key, NullWritable.get(), Integer.MAX_VALUE));
  }
View Full Code Here

          })));
    }

    @Override
    public int compare(WritableComparable a, WritableComparable b) {
      TupleWritable ta = (TupleWritable) a;
      TupleWritable tb = (TupleWritable) b;
      for (int i = 0; i < columnOrders.length; i++) {
        int index = columnOrders[i].column - 1;
        int order = 1;
        if (columnOrders[i].order == Order.ASCENDING) {
          order = 1;
        } else if (columnOrders[i].order == Order.DESCENDING) {
          order = -1;
        } else { // ignore
          continue;
        }
        if (!ta.has(index) && !tb.has(index)) {
          continue;
        } else if (ta.has(index) && !tb.has(index)) {
          return order;
        } else if (!ta.has(index) && tb.has(index)) {
          return -order;
        } else {
          Writable v1 = ta.get(index);
          Writable v2 = tb.get(index);
          if (v1 != v2 && (v1 != null && !v1.equals(v2))) {
            if (v1 instanceof WritableComparable && v2 instanceof WritableComparable) {
              int cmp = ((WritableComparable) v1).compareTo((WritableComparable) v2);
              if (cmp != 0) {
                return order * cmp;
 
View Full Code Here

TOP

Related Classes of org.apache.crunch.types.writable.TupleWritable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.