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; } }
public Type getType( int pos ) { if( !hasTypes() ) return null; return this.types[ pos ]; }
/** * Returns true if there are types associated with this instance. * * @return boolean */ public boolean hasTypes() { return fields.hasTypes(); }
public NestedBaseOperation( NestedCoercibleType<Node, Result> nestedCoercibleType, int numArgs, Fields fieldDeclaration ) { super( numArgs, fieldDeclaration.hasTypes() ? fieldDeclaration : fieldDeclaration.applyTypeToAll( nestedCoercibleType ) ); this.nestedCoercibleType = nestedCoercibleType; }
public NestedBaseOperation( NestedCoercibleType<Node, Result> nestedCoercibleType, Fields fieldDeclaration ) { super( fieldDeclaration.hasTypes() ? fieldDeclaration : fieldDeclaration.applyTypeToAll( nestedCoercibleType ) ); this.nestedCoercibleType = nestedCoercibleType; }
private static Fields makeFieldDeclaration( Fields fieldDeclaration ) { if( fieldDeclaration.hasTypes() ) return fieldDeclaration; return fieldDeclaration.applyTypes( Double.class ); }
/** * Returns the Type at the given position or having the fieldName. * * @param fieldName of type String or Number * @return the Type */ public Type getType( Comparable fieldName ) { if( !hasTypes() ) return null; return getType( getPos( fieldName ) ); }
public Context( Fields fieldDeclaration ) { if( fieldDeclaration.hasTypes() ) this.type = fieldDeclaration.getType( 0 ); this.canonical = Coercions.coercibleTypeFor( this.type ); }
/** Constructor SumPartials creates a new SumPartials instance. */ public SumPartials( Fields declaredFields ) { this.declaredFields = declaredFields; if( !declaredFields.hasTypes() ) throw new IllegalArgumentException( "result type must be declared " ); this.sumType = declaredFields.getType( 0 ); if( declaredFields.size() != 1 ) throw new IllegalArgumentException( "declared fields may only have one field, got: " + declaredFields ); this.canonical = Coercions.coercibleTypeFor( this.sumType ); }
private static Fields maskVoid( Fields fields, Fields mask ) { if( fields == null ) return null; if( mask == null || !fields.hasTypes() || !mask.hasTypes() ) return fields; Fields voidedKey = mask.applyTypes( Fields.size( mask.size(), Void.class ) ); fields = fields.applyTypes( voidedKey ); return fields; }
private void registerKryoTypes(Fields fields) { if(fields.hasTypes()) { Class[] fieldTypeClasses = fields.getTypesClasses(); for(Class fieldTypeClass : fieldTypeClasses) { if(!fieldTypeClass.isPrimitive() && !fieldTypeClass.equals(String.class) && !Writable.class.isAssignableFrom(fieldTypeClass)) { // register type if it is neither a primitive, String, or Writable env.getConfig().registerKryoType(fieldTypeClass); } } } }
private static Fields maskVoid( Fields fields, Fields mask ) { if( fields == null ) return null; if( mask == null || !fields.hasTypes() || !mask.hasTypes() ) return fields; Fields voidedKey = mask.applyTypes( Fields.size( mask.size(), Void.class ) ); fields = fields.applyTypes( voidedKey ); return fields; }
/** * Returns the Class for the given position value. * <p> * If the underlying value is of type {@link CoercibleType}, the result of * {@link cascading.tuple.type.CoercibleType#getCanonicalType()} will returned. * * @param fieldName of type String or Number * @return type Class */ public Class getTypeClass( Comparable fieldName ) { if( !hasTypes() ) return null; return getTypeClass( getPos( fieldName ) ); }
/** * Constructs a new instance that returns the average of the values encountered in the given fieldDeclaration field name. * * @param fieldDeclaration of type Fields */ @ConstructorProperties({"fieldDeclaration"}) public Average( Fields fieldDeclaration ) { super( 1, fieldDeclaration ); if( !fieldDeclaration.isSubstitution() && fieldDeclaration.size() != 1 ) throw new IllegalArgumentException( "fieldDeclaration may only declare 1 field, got: " + fieldDeclaration.size() ); if( fieldDeclaration.hasTypes() ) this.type = fieldDeclaration.getType( 0 ); this.canonical = Coercions.coercibleTypeFor( this.type ); }
/** * Constructor Coerce creates a new Coerce instance that will only coerce the given coerceFields Tuple values. * <p> * The given {@code coerceFields} instance must contain field type information, otherwise an * {@link IllegalArgumentException} will be thrown. * <p> * Note the resulting output Tuple will contain all the original incoming Fields. * * @param previous of type Pipe * @param coerceFields of type Fields */ @ConstructorProperties({"previous", "coerceFields"}) public Coerce( Pipe previous, Fields coerceFields ) { super( previous ); if( coerceFields == null ) throw new IllegalArgumentException( "coerceFields may not be null" ); if( !coerceFields.hasTypes() ) throw new IllegalArgumentException( "coerceFields must have field types declared" ); setTails( new Each( previous, coerceFields, new Identity( coerceFields ), Fields.REPLACE ) ); if( coerceFields.getTypes().length == 0 ) throw new IllegalArgumentException( "number of types must not be zero" ); } }
/** * Constructs a new instance that returns the fields declared in fieldDeclaration and accepts * only 1 argument. * <p> * If the given {@code fieldDeclaration} has a type, it will be used to coerce the result value. * * @param fieldDeclaration of type Fields */ @ConstructorProperties({"fieldDeclaration"}) public Sum( Fields fieldDeclaration ) { super( 1, fieldDeclaration ); if( !fieldDeclaration.isSubstitution() && fieldDeclaration.size() != 1 ) throw new IllegalArgumentException( "fieldDeclaration may only declare 1 field, got: " + fieldDeclaration.size() ); if( fieldDeclaration.hasTypes() ) this.type = fieldDeclaration.getType( 0 ); this.canonical = Coercions.coercibleTypeFor( this.type ); }
/** * Constructor JSONTextLine creates a new JSONTextLine instance for use with the * {@link cascading.flow.local.LocalFlowConnector}. * * @param mapper of ObjectMapper * @param fields of Fields * @param compressor of type Compressor, see {@link Compressors} * @param charsetName of String */ public JSONTextLine( ObjectMapper mapper, Fields fields, Compressor compressor, String charsetName ) { if( mapper != null ) this.mapper = mapper; if( fields == null ) throw new IllegalArgumentException( "fields may not be null" ); if( !fields.isDefined() ) throw new IllegalArgumentException( "fields argument must declare a single field" ); if( fields.size() != 1 ) throw new IllegalArgumentException( "may only declare a single source/sink field in the fields argument" ); fields = fields.hasTypes() ? fields : fields.applyTypes( new JSONCoercibleType( this.mapper ) ); setSinkFields( fields ); setSourceFields( fields ); setCompressor( compressor ); // throws an exception if not found setCharsetName( charsetName ); }
/** * Private utility method to map the fields to types that the underlying RDBMS can understand. * * @param fields The sink fields coming from the outer world */ private void deriveInternalSinkFields( Fields fields ) { if ( fields.hasTypes() ) { Comparable<?>[] comparables = new Comparable[ fields.size() ]; Type[] types = new Type[ fields.size() ]; for( int i = 0; i < fields.size(); i++ ) { comparables[ i ] = fields.get( i ); types[ i ] = InternalTypeMapping.findInternalType( fields.getType( i ) ); } this.internalSinkFields = new Fields( comparables, types ); } }
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; } }
public void testResolveWithTypes() { Fields selector = new Fields( "ip" ); Fields fields[] = new Fields[]{new Fields( "ip" ).applyTypes( String.class ), new Fields( "offset", "line" ).applyTypes( String.class, String.class )}; Fields resolved = Fields.resolve( selector, fields ); assertTrue( resolved.hasTypes() ); }