private CompatibilityAssertion assertThat(Type firstType, Type secondType) { Optional<Type> commonSuperType1 = typeRegistry.getCommonSuperType(firstType, secondType); Optional<Type> commonSuperType2 = typeRegistry.getCommonSuperType(secondType, firstType); assertEquals(commonSuperType1, commonSuperType2, "Expected getCommonSuperType to return the same result when invoked in either order"); boolean canCoerceFirstToSecond = typeRegistry.canCoerce(firstType, secondType); boolean canCoerceSecondToFirst = typeRegistry.canCoerce(secondType, firstType); return new CompatibilityAssertion(commonSuperType1, canCoerceFirstToSecond, canCoerceSecondToFirst); }
@Override public SolverReturnStatus update(BoundVariables.Builder bindings) { if (!bindings.containsTypeVariable(typeParameter)) { if (!satisfiesConstraints(actualType)) { return SolverReturnStatus.UNSOLVABLE; } bindings.setTypeVariable(typeParameter, actualType); return SolverReturnStatus.CHANGED; } Type originalType = bindings.getTypeVariable(typeParameter); Optional<Type> commonSuperType = typeManager.getCommonSuperType(originalType, actualType); if (!commonSuperType.isPresent()) { return SolverReturnStatus.UNSOLVABLE; } if (!satisfiesConstraints(commonSuperType.get())) { // This check must not be skipped even if commonSuperType is equal to originalType return SolverReturnStatus.UNSOLVABLE; } if (commonSuperType.get().equals(originalType)) { return SolverReturnStatus.UNCHANGED_SATISFIED; } bindings.setTypeVariable(typeParameter, commonSuperType.get()); return SolverReturnStatus.CHANGED; }
@Override public SolverReturnStatus update(BoundVariables.Builder bindings) { if (!bindings.containsTypeVariable(typeParameter)) { if (!satisfiesConstraints(actualType)) { return SolverReturnStatus.UNSOLVABLE; } bindings.setTypeVariable(typeParameter, actualType); return SolverReturnStatus.CHANGED; } Type originalType = bindings.getTypeVariable(typeParameter); Optional<Type> commonSuperType = typeManager.getCommonSuperType(originalType, actualType); if (!commonSuperType.isPresent()) { return SolverReturnStatus.UNSOLVABLE; } if (!satisfiesConstraints(commonSuperType.get())) { // This check must not be skipped even if commonSuperType is equal to originalType return SolverReturnStatus.UNSOLVABLE; } if (commonSuperType.get().equals(originalType)) { return SolverReturnStatus.UNCHANGED_SATISFIED; } bindings.setTypeVariable(typeParameter, commonSuperType.get()); return SolverReturnStatus.CHANGED; }
private CompatibilityAssertion assertThat(Type firstType, Type secondType) { Optional<Type> commonSuperType1 = typeRegistry.getCommonSuperType(firstType, secondType); Optional<Type> commonSuperType2 = typeRegistry.getCommonSuperType(secondType, firstType); assertEquals(commonSuperType1, commonSuperType2, "Expected getCommonSuperType to return the same result when invoked in either order"); boolean canCoerceFirstToSecond = typeRegistry.canCoerce(firstType, secondType); boolean canCoerceSecondToFirst = typeRegistry.canCoerce(secondType, firstType); return new CompatibilityAssertion(commonSuperType1, canCoerceFirstToSecond, canCoerceSecondToFirst); }
private Type coerceToSingleType(StackableAstVisitorContext<Context> context, Node node, String message, Expression first, Expression second) { Type firstType = UNKNOWN; if (first != null) { firstType = process(first, context); } Type secondType = UNKNOWN; if (second != null) { secondType = process(second, context); } // coerce types if possible Optional<Type> superTypeOptional = typeManager.getCommonSuperType(firstType, secondType); if (superTypeOptional.isPresent() && typeManager.canCoerce(firstType, superTypeOptional.get()) && typeManager.canCoerce(secondType, superTypeOptional.get())) { Type superType = superTypeOptional.get(); if (!firstType.equals(superType)) { addOrReplaceExpressionCoercion(first, firstType, superType); } if (!secondType.equals(superType)) { addOrReplaceExpressionCoercion(second, secondType, superType); } return superType; } throw new SemanticException(TYPE_MISMATCH, node, message, firstType, secondType); }
private Type coerceToSingleType(StackableAstVisitorContext<Context> context, Node node, String message, Expression first, Expression second) { Type firstType = UNKNOWN; if (first != null) { firstType = process(first, context); } Type secondType = UNKNOWN; if (second != null) { secondType = process(second, context); } // coerce types if possible Optional<Type> superTypeOptional = typeManager.getCommonSuperType(firstType, secondType); if (superTypeOptional.isPresent() && typeManager.canCoerce(firstType, superTypeOptional.get()) && typeManager.canCoerce(secondType, superTypeOptional.get())) { Type superType = superTypeOptional.get(); if (!firstType.equals(superType)) { addOrReplaceExpressionCoercion(first, firstType, superType); } if (!secondType.equals(superType)) { addOrReplaceExpressionCoercion(second, secondType, superType); } return superType; } throw new SemanticException(TYPE_MISMATCH, node, message, firstType, secondType); }
private Type coerceToSingleType(StackableAstVisitorContext<Context> context, String message, List<Expression> expressions) { // determine super type Type superType = UNKNOWN; for (Expression expression : expressions) { Optional<Type> newSuperType = typeManager.getCommonSuperType(superType, process(expression, context)); if (!newSuperType.isPresent()) { throw new SemanticException(TYPE_MISMATCH, expression, message, superType); } superType = newSuperType.get(); } // verify all expressions can be coerced to the superType for (Expression expression : expressions) { Type type = process(expression, context); if (!type.equals(superType)) { if (!typeManager.canCoerce(type, superType)) { throw new SemanticException(TYPE_MISMATCH, expression, message, superType); } addOrReplaceExpressionCoercion(expression, type, superType); } } return superType; }
@Override protected Type visitNullIfExpression(NullIfExpression node, StackableAstVisitorContext<Context> context) { Type firstType = process(node.getFirst(), context); Type secondType = process(node.getSecond(), context); if (!typeManager.getCommonSuperType(firstType, secondType).isPresent()) { throw new SemanticException(TYPE_MISMATCH, node, "Types are not comparable with NULLIF: %s vs %s", firstType, secondType); } return setExpressionType(node, firstType); }
private Type coerceToSingleType(StackableAstVisitorContext<Context> context, String message, List<Expression> expressions) { // determine super type Type superType = UNKNOWN; for (Expression expression : expressions) { Optional<Type> newSuperType = typeManager.getCommonSuperType(superType, process(expression, context)); if (!newSuperType.isPresent()) { throw new SemanticException(TYPE_MISMATCH, expression, message, superType); } superType = newSuperType.get(); } // verify all expressions can be coerced to the superType for (Expression expression : expressions) { Type type = process(expression, context); if (!type.equals(superType)) { if (!typeManager.canCoerce(type, superType)) { throw new SemanticException(TYPE_MISMATCH, expression, message, superType); } addOrReplaceExpressionCoercion(expression, type, superType); } } return superType; }
@Override protected Type visitNullIfExpression(NullIfExpression node, StackableAstVisitorContext<Context> context) { Type firstType = process(node.getFirst(), context); Type secondType = process(node.getSecond(), context); if (!typeManager.getCommonSuperType(firstType, secondType).isPresent()) { throw new SemanticException(TYPE_MISMATCH, node, "Types are not comparable with NULLIF: %s vs %s", firstType, secondType); } return setExpressionType(node, firstType); }
Type superType = fieldTypes.get(i); Optional<Type> commonSuperType = metadata.getTypeManager().getCommonSuperType(fieldType, superType); if (!commonSuperType.isPresent()) { throw new SemanticException(MISMATCHED_SET_COLUMN_TYPES,
Optional<Type> type = metadata.getTypeManager().getCommonSuperType(leftField.get().getType(), rightField.get().getType()); analysis.addTypes(ImmutableMap.of(NodeRef.of(column), type.get()));
Optional<Type> type = metadata.getTypeManager().getCommonSuperType(leftField.get().getType(), rightField.get().getType()); analysis.addTypes(ImmutableMap.of(NodeRef.of(column), type.get()));
Optional<Type> commonSuperType = typeManager.getCommonSuperType(originalType, actualType); if (!commonSuperType.isPresent()) { return SolverReturnStatus.UNSOLVABLE;
Optional<Type> commonSuperType = metadata.getTypeManager().getCommonSuperType(outputFieldTypes[i], descFieldType); if (!commonSuperType.isPresent()) { throw new SemanticException(
Optional<Type> commonSuperType = typeManager.getCommonSuperType(originalType, actualType); if (!commonSuperType.isPresent()) { return SolverReturnStatus.UNSOLVABLE;
Type commonType = metadata.getTypeManager().getCommonSuperType(firstType, secondType).get();
Type commonType = metadata.getTypeManager().getCommonSuperType(firstType, secondType).get();
Type patternType = createVarcharType(unescapedPattern.length()); TypeManager typeManager = metadata.getTypeManager(); Optional<Type> commonSuperType = typeManager.getCommonSuperType(valueType, patternType); checkArgument(commonSuperType.isPresent(), "Missing super type when optimizing %s", node); Expression valueExpression = toExpression(value, valueType);
Type superType = metadata.getTypeManager().getCommonSuperType(columnType, literalType).orElseThrow(() -> new IllegalArgumentException("incompatible types in test (" + columnType + ", " + literalType + ")"));