本文整理汇总了Java中cascading.tuple.Tuple类的典型用法代码示例。如果您正苦于以下问题:Java Tuple类的具体用法?Java Tuple怎么用?Java Tuple使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Tuple类属于cascading.tuple包,在下文中一共展示了Tuple类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: write
import cascading.tuple.Tuple; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Result write(SinkCall<Object[], ?> sinkCall, Generator generator) {
Tuple tuple = CascadingUtils.coerceToString(sinkCall);
// consider names (in case of aliases these are already applied)
List<String> names = (List<String>) sinkCall.getContext()[0];
generator.writeBeginObject();
for (int i = 0; i < tuple.size(); i++) {
String name = (i < names.size() ? names.get(i) : "tuple" + i);
// filter out fields
if (shouldKeep(generator.getParentPath(), name)) {
generator.writeFieldName(name);
Object object = tuple.getObject(i);
Result result = jdkWriter.write(object, generator);
if (!result.isSuccesful()) {
if (object instanceof Writable) {
return writableWriter.write((Writable) object, generator);
}
return Result.FAILED(object);
}
}
}
generator.writeEndObject();
return Result.SUCCESFUL();
}
示例2: coerceToString
import cascading.tuple.Tuple; //导入依赖的package包/类
static Tuple coerceToString(SinkCall<?, ?> sinkCall) {
TupleEntry entry = sinkCall.getOutgoingEntry();
Fields fields = entry.getFields();
Tuple tuple = entry.getTuple();
if (fields.hasTypes()) {
Type types[] = new Type[fields.size()];
for (int index = 0; index < fields.size(); index++) {
Type type = fields.getType(index);
if (type instanceof CoercibleType<?>) {
types[index] = String.class;
}
else {
types[index] = type;
}
}
tuple = entry.getCoercedTuple(types);
}
return tuple;
}
示例3: convert
import cascading.tuple.Tuple; //导入依赖的package包/类
@Override
public void convert(Object from, BytesArray to) {
// expect a tuple holding one field - chararray or bytearray
Assert.isTrue(from instanceof SinkCall,
String.format("Unexpected object type, expecting [%s], given [%s]", SinkCall.class, from.getClass()));
// handle common cases
SinkCall sinkCall = (SinkCall) from;
Tuple rawTuple = sinkCall.getOutgoingEntry().getTuple();
if (rawTuple == null || rawTuple.isEmpty()) {
to.bytes("{}");
return;
}
Assert.isTrue(rawTuple.size() == 1, "When using JSON input, only one field is expected");
// postpone the coercion
Tuple tuple = CascadingUtils.coerceToString(sinkCall);
super.convert(tuple.getObject(0), to);
}
示例4: translateSource
import cascading.tuple.Tuple; //导入依赖的package包/类
private DataSet<Tuple> translateSource(FlowProcess flowProcess, ExecutionEnvironment env, FlowNode node, int dop) {
Tap tap = this.getSingle(node.getSourceTaps());
JobConf tapConfig = new JobConf(this.getNodeConfig(node));
tap.sourceConfInit(flowProcess, tapConfig);
tapConfig.set( "cascading.step.source", Tap.id( tap ) );
Fields outFields = tap.getSourceFields();
registerKryoTypes(outFields);
JobConf sourceConfig = new JobConf(this.getNodeConfig(node));
MultiInputFormat.addInputFormat(sourceConfig, tapConfig);
DataSet<Tuple> src = env
.createInput(new TapInputFormat(node), new TupleTypeInfo(outFields))
.name(tap.getIdentifier())
.setParallelism(dop)
.withParameters(FlinkConfigConverter.toFlinkConfig(new Configuration(sourceConfig)));
return src;
}
示例5: readCharPredicatePushdown
import cascading.tuple.Tuple; //导入依赖的package包/类
@Test
public void readCharPredicatePushdown() throws IOException {
TypeInfo typeInfo = TypeInfoFactory.getCharTypeInfo(3);
try (OrcWriter writer = getOrcWriter(typeInfo)) {
writer.addRow(new HiveChar("foo", 3));
writer.addRow(new HiveChar("bar", 3));
}
StructTypeInfo structTypeInfo = new StructTypeInfoBuilder().add("a", typeInfo).build();
SearchArgument searchArgument = SearchArgumentFactory
.newBuilder()
.startAnd()
.equals("a", new HiveChar("foo", 5))
.end()
.build();
OrcFile orcFile = OrcFile.source().columns(structTypeInfo).schemaFromFile().searchArgument(searchArgument).build();
Tap<?, ?, ?> tap = new Hfs(orcFile, path);
List<Tuple> list = Plunger.readDataFromTap(tap).asTupleList();
assertThat(list.size(), is(1));
assertThat(list.get(0).getObject(0), is((Object) "foo"));
}
示例6: prepareGroupByInput
import cascading.tuple.Tuple; //导入依赖的package包/类
private DataSet<Tuple> prepareGroupByInput(List<DataSet<Tuple>> inputs, FlowNode node) {
DataSet<Tuple> merged = null;
for(int i=0; i<inputs.size(); i++) {
// get Flink DataSet
DataSet<Tuple> input = inputs.get(i);
if(merged == null) {
merged = input;
}
else {
merged = merged
.union(input);
}
}
return merged;
}
示例7: translateMerge
import cascading.tuple.Tuple; //导入依赖的package包/类
private DataSet<Tuple> translateMerge(List<DataSet<Tuple>> inputs, FlowNode node) {
DataSet<Tuple> unioned = null;
TypeInformation<Tuple> type = null;
int maxDop = -1;
for(DataSet<Tuple> input : inputs) {
maxDop = Math.max(maxDop, ((Operator)input).getParallelism());
if(unioned == null) {
unioned = input;
type = input.getType();
}
else {
unioned = unioned.union(input);
}
}
return unioned.map(new IdMapper())
.returns(type)
.setParallelism(maxDop);
}
示例8: deserialize
import cascading.tuple.Tuple; //导入依赖的package包/类
@Override
public Tuple[] deserialize(Tuple[] reuse, DataInputView source) throws IOException {
// read null mask
NullMaskSerDeUtils.readNullMask(this.nullFields, this.fillLength, source);
// read non-null fields
for (int i = 0; i < this.fillLength; i++) {
if(!this.nullFields[i]) {
reuse[i] = tupleSerializers[i].deserialize(source);
}
else {
reuse[i] = null;
}
}
return reuse;
}
示例9: writeNullMask
import cascading.tuple.Tuple; //导入依赖的package包/类
public static void writeNullMask(
Tuple t, DataOutputView target) throws IOException {
final int length = t.size();
int b;
int bytePos;
for(int fieldPos = 0; fieldPos < length; ) {
b = 0x00;
// set bits in byte
for(bytePos = 0; bytePos < 8 && fieldPos < length; bytePos++, fieldPos++) {
b = b << 1;
// set bit if field is null
if(t.getObject(fieldPos) == null) {
b |= 0x01;
}
}
// shift bits if last byte is not completely filled
for(; bytePos < 8; bytePos++) {
b = b << 1;
}
// write byte
target.writeByte(b);
}
}
示例10: run
import cascading.tuple.Tuple; //导入依赖的package包/类
@Override
public void run(Object input) {
Iterator<Tuple2<Tuple, Tuple[]>> iterator;
try {
iterator = (Iterator<Tuple2<Tuple, Tuple[]>>) input;
}
catch(ClassCastException cce) {
throw new RuntimeException("CoGroupInGate requires Iterator<Tuple2<Tuple, Tuple[]>", cce);
}
resultIterator.reset(iterator);
resultIterator.hasNext(); // load first element into closure
tupleEntryIterator.reset(resultIterator);
keyEntry.setTuple( this.closure.getGroupTuple(null) );
next.receive( this, grouping );
}
示例11: hash
import cascading.tuple.Tuple; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public int hash(Tuple value) {
if(!areKeysAbs) {
makeKeysAbs(keyPositions, value.size());
areKeysAbs = true;
}
int code = this.comparators[0].hash(value.getObject(keyPositions[0]));
for (int i = 1; i < this.keyPositions.length; i++) {
code *= HASH_SALT[i & 0x1F]; // salt code with (i % HASH_SALT.length)-th salt component
code += this.comparators[i].hash(value.getObject(keyPositions[i]));
}
return code;
}
示例12: compare
import cascading.tuple.Tuple; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public int compare(Tuple first, Tuple second) {
if(!areKeysAbs) {
makeKeysAbs(keyPositions, first.size());
areKeysAbs = true;
}
for (int i=0; i<keyPositions.length; i++) {
int cmp = comparators[i].compare(first.getObject(keyPositions[i]), second.getObject(keyPositions[i]));
if (cmp != 0) {
return cmp;
}
}
return 0;
}
示例13: putNormalizedKey
import cascading.tuple.Tuple; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void putNormalizedKey(Tuple value, MemorySegment target, int offset, int numBytes) {
if(!areKeysAbs) {
makeKeysAbs(keyPositions, value.size());
areKeysAbs = true;
}
int i = 0;
for (; i < this.numLeadingNormalizableKeys && numBytes > 0; i++) {
int len = this.normalizedKeyLengths[i];
len = numBytes >= len ? len : numBytes;
this.comparators[i].putNormalizedKey(value.getObject(keyPositions[i]), target, offset, len);
numBytes -= len;
offset += len;
}
}
示例14: copy
import cascading.tuple.Tuple; //导入依赖的package包/类
@Override
public Tuple copy(Tuple from) {
Tuple target = Tuple.size(from.size());
for (int i = 0; i < from.size(); i++) {
try {
Object orig = from.getObject(i);
if (orig != null) {
target.set(i, fieldSers[i].copy(orig));
}
else {
target.set(i, null);
}
}
catch(ClassCastException cce) {
throw new FlowException("Unexpected type of field \""+fields.get(i)+"\" encountered. " +
"Should have been "+fields.getType(i)+" but was "+from.getObject(i).getClass()+".", cce);
}
}
return target;
}
示例15: serialize
import cascading.tuple.Tuple; //导入依赖的package包/类
@Override
public void serialize(Tuple value, DataOutputView target) throws IOException {
// write null mask
NullMaskSerDeUtils.writeNullMask(value, target);
for (int i = 0; i < value.size(); i++) {
Object o = value.getObject(i);
if(o != null) {
try {
fieldSers[i].serialize(o, target);
}
catch(ClassCastException cce) {
throw new FlowException("Unexpected type of field \""+fields.get(i)+"\" encountered. " +
"Should have been "+fields.getType(i)+" but was "+o.getClass()+".", cce);
}
}
}
}