Package org.apache.flink.types

Examples of org.apache.flink.types.Value


  public StringValueParser parser = new StringValueParser();
 
  @Test
  public void testGetValue() {
    Value v = parser.createValue();
    assertTrue(v instanceof StringValue);
  }
View Full Code Here


 
  @Override
  public void writeRecord(Record record) throws IOException {
    try {
      for (int x = 0; x < record.getNumFields(); x++) {
        Value temp = record.getField(x, fieldClasses[x]);
        addValue(x + 1, temp);
      }
      upload.addBatch();
      batchCount++;
      if(batchCount >= batchInterval) {
View Full Code Here

    int readPos;

    for (int i = 0; i < this.numFields; i++) {
      readPos = this.recordPositions[i];
      if (readPos < numRecFields) {
        Value v = record.getField(this.recordPositions[i], this.classes[i]);
        if (v != null) {
          if (i != 0) {
            this.wrt.write(this.fieldDelimiter);
          }
          this.wrt.write(v.toString());
        } else {
          if (this.lenient) {
            if (i != 0) {
              this.wrt.write(this.fieldDelimiter);
            }
View Full Code Here

        execute(iteration.getTerminationCriterion(), superstep);
      }
     
      // evaluate the aggregator convergence criterion
      if (convCriterion != null && convCriterionAggName != null) {
        Value v = aggregators.get(convCriterionAggName).getAggregate();
        if (convCriterion.isConverged(superstep, v)) {
          break;
        }
      }
     
View Full Code Here

    if (aggregates == null) {
      // we have read the binary data, but not yet turned into the objects
      final int num = aggNames.length;
      aggregates = new Value[num];
      for (int i = 0; i < num; i++) {
        Value v;
        try {
          Class<? extends Value> valClass = Class.forName(classNames[i], true, classResolver).asSubclass(Value.class);
          v = InstantiationUtil.instantiate(valClass, Value.class);
        }
        catch (ClassNotFoundException e) {
          throw new RuntimeException("Could not load user-defined class '" + classNames[i] + "'.", e);
        }
        catch (ClassCastException e) {
          throw new RuntimeException("User-defined aggregator class is not a value sublass.");
        }
       
        DataInputStream in = new DataInputStream(new ByteArrayInputStream(serializedData[i]));
        try {
          v.read(new InputViewDataInputStreamWrapper(in));
          in.close();
        } catch (IOException e) {
          throw new RuntimeException("Error while deserializing the user-defined aggregate class.", e);
        }
       
View Full Code Here

      Aggregator<Value> aggregator = (Aggregator<Value>) aggregators.get(convergenceAggregatorName);
      if (aggregator == null) {
        throw new RuntimeException("Error: Aggregator for convergence criterion was null.");
      }
     
      Value aggregate = aggregator.getAggregate();

      if (convergenceCriterion.isConverged(currentIteration, aggregate)) {
        if (log.isInfoEnabled()) {
          log.info(formatLogString("convergence reached after [" + currentIteration
            + "] iterations, terminating..."));
View Full Code Here

  throws Exception
  {
    // test getField(int, Class)
    for (int i = 0; i < expected.length; i++) {
      final int pos = permutation[i];
      final Value e = expected[pos];

      if (e == null) {
        final Value retrieved = rec.getField(pos, IntValue.class);
        if (retrieved != null) {
          Assert.fail("Value at position " + pos + " expected to be null in " + Arrays.toString(expected));
        }
      } else {
        final Value retrieved = rec.getField(pos, e.getClass());
        if (!(e.equals(retrieved))) {
          Assert.assertEquals("Wrong value at position " + pos + " in " + Arrays.toString(expected), e, retrieved);
        }
      }
    }
   
    // test getField(int, Value)
    for (int i = 0; i < expected.length; i++) {
      final int pos = permutation[i];
      final Value e = expected[pos];

      if (e == null) {
        final Value retrieved = rec.getField(pos, new IntValue());
        if (retrieved != null) {
          Assert.fail("Value at position " + pos + " expected to be null in " + Arrays.toString(expected));
        }
      } else {
        final Value retrieved = rec.getField(pos, e.getClass().newInstance());
        if (!(e.equals(retrieved))) {
          Assert.assertEquals("Wrong value at position " + pos + " in " + Arrays.toString(expected), e, retrieved);
        }
      }
    }
   
    // test getFieldInto(Value)
    for (int i = 0; i < expected.length; i++) {
      final int pos = permutation[i];
      final Value e = expected[pos];

      if (e == null) {
        if (rec.getFieldInto(pos, new IntValue())) {
          Assert.fail("Value at position " + pos + " expected to be null in " + Arrays.toString(expected));
        }
      } else {
        final Value retrieved = e.getClass().newInstance();
        if (!rec.getFieldInto(pos, retrieved)) {
          Assert.fail("Value at position " + pos + " expected to be not null in " + Arrays.toString(expected));
        }
       
        if (!(e.equals(retrieved))) {
View Full Code Here

 
  private static final void checkUnionedRecord(Record union, Value[] rec1fields, Value[] rec2fields)
  {
    for (int i = 0; i < Math.max(rec1fields.length, rec2fields.length); i++) {
      // determine the expected value from the value arrays
      final Value expected;
      if (i < rec1fields.length) {
        if (i < rec2fields.length) {
          expected = rec1fields[i] == null ? rec2fields[i] : rec1fields[i];
        } else {
          expected = rec1fields[i];
        }
      } else {
        expected = rec2fields[i];
      }
     
      // check value from record against expected value
      if (expected == null) {
        final Value retrieved = union.getField(i, IntValue.class);
        Assert.assertNull("Value at position " + i + " expected to be null in " +
                Arrays.toString(rec1fields) + " U " + Arrays.toString(rec2fields), retrieved);
      } else {
        final Value retrieved = union.getField(i, expected.getClass());
        Assert.assertEquals("Wrong value at position " + i + " in " +
          Arrays.toString(rec1fields) + " U " + Arrays.toString(rec2fields), expected, retrieved);
      }
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.flink.types.Value

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.