本文整理汇总了Java中cascading.scheme.SinkCall类的典型用法代码示例。如果您正苦于以下问题:Java SinkCall类的具体用法?Java SinkCall怎么用?Java SinkCall使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SinkCall类属于cascading.scheme包,在下文中一共展示了SinkCall类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extractField
import cascading.scheme.SinkCall; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes" })
@Override
protected Object extractField(Object target) {
List<String> fieldNames = getFieldNames();
for (int i = 0; i < fieldNames.size(); i++) {
if (target instanceof SinkCall) {
target = ((SinkCall) target).getOutgoingEntry().getObject(fieldNames.get(i));
if (target == null) {
return NOT_FOUND;
}
}
else {
return NOT_FOUND;
}
}
return target;
}
示例2: write
import cascading.scheme.SinkCall; //导入依赖的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();
}
示例3: coerceToString
import cascading.scheme.SinkCall; //导入依赖的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;
}
示例4: convert
import cascading.scheme.SinkCall; //导入依赖的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);
}
示例5: sinkPrepare
import cascading.scheme.SinkCall; //导入依赖的package包/类
@Override
public void sinkPrepare( FlowProcess<? extends Configuration> flowProcess, SinkCall<Object[], OutputCollector> sinkCall ) throws IOException {
if( !( flowProcess instanceof FlowProcessWrapper ) ) {
throw new RuntimeException( "not a flow process wrapper" );
}
if( !"process-default".equals( flowProcess.getProperty( "default" ) ) ) {
throw new RuntimeException( "not default value" );
}
if( !"sink-replace".equals( flowProcess.getProperty( "replace" ) ) ) {
throw new RuntimeException( "not replaced value" );
}
flowProcess = ( (FlowProcessWrapper) flowProcess ).getDelegate();
if( !"process-default".equals( flowProcess.getProperty( "default" ) ) ) {
throw new RuntimeException( "not default value" );
}
if( !"process-replace".equals( flowProcess.getProperty( "replace" ) ) ) {
throw new RuntimeException( "not replaced value" );
}
super.sinkPrepare( flowProcess, sinkCall );
}
示例6: sinkPrepare
import cascading.scheme.SinkCall; //导入依赖的package包/类
@Override
public void sinkPrepare(final FlowProcess<JobConf> flowProcess, final SinkCall<Object[], OutputCollector> sinkCall) throws IOException {
final StringWriter stringWriter = new StringWriter(4 * 1024);
final CSVWriter csvWriter = createCsvWriter(stringWriter);
sinkCall.setContext(new Object[5]);
sinkCall.getContext()[0] = new Text();
sinkCall.getContext()[1] = stringWriter;
sinkCall.getContext()[2] = Charset.forName(charsetName);
sinkCall.getContext()[3] = csvWriter;
sinkCall.getContext()[4] = new String[getSinkFields().size()];
if (hasHeader) {
final Fields fields = sinkCall.getOutgoingEntry().getFields();
write(sinkCall, fields);
}
}
示例7: write
import cascading.scheme.SinkCall; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected void write(final SinkCall<Object[], OutputCollector> sinkCall, final Iterable<? extends Object> value) throws IOException {
final Text text = (Text) sinkCall.getContext()[0];
final StringWriter stringWriter = (StringWriter) sinkCall.getContext()[1];
final Charset charset = (Charset) sinkCall.getContext()[2];
final CSVWriter csvWriter = (CSVWriter) sinkCall.getContext()[3];
final String[] nextLine = (String[]) sinkCall.getContext()[4];
stringWriter.getBuffer().setLength(0);
int i = 0;
for (Object item: value) {
nextLine[i] = item == null ? "" : item.toString();
i++;
}
csvWriter.writeNext(nextLine);
final int l = stringWriter.getBuffer().length();
stringWriter.getBuffer().setLength(l > 0 ? l - 1 : 0);
text.set(stringWriter.getBuffer().toString().getBytes(charset));
sinkCall.getOutput().collect(null, text);
}
示例8: write
import cascading.scheme.SinkCall; //导入依赖的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()[SINK_CTX_ALIASES];
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();
}
示例9: sink
import cascading.scheme.SinkCall; //导入依赖的package包/类
@Override
public void sink(FlowProcess<JobConf> process, SinkCall<Object[], OutputCollector> sinkCall)
throws IOException {
TupleEntry tuple = sinkCall.getOutgoingEntry();
Object obj = tuple.getObject(0);
String key;
//a hack since byte[] isn't natively handled by hadoop
if (getStructure() instanceof DefaultPailStructure) {
key = getCategory(obj);
} else {
key = Utils.join(getStructure().getTarget(obj), "/") + getCategory(obj);
}
if (bw == null) { bw = new BytesWritable(); }
if (keyW == null) { keyW = new Text(); }
serialize(obj, bw);
keyW.set(key);
sinkCall.getOutput().collect(keyW, bw);
}
示例10: sinkPrepare
import cascading.scheme.SinkCall; //导入依赖的package包/类
@Override
public void sinkPrepare(FlowProcess<Properties> flowProcess, SinkCall<Object[], Object> sinkCall) throws IOException {
super.sinkPrepare(flowProcess, sinkCall);
Object[] context = new Object[1];
Settings settings = HadoopSettingsManager.loadFrom(flowProcess.getConfigCopy()).merge(props);
context[0] = CascadingUtils.fieldToAlias(settings, getSinkFields());
sinkCall.setContext(context);
}
示例11: toString
import cascading.scheme.SinkCall; //导入依赖的package包/类
@Override
public String toString(Object field) {
if (field instanceof SinkCall) {
return ((SinkCall) field).getOutgoingEntry().toString();
}
return field.toString();
}
示例12: sinkPrepare
import cascading.scheme.SinkCall; //导入依赖的package包/类
@Override
public void sinkPrepare(FlowProcess<JobConf> flowProcess, SinkCall<Object[], OutputCollector> sinkCall) throws IOException {
super.sinkPrepare(flowProcess, sinkCall);
Object[] context = new Object[1];
// the tuple is fixed, so we can just use a collection/index
Settings settings = loadSettings(flowProcess.getConfigCopy(), false);
context[0] = CascadingUtils.fieldToAlias(settings, getSinkFields());
sinkCall.setContext(context);
IS_ES_20 = SettingsUtils.isEs20(settings);
}
示例13: sink
import cascading.scheme.SinkCall; //导入依赖的package包/类
@Override
public void sink(FlowProcess<JobConf> flowProcess, SinkCall<Object, Object> sinkCall) throws IOException {
Tuple tuple = sinkCall.getOutgoingEntry().getTuple();
StringBuffer sb = new StringBuffer();
for (Object object : tuple) {
if (object instanceof Writable) {
sb.append(WritableUtils.fromWritable((Writable) object));
}
else {
sb.append(object);
}
sb.append(" ");
}
((PrintStream) sinkCall.getOutput()).println(sb.toString());
}
示例14: sinkPrepare
import cascading.scheme.SinkCall; //导入依赖的package包/类
@Override
public void sinkPrepare(FlowProcess<JobConf> flowProcess, SinkCall<Object[], OutputCollector> sinkCall) throws IOException {
initIndices();
sinkCall.setContext(new Object[2]);
sinkCall.getContext()[0] = new LongWritable();
sinkCall.getContext()[1] = new ListWritable<>(Text.class);
}
示例15: sink
import cascading.scheme.SinkCall; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public void sink(FlowProcess<JobConf> flowProcess, SinkCall<Object[], OutputCollector> sinkCall) throws IOException {
ListWritable<Text> record = (ListWritable<Text>) sinkCall.getContext()[1];
record.clear();
TupleEntry entry = sinkCall.getOutgoingEntry();
Tuple tuple = entry.getTuple();
Fields fields = getSinkFields();
for (int i = 0; i < fields.size(); i++) {
int index = indices != null ? indices.get(fields.get(i).toString()) : i;
if (record.size() < index) {
for (int j = record.size(); j < index; j++) {
record.add(null);
}
}
Object value = tuple.getObject(i);
if (value != null) {
record.add(index, new Text(value.toString()));
} else {
record.add(index, null);
}
}
sinkCall.getOutput().collect(null, record);
}