test_class.file: tajo-core/src/test/java/org/apache/tajo/engine/planner/TestUniformRangePartition.java
test_class.identifier: TestUniformRangePartition
test_case.body: @Test
    public void testIncrement4() {
      Schema schema = new Schema()
          .addColumn("l_orderkey", Type.INT8)
          .addColumn("l_linenumber", Type.INT8);
  
      SortSpec [] sortSpecs = PlannerUtil.schemaToSortSpecs(schema);
  
      Tuple s = new VTuple(2);
      s.put(0, DatumFactory.createInt8(10));
      s.put(1, DatumFactory.createInt8(20));
      Tuple e = new VTuple(2);
      e.put(0, DatumFactory.createInt8(19));
      e.put(1, DatumFactory.createInt8(39));
  
      TupleRange expected = new TupleRange(sortSpecs, s, e);
  
      UniformRangePartition partitioner = new UniformRangePartition(expected, sortSpecs);
      assertEquals(200, partitioner.getTotalCardinality().longValue());
  
      Tuple range2 = partitioner.increment(s, 100, 1);
      assertEquals(15, range2.get(0).asInt4());
      assertEquals(20, range2.get(1).asInt4());
      Tuple range3 = partitioner.increment(range2, 99, 1);
      assertEquals(19, range3.get(0).asInt4());
      assertEquals(39, range3.get(1).asInt4());
    }
