private void addOrReplaceExpressionCoercion(Expression expression, Type type, Type superType) { NodeRef<Expression> ref = NodeRef.of(expression); expressionCoercions.put(ref, superType); if (typeManager.isTypeOnlyCoercion(type, superType)) { typeOnlyCoercions.add(ref); } else if (typeOnlyCoercions.contains(ref)) { typeOnlyCoercions.remove(ref); } } }
private boolean isTypeOnlyCoercion(Type actual, Type expected) { return typeRegistry.isTypeOnlyCoercion(actual, expected); }
private void verifyTypeSignature(Symbol symbol, TypeSignature expected, TypeSignature actual) { // UNKNOWN should be considered as a wildcard type, which matches all the other types TypeManager typeManager = metadata.getTypeManager(); if (!actual.equals(UNKNOWN.getTypeSignature()) && !typeManager.isTypeOnlyCoercion(typeManager.getType(actual), typeManager.getType(expected))) { checkArgument(expected.equals(actual), "type of symbol '%s' is expected to be %s, but the actual type is %s", symbol, expected, actual); } } }
Type actualType = analysis.getType(item); if (!actualType.equals(expectedType)) { analysis.addCoercion(item, expectedType, metadata.getTypeManager().isTypeOnlyCoercion(actualType, expectedType)); Type expectedType = fieldTypes.get(0); if (!actualType.equals(expectedType)) { analysis.addCoercion(row, expectedType, metadata.getTypeManager().isTypeOnlyCoercion(actualType, expectedType));
private Map<Symbol, Expression> coerce(Iterable<? extends Expression> expressions, PlanBuilder subPlan, TranslationMap translations) { ImmutableMap.Builder<Symbol, Expression> projections = ImmutableMap.builder(); for (Expression expression : expressions) { Type type = analysis.getType(expression); Type coercion = analysis.getCoercion(expression); Symbol symbol = symbolAllocator.newSymbol(expression, firstNonNull(coercion, type)); Expression rewritten = subPlan.rewrite(expression); if (coercion != null) { rewritten = new Cast( rewritten, coercion.getTypeSignature().toString(), false, metadata.getTypeManager().isTypeOnlyCoercion(type, coercion)); } projections.put(symbol, rewritten); translations.put(expression, symbol); } return projections.build(); }
private boolean isTypeOnlyCoercion(String actual, String expected) { return typeRegistry.isTypeOnlyCoercion(createType(actual), createType(expected)); }
if (!typeManager.isTypeOnlyCoercion(typeManager.getType(boundSignature.getReturnType()), returnType)) { continue; for (int i = 0; i < argumentTypes.size(); i++) { Type expectedType = typeManager.getType(boundSignature.getArgumentTypes().get(i)); if (!typeManager.isTypeOnlyCoercion(argumentTypes.get(i), expectedType)) { nonTypeOnlyCoercion = true; break;
private PlanBuilder handleGroupingOperations(PlanBuilder subPlan, QuerySpecification node, Optional<Symbol> groupIdSymbol, List<Set<FieldId>> groupingSets) { if (analysis.getGroupingOperations(node).isEmpty()) { return subPlan; } TranslationMap newTranslations = subPlan.copyTranslations(); Assignments.Builder projections = Assignments.builder(); projections.putIdentities(subPlan.getRoot().getOutputSymbols()); List<Set<Integer>> descriptor = groupingSets.stream() .map(set -> set.stream() .map(FieldId::getFieldIndex) .collect(toImmutableSet())) .collect(toImmutableList()); for (GroupingOperation groupingOperation : analysis.getGroupingOperations(node)) { Expression rewritten = GroupingOperationRewriter.rewriteGroupingOperation(groupingOperation, descriptor, analysis.getColumnReferenceFields(), groupIdSymbol); Type coercion = analysis.getCoercion(groupingOperation); Symbol symbol = symbolAllocator.newSymbol(rewritten, analysis.getTypeWithCoercions(groupingOperation)); if (coercion != null) { rewritten = new Cast( rewritten, coercion.getTypeSignature().toString(), false, metadata.getTypeManager().isTypeOnlyCoercion(analysis.getType(groupingOperation), coercion)); } projections.put(symbol, rewritten); newTranslations.put(groupingOperation, symbol); } return new PlanBuilder(newTranslations, new ProjectNode(idAllocator.getNextId(), subPlan.getRoot(), projections.build()), analysis.getParameters()); }
Type superType = commonSuperType.get(); if (!valueType.equals(superType)) { valueExpression = new Cast(valueExpression, superType.getTypeSignature().toString(), false, typeManager.isTypeOnlyCoercion(valueType, superType)); patternExpression = new Cast(patternExpression, superType.getTypeSignature().toString(), false, typeManager.isTypeOnlyCoercion(patternType, superType));
type.getTypeSignature().toString(), false, metadata.getTypeManager().isTypeOnlyCoercion(left.getDescriptor().getFieldByIndex(leftField).getType(), type))); leftJoinColumns.put(identifier, leftOutput); type.getTypeSignature().toString(), false, metadata.getTypeManager().isTypeOnlyCoercion(right.getDescriptor().getFieldByIndex(rightField).getType(), type))); rightJoinColumns.put(identifier, rightOutput);
Type queryType = symbolAllocator.getTypes().get(input); if (queryType.equals(tableType) || metadata.getTypeManager().isTypeOnlyCoercion(queryType, tableType)) { assignments.put(output, input.toSymbolReference());