Package com.datasalt.pangool.tuplemr.Criteria

Examples of com.datasalt.pangool.tuplemr.Criteria.SortElement


   * @see Order
   * @see NullOrder
   */
  public OrderBy add(String name, Order order, NullOrder nullOrder, RawComparator<?> comparator) {
    failIfFieldNamePresent(name);
    this.elements.add(new SortElement(name, order, nullOrder, comparator));
    return this;
  }
View Full Code Here


  private void initComparators() {
    TupleMRConfigBuilder.initializeComparators(context.getHadoopContext()
        .getConfiguration(), tupleMRConfig);
    customComparators = new RawComparator<?>[maxDepth + 1];
    for(int i = minDepth; i <= maxDepth; i++) {
      SortElement element = tupleMRConfig.getCommonCriteria().getElements().get(i);
      if(element.getCustomComparator() != null) {
        customComparators[i] = element.getCustomComparator();
      }
    }
  }
View Full Code Here

  public int compare(Schema schema, Criteria c, ITuple w1, int[] index1, ITuple w2,
                     int[] index2, Serializer[] serializers) {
    for (int i = 0; i < c.getElements().size(); i++) {
      Field field = schema.getField(i);
      SortElement e = c.getElements().get(i);
      Object o1 = w1.get(index1[i]);
      Object o2 = w2.get(index2[i]);

      // Handling with null values
      if (o1 == null || o2 == null) {
        int cmp = nullCompare(o1, o2, e);
        if (cmp != 0) {
          return cmp;
        } else {
          continue;
        }
      }

      // At this point we know that both values are not null.
      Serializer serializer = (serializers == null) ? null : serializers[i];
      int comparison = compareObjects(o1, o2, e.getCustomComparator(), field.getType(), serializer);
      if (comparison != 0) {
        return (e.getOrder() == Order.ASC ? comparison : -comparison);
      }
    }
    return 0;
  }