test_case.class_method_signature: TestUniformRangePartition.testIncrement4()
test_case.full_signature: @Test public void testIncrement4()
test_case.identifier: testIncrement4
test_case.invocations: addColumn addColumn schemaToSortSpecs put createInt8 put createInt8 put createInt8 put createInt8 assertEquals longValue getTotalCardinality increment assertEquals asInt4 get assertEquals asInt4 get increment assertEquals asInt4 get assertEquals asInt4 get
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testIncrement4()
focal_class.declarator: variableId
focal_class.modifier: private
focal_class.original_string: private int variableId;
focal_class.type: int
focal_class.var_name: variableId
focal_class.declarator: cardForEachDigit
focal_class.modifier: private
focal_class.original_string: private BigDecimal[] cardForEachDigit;
focal_class.type: BigDecimal[]
focal_class.var_name: cardForEachDigit
focal_class.declarator: colCards
focal_class.modifier: private
focal_class.original_string: private BigDecimal[] colCards;
focal_class.type: BigDecimal[]
focal_class.var_name: colCards
focal_class.file: tajo-core/src/main/java/org/apache/tajo/engine/planner/UniformRangePartition.java
focal_class.identifier: UniformRangePartition
focal_class.class_method_signature: UniformRangePartition.UniformRangePartition(TupleRange totalRange, SortSpec[] sortSpecs, boolean inclusive)
focal_class.full_signature: public  UniformRangePartition(TupleRange totalRange, SortSpec[] sortSpecs, boolean inclusive)
focal_class.identifier: UniformRangePartition
focal_class.modifiers: public
focal_class.parameters: (TupleRange totalRange, SortSpec[] sortSpecs, boolean inclusive)
focal_class.signature:  UniformRangePartition(TupleRange totalRange, SortSpec[] sortSpecs, boolean inclusive)
focal_class.class_method_signature: UniformRangePartition.UniformRangePartition(TupleRange range, SortSpec [] sortSpecs)
focal_class.full_signature: public  UniformRangePartition(TupleRange range, SortSpec [] sortSpecs)
focal_class.identifier: UniformRangePartition
focal_class.modifiers: public
focal_class.parameters: (TupleRange range, SortSpec [] sortSpecs)
focal_class.signature:  UniformRangePartition(TupleRange range, SortSpec [] sortSpecs)
focal_class.class_method_signature: UniformRangePartition.partition(int partNum)
focal_class.full_signature: @Override public TupleRange[] partition(int partNum)
focal_class.identifier: partition
focal_class.modifiers: @Override public
focal_class.parameters: (int partNum)
focal_class.return: TupleRange[]
focal_class.signature: TupleRange[] partition(int partNum)
focal_class.class_method_signature: UniformRangePartition.isOverflow(int colId, Datum last, BigDecimal inc, SortSpec [] sortSpecs)
focal_class.full_signature: public boolean isOverflow(int colId, Datum last, BigDecimal inc, SortSpec [] sortSpecs)
focal_class.identifier: isOverflow
focal_class.modifiers: public
focal_class.parameters: (int colId, Datum last, BigDecimal inc, SortSpec [] sortSpecs)
focal_class.return: boolean
focal_class.signature: boolean isOverflow(int colId, Datum last, BigDecimal inc, SortSpec [] sortSpecs)
focal_class.class_method_signature: UniformRangePartition.incrementAndGetReminder(int colId, Datum last, long inc)
focal_class.full_signature: public long incrementAndGetReminder(int colId, Datum last, long inc)
focal_class.identifier: incrementAndGetReminder
focal_class.modifiers: public
focal_class.parameters: (int colId, Datum last, long inc)
focal_class.return: long
focal_class.signature: long incrementAndGetReminder(int colId, Datum last, long inc)
focal_class.class_method_signature: UniformRangePartition.increment(final Tuple last, final long inc, final int baseDigit)
focal_class.full_signature: public Tuple increment(final Tuple last, final long inc, final int baseDigit)
focal_class.identifier: increment
focal_class.modifiers: public
focal_class.parameters: (final Tuple last, final long inc, final int baseDigit)
focal_class.return: Tuple
focal_class.signature: Tuple increment(final Tuple last, final long inc, final int baseDigit)
focal_class.superclass: extends RangePartitionAlgorithm
focal_method.body: public Tuple increment(final Tuple last, final long inc, final int baseDigit) {
      BigDecimal [] incs = new BigDecimal[last.size()];
      boolean [] overflowFlag = new boolean[last.size()];
      BigDecimal [] result;
      BigDecimal value = new BigDecimal(inc);
  
      BigDecimal [] reverseCardsForDigit = new BigDecimal[baseDigit + 1];
      for (int i = baseDigit; i >= 0; i--) {
        if (i == baseDigit) {
          reverseCardsForDigit[i] = colCards[i];
        } else {
          reverseCardsForDigit[i] = reverseCardsForDigit[i+1].multiply(colCards[i]);
        }
      }
  
      for (int i = 0; i < baseDigit; i++) {
        result = value.divideAndRemainder(reverseCardsForDigit[i + 1]);
        incs[i] = result[0];
        value = result[1];
      }
      int finalId = baseDigit;
      incs[finalId] = value;
      for (int i = finalId; i >= 0; i--) {
        if (isOverflow(i, last.get(i), incs[i], sortSpecs)) {
          if (i == 0) {
            throw new RangeOverflowException(range, last, incs[i].longValue());
          }
          long rem = incrementAndGetReminder(i, last.get(i), value.longValue());
          incs[i] = new BigDecimal(rem);
          incs[i - 1] = incs[i-1].add(new BigDecimal(1));
          overflowFlag[i] = true;
        } else {
          if (i > 0) {
            incs[i] = value;
            break;
          }
        }
      }
  
      for (int i = 0; i < incs.length; i++) {
        if (incs[i] == null) {
          incs[i] = new BigDecimal(0);
        }
      }
  
      Tuple end = new VTuple(sortSpecs.length);
      Column column;
      for (int i = 0; i < last.size(); i++) {
        column = sortSpecs[i].getSortKey();
        switch (column.getDataType().getType()) {
          case CHAR:
            if (overflowFlag[i]) {
              end.put(i, DatumFactory.createChar((char) (range.getStart().get(i).asChar() + incs[i].longValue())));
            } else {
              end.put(i, DatumFactory.createChar((char) (last.get(i).asChar() + incs[i].longValue())));
            }
            break;
          case BIT:
            if (overflowFlag[i]) {
              end.put(i, DatumFactory.createBit(
                  (byte) (range.getStart().get(i).asByte() + incs[i].longValue())));
            } else {
              end.put(i, DatumFactory.createBit((byte) (last.get(i).asByte() + incs[i].longValue())));
            }
            break;
          case INT2:
            if (overflowFlag[i]) {
              end.put(i, DatumFactory.createInt2(
                  (short) (range.getStart().get(i).asInt2() + incs[i].longValue())));
            } else {
              end.put(i, DatumFactory.createInt2((short) (last.get(i).asInt2() + incs[i].longValue())));
            }
            break;
          case INT4:
            if (overflowFlag[i]) {
              end.put(i, DatumFactory.createInt4(
                  (int) (range.getStart().get(i).asInt4() + incs[i].longValue())));
            } else {
              if (sortSpecs[i].isAscending()) {
                end.put(i, DatumFactory.createInt4((int) (last.get(i).asInt4() + incs[i].longValue())));
              } else {
                end.put(i, DatumFactory.createInt4((int) (last.get(i).asInt4() - incs[i].longValue())));
              }
            }
            break;
          case INT8:
            if (overflowFlag[i]) {
              end.put(i, DatumFactory.createInt8(
                  range.getStart().get(i).asInt8() + incs[i].longValue()));
            } else {
              end.put(i, DatumFactory.createInt8(last.get(i).asInt8() + incs[i].longValue()));
            }
            break;
          case FLOAT4:
            if (overflowFlag[i]) {
              end.put(i, DatumFactory.createFloat4(
                  range.getStart().get(i).asFloat4() + incs[i].longValue()));
            } else {
              end.put(i, DatumFactory.createFloat4(last.get(i).asFloat4() + incs[i].longValue()));
            }
            break;
          case FLOAT8:
            if (overflowFlag[i]) {
              end.put(i, DatumFactory.createFloat8(
                  range.getStart().get(i).asFloat8() + incs[i].longValue()));
            } else {
              end.put(i, DatumFactory.createFloat8(last.get(i).asFloat8() + incs[i].longValue()));
            }
            break;
          case TEXT:
            if (overflowFlag[i]) {
              end.put(i, DatumFactory.createText(((char) (range.getStart().get(i).asChars().charAt(0)
                  + incs[i].longValue())) + ""));
            } else {
              end.put(i, DatumFactory.createText(
                  ((char) ((last.get(i) instanceof NullDatum ? '0': last.get(i).asChars().charAt(0)) + incs[i].longValue())) + ""));
            }
            break;
          case DATE:
            if (overflowFlag[i]) {
              end.put(i, DatumFactory.createDate((int) (range.getStart().get(i).asInt4() + incs[i].longValue())));
            } else {
              end.put(i, DatumFactory.createDate((int) (last.get(i).asInt4() + incs[i].longValue())));
            }
            break;
          case TIME:
            if (overflowFlag[i]) {
              end.put(i, DatumFactory.createTime(range.getStart().get(i).asInt8() + incs[i].longValue()));
            } else {
              end.put(i, DatumFactory.createTime(last.get(i).asInt8() + incs[i].longValue()));
            }
            break;
          case TIMESTAMP:
            if (overflowFlag[i]) {
              end.put(i, DatumFactory.createTimeStampFromMillis(
                  range.getStart().get(i).asInt8() + incs[i].longValue()));
            } else {
              end.put(i, DatumFactory.createTimeStampFromMillis(last.get(i).asInt8() + incs[i].longValue()));
            }
            break;
          case INET4:
            byte[] ipBytes;
            if (overflowFlag[i]) {
              ipBytes = range.getStart().get(i).asByteArray();
              assert ipBytes.length == 4;
              end.put(i, DatumFactory.createInet4(ipBytes));
            } else {
              int lastVal = last.get(i).asInt4() + incs[i].intValue();
              ipBytes = new byte[4];
              Bytes.putInt(ipBytes, 0, lastVal);
              end.put(i, DatumFactory.createInet4(ipBytes));
            }
            break;
          default:
            throw new UnsupportedOperationException(column.getDataType() + " is not supported yet");
        }
      }
  
      return end;
    }
