Java Code Examples for cascading.tuple.TupleEntry#getObject()

The following examples show how to use cascading.tuple.TupleEntry#getObject() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TupleWriteSupport.java    From parquet-mr with Apache License 2.0 6 votes vote down vote up
@Override
public void write(TupleEntry record) {
  recordConsumer.startMessage();
  final List<Type> fields = rootSchema.getFields();

  for (int i = 0; i < fields.size(); i++) {
    Type field = fields.get(i);

    if (record == null || record.getObject(field.getName()) == null) {
      continue;
    }
    recordConsumer.startField(field.getName(), i);
    if (field.isPrimitive()) {
      writePrimitive(record, field.asPrimitiveType());
    } else {
      throw new UnsupportedOperationException("Complex type not implemented");
    }
    recordConsumer.endField(field.getName(), i);
  }
  recordConsumer.endMessage();
}
 
Example 2
Source File: ParquetValueScheme.java    From parquet-mr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void sink(FlowProcess<JobConf> fp, SinkCall<Object[], OutputCollector> sc)
    throws IOException {
  TupleEntry tuple = sc.getOutgoingEntry();

  if (tuple.size() != 1) {
    throw new RuntimeException("ParquetValueScheme expects tuples with an arity of exactly 1, but found " + tuple.getFields());
  }

  T value = (T) tuple.getObject(0);
  OutputCollector output = sc.getOutput();
  output.collect(null, value);
}
 
Example 3
Source File: ParquetScroogeSchemeTest.java    From parquet-mr with Apache License 2.0 5 votes vote down vote up
@Override
public void operate(FlowProcess flowProcess, FunctionCall functionCall) {
  TupleEntry arguments = functionCall.getArguments();
  Tuple result = new Tuple();

  Name name = (Name) arguments.getObject(0);
  result.add(name.firstName());
  result.add(name.lastName().get());
  functionCall.getOutputCollector().add(result);
}
 
Example 4
Source File: ParquetValueScheme.java    From parquet-mr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void sink(FlowProcess<? extends JobConf> fp, SinkCall<Object[], OutputCollector> sc)
    throws IOException {
  TupleEntry tuple = sc.getOutgoingEntry();

  if (tuple.size() != 1) {
    throw new RuntimeException("ParquetValueScheme expects tuples with an arity of exactly 1, but found " + tuple.getFields());
  }

  T value = (T) tuple.getObject(0);
  OutputCollector output = sc.getOutput();
  output.collect(null, value);
}
 
Example 5
Source File: TestParquetTBaseScheme.java    From parquet-mr with Apache License 2.0 5 votes vote down vote up
@Override
public void operate(FlowProcess flowProcess, FunctionCall functionCall) {
  TupleEntry arguments = functionCall.getArguments();
  Tuple result = new Tuple();

  Name name = (Name) arguments.getObject(0);
  result.add(name.getFirst_name());
  result.add(name.getLast_name());
  functionCall.getOutputCollector().add(result);
}
 
Example 6
Source File: TupleEntryMatcher.java    From plunger with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean matchesSafely(TupleEntry actual, Description description) {
  Set<Comparable<?>> actualNames = extractFieldNames(actual.getFields());
  Set<Comparable<?>> expectedNames = extractFieldNames(expected.getFields());

  Set<Comparable<?>> allNames = new HashSet<Comparable<?>>();
  allNames.addAll(actualNames);
  allNames.addAll(expectedNames);

  boolean result = true;
  for (Comparable<?> name : allNames) {
    Fields field = new Fields(name);
    if (!actual.getFields().contains(field)) {
      description.appendText(format("%s was expected, but was not present%n", name));
      result = false;
      continue;
    }
    if (!expected.getFields().contains(field)) {
      description.appendText(format("%s was not expected, but was present%n", name));
      result = false;
      continue;
    }
    int actualPos = actual.getFields().getPos(name);
    int expectedPos = expected.getFields().getPos(name);
    if (actualPos != expectedPos) {
      description.appendText(format("%s expected position was %s, but was %s%n", name, expectedPos, actualPos));
      result = false;
    }
    Type actualType = actual.getFields().getType(name);
    Type expectedType = expected.getFields().getType(name);
    if (!equal(actualType, expectedType)) {
      description.appendText(format("%s expected type was %s, but was %s%n", name, expectedType, actualType));
      result = false;
      continue;
    }
    Object actualValue = actual.getObject(name);
    Object expectedValue = expected.getObject(name);
    if (!equal(actualValue, expectedValue)) {
      description.appendText(format("%s expected value was '%s', but was '%s'%n", name, expectedValue, actualValue));
      result = false;
    }
  }
  return result;
}