public ExpressionChecker addExpr( String expression, Object expectedValue, FieldType resultFieldType) { exps.add(ExpressionTestCase.of(expression, expectedValue, resultFieldType)); return this; }
public ExpressionChecker addExpr(String expression, Object expectedValue) { TypeName resultTypeName = JAVA_CLASS_TO_TYPENAME.get(expectedValue.getClass()); checkArgument( resultTypeName != null, String.format( "The type of the expected value '%s' is unknown in 'addExpr(String expression, " + "Object expectedValue)'. Please use 'addExpr(String expr, Object expected, " + "FieldType type)' instead and provide the type of the expected object", expectedValue)); addExpr(expression, expectedValue, FieldType.of(resultTypeName)); return this; }
public void testWideningOrder(TypeName input, TypeName output) { Schema inputSchema = Schema.of(Schema.Field.of("f0", FieldType.of(input))); Schema outputSchema = Schema.of(Schema.Field.of("f0", FieldType.of(output))); List<Cast.CompatibilityError> errors = Cast.Widening.of().apply(inputSchema, outputSchema); if (NUMERIC_ORDER.indexOf(input) <= NUMERIC_ORDER.indexOf(output)) { assertThat(input + " is before " + output, errors, empty()); } else { assertThat(input + " is after " + output, errors, not(empty())); } }
/** Get a {@link FieldType} from a {@link TypeDescriptor}. */ public static FieldType fieldTypeForJavaType(TypeDescriptor typeDescriptor) { if (typeDescriptor.isArray() || typeDescriptor.isSubtypeOf(TypeDescriptor.of(Collection.class))) { return getArrayFieldType(typeDescriptor); } else if (typeDescriptor.isSubtypeOf(TypeDescriptor.of(Map.class))) { return getMapFieldType(typeDescriptor); } else if (typeDescriptor.isSubtypeOf(TypeDescriptor.of(Row.class))) { throw new IllegalArgumentException( "Cannot automatically determine a field type from a Row class" + " as we cannot determine the schema. You should set a field type explicitly."); } else { TypeName typeName = PRIMITIVE_MAPPING.inverse().get(typeDescriptor); if (typeName == null) { throw new RuntimeException("Couldn't find field type for " + typeDescriptor); } FieldType fieldType = FieldType.of(typeName); return fieldType; } }
public ExpressionChecker addExprWithNullExpectedValue( String expression, TypeName resultTypeName) { addExpr(expression, null, FieldType.of(resultTypeName)); return this; }