static void setObject(TupleEntry entry, Comparable<?> field, Object object) { if (object != null && entry.getFields().getType(field) instanceof CoercibleType) { entry.setObject(field, object.toString()); } else { entry.setObject(field, object); } }
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; } }
@ConstructorProperties({"fieldDeclaration", "expression", "parameterNames", "parameterTypes"}) protected ExpressionOperation( Fields fieldDeclaration, String expression, String[] parameterNames, Class[] parameterTypes ) { super( parameterTypes.length, fieldDeclaration, expression, asClass( fieldDeclaration.getType( 0 ) ), parameterNames, parameterTypes ); }
@ConstructorProperties({"fieldDeclaration", "expression"}) protected ExpressionOperation( Fields fieldDeclaration, String expression ) { super( ANY, fieldDeclaration, expression, asClass( fieldDeclaration.getType( 0 ) ) ); }
@ConstructorProperties({"fieldDeclaration", "expression", "parameterType"}) protected ExpressionOperation( Fields fieldDeclaration, String expression, Class parameterType ) { super( 1, fieldDeclaration, expression, asClass( fieldDeclaration.getType( 0 ) ), null, new Class[]{parameterType} ); }
public Class getTypeClass( int pos ) { Type type = getType( pos ); if( type instanceof CoercibleType ) return ( (CoercibleType) type ).getCanonicalType(); return (Class) type; }
private static List<DataField> toDataFields( Fields fields ) { List<DataField> dataFields = new ArrayList<DataField>(); for( Comparable field : fields ) { if( field instanceof Number ) throw new IllegalArgumentException( "all fields must be names, not ordinal, got: " + field ); dataFields.add( new ContinuousDataField( (String) field, fields.getType( field ) ) ); } return dataFields; }
@ConstructorProperties({"fieldDeclaration", "expression", "parameterNames", "parameterTypes"}) protected ExpressionOperation( Fields fieldDeclaration, String expression, String[] parameterNames, Class[] parameterTypes ) { super( parameterTypes.length, fieldDeclaration, expression, asClass( fieldDeclaration.getType( 0 ) ), parameterNames, parameterTypes ); }
@ConstructorProperties({"fieldDeclaration", "expression"}) protected ExpressionOperation( Fields fieldDeclaration, String expression ) { super( ANY, fieldDeclaration, expression, asClass( fieldDeclaration.getType( 0 ) ) ); }
@ConstructorProperties({"fieldDeclaration", "expression", "parameterType"}) protected ExpressionOperation( Fields fieldDeclaration, String expression, Class parameterType ) { super( 1, fieldDeclaration, expression, asClass( fieldDeclaration.getType( 0 ) ), null, new Class[]{parameterType} ); }
private static List<DataField> toDataFields( Fields fields, String[][] categories ) { List<DataField> dataFields = new ArrayList<DataField>(); for( Comparable field : fields ) { if( field instanceof Number ) throw new IllegalArgumentException( "all fields must be names, not ordinal, got: " + field ); dataFields.add( new CategoricalDataField( (String) field, fields.getType( field ), categories[ fields.getPos( field ) ] ) ); } return dataFields; }
public Expression field( BlockBuilder list, int index ) { final Type type = incomingFields.getType( index ); final String name = incomingFields.get( index ).toString(); return Expressions.parameter( type, name ); } } );
/** 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 ); }
/** * 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 ); }
static void setObject(TupleEntry entry, Comparable<?> field, Object object) { if (object != null && entry.getFields().getType(field) instanceof CoercibleType) { entry.setObject(field, object.toString()); } else { entry.setObject(field, object); } }
@Test public void testTypedSelect() { Fields declarationA = new Fields( names( "a", "b" ), types( int.class, String.class ) ); Fields selectA = new Fields( "a", "b" ); Fields got = declarationA.select( selectA ); assertEquals( "not equal: ", 2, got.size() ); assertEquals( "not equal: ", int.class, got.getType( 0 ) ); assertEquals( "not equal: ", String.class, got.getType( 1 ) ); }
@Test public void testTypedSelect2() { Fields declarationA = new Fields( names( "a", "b" ), types( int.class, String.class ) ); Fields selectA = new Fields( "b", "a" ); Fields got = declarationA.select( selectA ); assertEquals( "not equal: ", 2, got.size() ); assertEquals( "not equal: ", String.class, got.getType( 0 ) ); assertEquals( "not equal: ", int.class, got.getType( 1 ) ); }
@Test public void testTypedDiff() { Fields fieldA = new Fields( names( "a", "b" ), types( int.class, String.class ) ); Fields fieldB = new Fields( "a" ); Fields diff = fieldA.subtract( fieldB ); assertEquals( "not equal: ", 1, diff.size() ); assertEquals( "not equal: ", String.class, diff.getType( 0 ) ); }
@Test public void testTypedAppendToNone() { Fields fieldA = Fields.NONE; Fields fieldB = new Fields( names( "a" ), types( String.class ) ); Fields appended = fieldA.append( fieldB ); assertEquals( "not equal: ", 1, appended.size() ); assertEquals( "not equal: ", "a", appended.get( 0 ) ); assertEquals( "not equal: ", String.class, appended.getType( 0 ) ); }