private static DataType resolveOutputType(List<DataType> types) { DataType ret = null; for (DataType type : types) { if (!(type instanceof CollectionDataType)) { return DataType.STRING; } if (ret == null) { ret = type; } else if (!ret.isAssignableFrom(type)) { return DataType.STRING; } } return ret; }
private boolean compatibleTypes(DataType summaryType, DataType existingType) { if (summaryType instanceof TensorDataType && existingType instanceof TensorDataType) { return summaryType.isAssignableFrom(existingType); // TODO: Just do this for all types } return summaryType.equals(existingType); }
private static boolean compatibleTypes(DataType seenType, DataType fieldType) { // legacy tag field type compatibility; probably not needed any more (Oct 2016) if ("tag".equals(seenType.getName())) { return "tag".equals(fieldType.getName()) || "WeightedSet<string>".equals(fieldType.getName()); } if ("tag".equals(fieldType.getName())) { return "tag".equals(seenType.getName()) || "WeightedSet<string>".equals(seenType.getName()); } if (seenType instanceof TensorDataType && fieldType instanceof TensorDataType) { return fieldType.isAssignableFrom(seenType); // TODO: Just do this for all types } return seenType.equals(fieldType); }
private static DataType resolveInputType(Collection<? extends StatementExpression> list) { DataType prev = null; for (Expression exp : list) { DataType next = exp.requiredInputType(); if (prev == null) { prev = next; } else if (next != null && !prev.isAssignableFrom(next)) { throw new VerificationException(ScriptExpression.class, "Statements require conflicting input types, " + prev.getName() + " vs " + next.getName() + "."); } } return prev; }
private static DataType resolveInputType(Collection<? extends Expression> list) { DataType prev = null; for (Expression exp : list) { DataType next = exp.requiredInputType(); if (next == null) { // ignore } else if (prev == null) { prev = next; } else if (!prev.isAssignableFrom(next)) { throw new VerificationException(CatExpression.class, "Operands require conflicting input types, " + prev.getName() + " vs " + next.getName() + "."); } } return prev; }
@Override public void tryOutputType(Expression exp, String fieldName, DataType valueType) { Field field = output.getDataType().getField(fieldName); if (field == null) { throw new VerificationException(exp, "Field '" + fieldName + "' not found."); } DataType fieldType = field.getDataType(); if (!fieldType.isAssignableFrom(valueType)) { throw new VerificationException(exp, "Can not assign " + valueType.getName() + " to field '" + fieldName + "' which is " + fieldType.getName() + "."); } }
throw new UnsupportedOperationException(); if ( ! fieldType.isAssignableFrom(valueType) && ! fieldType.isAssignableFrom(createCompatType(valueType))) { throw new VerificationException(exp, "Can not assign " + valueType.getName() + " to " + fieldDesc + " '" + fieldName + "' which is " + fieldType.getName() + ".");
throw new VerificationException(this, "Failed to resolve input type."); if (!inputType.isAssignableFrom(input)) { throw new VerificationException(this, "Expected " + inputType.getName() + " input, got " + input.getName() + "."); throw new VerificationException(this, "Failed to resolve output type."); if (!outputType.isAssignableFrom(output)) { throw new VerificationException(this, "Expected " + outputType.getName() + " output, got " + output.getName() + ".");
@Override protected void doVerify(VerificationContext context) { DataType input = context.getValue(); if (input instanceof ArrayDataType || input instanceof WeightedSetDataType) { context.setValue(((CollectionDataType)input).getNestedType()).execute(exp); if (input instanceof ArrayDataType) { context.setValue(DataType.getArray(context.getValue())); } else { WeightedSetDataType wset = (WeightedSetDataType)input; context.setValue(DataType.getWeightedSet(context.getValue(), wset.createIfNonExistent(), wset.removeIfZero())); } } else if (input instanceof StructDataType) { for (Field field : ((StructDataType)input).getFields()) { DataType fieldType = field.getDataType(); DataType valueType = context.setValue(fieldType).execute(exp).getValue(); if (!fieldType.isAssignableFrom(valueType)) { throw new VerificationException(this, "Expected " + fieldType.getName() + " output, got " + valueType.getName() + "."); } } context.setValue(input); } else { throw new VerificationException(this, "Expected Array, Struct or WeightedSet input, got " + input.getName() + "."); } }