focal_method.class_method_signature: UniformRangePartition.increment(final Tuple last, final long inc, final int baseDigit)
focal_method.full_signature: public Tuple increment(final Tuple last, final long inc, final int baseDigit)
focal_method.identifier: increment
focal_method.invocations: size size multiply divideAndRemainder isOverflow get longValue incrementAndGetReminder get longValue add size getSortKey getType getDataType put createChar asChar get getStart longValue put createChar asChar get longValue put createBit asByte get getStart longValue put createBit asByte get longValue put createInt2 asInt2 get getStart longValue put createInt2 asInt2 get longValue put createInt4 asInt4 get getStart longValue isAscending put createInt4 asInt4 get longValue put createInt4 asInt4 get longValue put createInt8 asInt8 get getStart longValue put createInt8 asInt8 get longValue put createFloat4 asFloat4 get getStart longValue put createFloat4 asFloat4 get longValue put createFloat8 asFloat8 get getStart longValue put createFloat8 asFloat8 get longValue put createText charAt asChars get getStart longValue put createText get charAt asChars get longValue put createDate asInt4 get getStart longValue put createDate asInt4 get longValue put createTime asInt8 get getStart longValue put createTime asInt8 get longValue put createTimeStampFromMillis asInt8 get getStart longValue put createTimeStampFromMillis asInt8 get longValue asByteArray get getStart put createInet4 asInt4 get intValue putInt put createInet4 getDataType
focal_method.modifiers: public
focal_method.parameters: (final Tuple last, final long inc, final int baseDigit)
focal_method.return: Tuple
focal_method.signature: Tuple increment(final Tuple last, final long inc, final int baseDigit)