本文整理汇总了Java中cascading.tuple.Fields.size方法的典型用法代码示例。如果您正苦于以下问题:Java Fields.size方法的具体用法?Java Fields.size怎么用?Java Fields.size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cascading.tuple.Fields
的用法示例。
在下文中一共展示了Fields.size方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: coerceToString
import cascading.tuple.Fields; //导入方法依赖的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;
}
示例2: testSchemeFields
import cascading.tuple.Fields; //导入方法依赖的package包/类
/**
* Helper method used for assertion of fields generated by CsvScheme.
*/
@SuppressWarnings("unchecked")
private void testSchemeFields(String sourcePath, CsvScheme sourceSchema, String sinkPath, CsvScheme sinkScheme, Set<String> expected) {
Tap source = new Hfs(sourceSchema, sourcePath);
Tap sink = new Hfs(sinkScheme, sinkPath);
Pipe pipe = new Pipe("pipe");
FlowConnector connector = new Hadoop2MR1FlowConnector();
connector.connect(source, sink, pipe).complete();
Fields sinkFields = sink.getSinkFields();
for (int i = 0; i < sinkFields.size(); i++) {
assertTrue("Unexpected column " + sinkFields.get(i), expected.contains(sinkFields.get(i)));
expected.remove(sinkFields.get(i));
}
assertTrue("Not all expected values are found", expected.isEmpty());
}
示例3: newStructTypeInfo
import cascading.tuple.Fields; //导入方法依赖的package包/类
static StructTypeInfo newStructTypeInfo(Fields fields) {
List<String> names = new ArrayList<>();
List<TypeInfo> typeInfos = new ArrayList<>();
for (int i = 0; i < fields.size(); i++) {
String name = fields.get(i).toString();
if (ROW_ID_NAME.equals(name)) {
if (!fields.getTypeClass(i).equals(RecordIdentifier.class)) {
throw new IllegalArgumentException(ROW_ID_NAME + " column is not of type "
+ RecordIdentifier.class.getSimpleName() + ". Found type: " + fields.getTypeClass(i));
}
continue;
}
names.add(name.toLowerCase());
Class<?> type = fields.getTypeClass(i);
if (type == null) {
throw new IllegalArgumentException("Missing type information for field: " + name);
}
TypeInfo typeInfo = getTypeInfoFromClass(type);
typeInfos.add(typeInfo);
}
return (StructTypeInfo) TypeInfoFactory.getStructTypeInfo(names, typeInfos);
}
示例4: asStrings
import cascading.tuple.Fields; //导入方法依赖的package包/类
static List<String> asStrings(Fields fields) {
if (fields == null || !fields.isDefined()) {
// use auto-generated name
return Collections.emptyList();
}
int size = fields.size();
List<String> names = new ArrayList<String>(size);
for (int fieldIndex = 0; fieldIndex < size; fieldIndex++) {
names.add(fields.get(fieldIndex).toString());
}
return names;
}
示例5: TupleTypeInfo
import cascading.tuple.Fields; //导入方法依赖的package包/类
public TupleTypeInfo(Fields schema) {
super(Tuple.class);
this.schema = schema;
this.fieldIndexes = new HashMap<String, Integer>();
if(schema.isDefined()) {
this.length = schema.size();
this.fieldTypes = new LinkedHashMap<String, FieldTypeInfo>(this.length);
Comparator[] comps = schema.getComparators();
Class[] typeClasses = schema.getTypesClasses();
for(int i=0; i<length; i++) {
String fieldName = getFieldName(i);
FieldTypeInfo fieldType = getFieldTypeInfo(i, typeClasses, comps);
this.fieldTypes.put(fieldName, fieldType);
this.fieldIndexes.put(fieldName, i);
}
}
else {
if(schema.isUnknown()) {
this.length = -1;
this.fieldTypes = new LinkedHashMap<String, FieldTypeInfo>(16);
this.fieldTypes.put("0", new FieldTypeInfo());
this.fieldIndexes.put("0", 0);
}
else {
throw new IllegalArgumentException("Unsupported Fields: "+schema);
}
}
}
示例6: DefinedTupleSerializer
import cascading.tuple.Fields; //导入方法依赖的package包/类
public DefinedTupleSerializer(Fields fields, TypeSerializer[] fieldSers) {
if(!fields.isDefined()) {
throw new RuntimeException("DefinedTupleSerializer requires defined Fields schema");
}
if(fieldSers == null || fieldSers.length != fields.size()) {
throw new RuntimeException("Exactly one field serializer required for each tuple field.");
}
this.fields = fields;
this.fieldSers = fieldSers;
this.length = fields.size();
this.nullFields = new boolean[this.length];
}
示例7: checkFields
import cascading.tuple.Fields; //导入方法依赖的package包/类
static void checkFields(Fields fields) {
if (fields == null) {
throw new IllegalArgumentException("fields == null");
}
if (fields.size() != 1) {
throw new IllegalArgumentException("You may only specify a single field: " + fields);
}
if (fields.getTypes() == null) {
throw new IllegalArgumentException("Fields must declare types: " + fields);
}
if (fields.getTypeClass(0) == null) {
throw new IllegalArgumentException("Fields must declare types: " + fields);
}
}
示例8: TupleComparator
import cascading.tuple.Fields; //导入方法依赖的package包/类
TupleComparator(Fields declaredFields, Fields sortFields) {
if (Fields.merge(declaredFields, sortFields).size() != declaredFields.size()) {
throw new IllegalArgumentException("Declared fields must contain sort fields: sortFields=" + sortFields
+ ", declaredFields=" + declaredFields);
}
this.declaredFields = declaredFields;
this.sortFields = sortFields;
}
示例9: tupleEntry
import cascading.tuple.Fields; //导入方法依赖的package包/类
public static Matcher<TupleEntry> tupleEntry(Fields fields, Tuple tuple) {
if (fields.size() != tuple.size()) {
throw new IllegalArgumentException("Fields size (" + fields.size() + ") does not match tuple size ("
+ tuple.size() + ")");
}
return tupleEntry(new TupleEntry(fields, tuple));
}
示例10: validateValues
import cascading.tuple.Fields; //导入方法依赖的package包/类
/**
* Validates that the passed values can be converted to the types in the passed {@link Fields Fields} but only in
* cases where the creation of a {@link Tuple Tuple} wouldn't throw an Exception (i.e. we are stricter than Cascading
* in order to reduce hard to debug type-related errors in tests). For example Cascading will coerce a null or a "4"
* to the boolean false which Plunger won't allow.
*
* @param fields Fields containing the expected types.
* @param values Values to be validated against the expected types.
* @return values or an Object[] with length of fields.size() when values is empty or null.
* @throws IllegalStateException if the validation fails in any way.
*/
static Object[] validateValues(Fields fields, Object... values) {
if (values == null || values.length == 0) {
values = new Object[fields.size()];
} else if (values.length != fields.size()) {
throw new IllegalStateException("Value array length not suitable for fields: " + fields);
}
for (int i = 0; i < values.length; i++) {
Class<?> typeClass = fields.getTypeClass(i);
if (typeClass != null) {
Object value = values[i];
if (typeClass.isPrimitive() && value == null) {
throw new IllegalStateException("null cannot be converted to " + typeClass);
}
if (typeClass.isPrimitive() && value != null) {
Class<?> nonPrimitiveTypeClass = Coercions.asNonPrimitive(typeClass);
Class<?> nonPrimitiveValueClass = Coercions.asNonPrimitive(value.getClass());
if (!nonPrimitiveTypeClass.isAssignableFrom(nonPrimitiveValueClass)) {
throw new IllegalStateException(value.getClass() + " cannot be converted to " + typeClass);
}
}
}
}
return values;
}
示例11: DataBuilder
import cascading.tuple.Fields; //导入方法依赖的package包/类
/**
* Constructs a new tuple source builder that will provide {@link Tuple Tuples} that contain values consistent with
* the declared {@link Fields}. Adding tuples will also coerce types.
*/
public DataBuilder(Fields fields, Class<?>[] types) {
this.fields = fields;
fieldMask = fields;
this.types = types;
list = new ArrayList<Tuple>();
if (types != null && types.length != fields.size()) {
throw new IllegalArgumentException("There must be the same number of types as fields");
}
}
示例12: checkFields
import cascading.tuple.Fields; //导入方法依赖的package包/类
private static final void checkFields(Fields fields) {
if (fields == null || fields.size() <= 0) {
throw new IllegalArgumentException("Invalid fields: " + fields);
}
}