View Full Code Here

    }

    for (int depth = 0; depth < criteria.getElements().size(); depth++) {
      Field field = schema.getField(depth);
      Field.Type type = field.getType();
      SortElement sortElement = criteria.getElements().get(depth);
      Order sort = sortElement.getOrder();
      RawComparator comparator = sortElement.getCustomComparator();

      // Control for nulls, if field is nullable.
      if (field.isNullable()) {
        Criteria.NullOrder nullOrder = sortElement.getNullOrder();
        if (n.nulls1.isSet(schema.getNullablePositionFromIndex(depth))) {
          if (n.nulls2.isSet(schema.getNullablePositionFromIndex(depth))) {
            // Both are null, so both are equal. No space is used. Continue.
            continue;
          } else {
View Full Code Here

  private void initComparators() {
    TupleMRConfigBuilder.initializeComparators(context.getHadoopContext()
        .getConfiguration(), tupleMRConfig);
    customComparators = new RawComparator<?>[maxDepth + 1];
    for(int i = minDepth; i <= maxDepth; i++) {
      SortElement element = tupleMRConfig.getCommonCriteria().getElements().get(i);
      if(element.getCustomComparator() != null) {
        customComparators[i] = element.getCustomComparator();
      }
    }
  }
View Full Code Here

  public int compare(Schema schema, Criteria c, ITuple w1, int[] index1, ITuple w2,
      int[] index2,Serializer[] serializers) {
    for(int i = 0; i < c.getElements().size(); i++) {
      Field field = schema.getField(i);
      SortElement e = c.getElements().get(i);
      Object o1 = w1.get(index1[i]);
      Object o2 = w2.get(index2[i]);
      Serializer serializer = (serializers == null) ? null : serializers[i];
      int comparison = compareObjects(o1, o2, e.getCustomComparator(), field.getType(),serializer);
      if(comparison != 0) {
        return(e.getOrder() == Order.ASC ? comparison : -comparison);
      }
    }
    return 0;
  }
View Full Code Here

    o.offset1 = s1;
    o.offset2 = s2;
    for(int depth = 0; depth < criteria.getElements().size(); depth++) {
      Field field = schema.getField(depth);
      Field.Type type = field.getType();
      SortElement sortElement = criteria.getElements().get(depth);
      Order sort = sortElement.getOrder();
      RawComparator comparator = sortElement.getCustomComparator();

      if(comparator != null) {
        //custom comparator for OBJECT
        int length1 = WritableComparator.readVInt(b1, o.offset1);
        int length2 = WritableComparator.readVInt(b2, o.offset2);
View Full Code Here

    b.setSpecificOrderBy("schema1", new OrderBy().add("blabla", Order.DESC));
    TupleMRConfig config = b.buildConf();
    config.getSerializationInfo();
    {
      List<SortElement> expectedCommon = new ArrayList<SortElement>();
      expectedCommon.add(new SortElement("b", Order.ASC, Criteria.NullOrder.NULL_SMALLEST));
      expectedCommon.add(new SortElement("c", Order.DESC, Criteria.NullOrder.NULL_SMALLEST));
      Assert.assertEquals(new Criteria(expectedCommon), config.getCommonCriteria());
    }
    {
      List<SortElement> expectedSchema1 = new ArrayList<SortElement>();
      expectedSchema1.add(new SortElement("a", Order.DESC, Criteria.NullOrder.NULL_SMALLEST));
      expectedSchema1.add(new SortElement("blabla", Order.DESC, Criteria.NullOrder.NULL_SMALLEST));
      Assert.assertEquals(new Criteria(expectedSchema1), config.getSpecificOrderBys()
          .get(0));
    }
    {
      List<SortElement> expectedSchema2 = new ArrayList<SortElement>();
      expectedSchema2.add(new SortElement("a", Order.DESC, Criteria.NullOrder.NULL_SMALLEST));
      Assert.assertEquals(new Criteria(expectedSchema2), config.getSpecificOrderBys()
          .get(1));
    }

  }
View Full Code Here

    System.out.println(serInfo.getCommonSchema());
    System.out.println(serInfo.getPartitionFieldsIndexes());

    {
      List<SortElement> expectedCommon = new ArrayList<SortElement>();
      expectedCommon.add(new SortElement("b", Order.ASC, Criteria.NullOrder.NULL_SMALLEST));
      expectedCommon.add(new SortElement("c", Order.DESC, Criteria.NullOrder.NULL_SMALLEST));
      Assert.assertEquals(new Criteria(expectedCommon), config.getCommonCriteria());
    }
    {
      List<SortElement> expectedSchema1 = new ArrayList<SortElement>();
      expectedSchema1.add(new SortElement("a", Order.DESC, Criteria.NullOrder.NULL_SMALLEST));
      expectedSchema1.add(new SortElement("blabla", Order.DESC, Criteria.NullOrder.NULL_SMALLEST));
      Assert.assertEquals(new Criteria(expectedSchema1), config.getSpecificOrderBys()
          .get(0));
    }
    {
      List<SortElement> expectedSchema2 = new ArrayList<SortElement>();
      expectedSchema2.add(new SortElement("a", Order.DESC, Criteria.NullOrder.NULL_SMALLEST));
      Assert.assertEquals(new Criteria(expectedSchema2), config.getSpecificOrderBys()
          .get(1));
    }

  }
View Full Code Here

    b.setGroupByFields("c", "b");
    TupleMRConfig config = b.buildConf();
    config.getSerializationInfo();
    {
      List<SortElement> expectedCommon = new ArrayList<SortElement>();
      expectedCommon.add(new SortElement("c", Order.ASC, Criteria.NullOrder.NULL_SMALLEST));
      expectedCommon.add(new SortElement("b", Order.ASC, Criteria.NullOrder.NULL_SMALLEST));
      Assert.assertEquals(new Criteria(expectedCommon), config.getCommonCriteria());
    }
  }
View Full Code Here

TOP

Related Classes of com.datasalt.pangool.tuplemr.Criteria.SortElement

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.