@VisibleForTesting public static InternalAggregationFunction generateInternalAggregationFunction(Class<?> clazz, TypeSignature outputType, List<TypeSignature> inputTypes) { return generateInternalAggregationFunction(clazz, outputType, inputTypes, new TypeRegistry()); }
addType(BOOLEAN); addType(BIGINT); addType(INTEGER); addType(SMALLINT); addType(TINYINT); addType(DOUBLE); addType(REAL); addType(VARBINARY); addType(DATE); addType(TIME); addType(TIME_WITH_TIME_ZONE); addType(TIMESTAMP); addType(TIMESTAMP_WITH_TIME_ZONE); addType(INTERVAL_YEAR_MONTH); addType(INTERVAL_DAY_TIME); addType(HYPER_LOG_LOG); addType(SET_DIGEST); addType(P4_HYPER_LOG_LOG); addType(JONI_REGEXP); addType(RE2J_REGEXP); addType(LIKE_PATTERN); addType(JSON_PATH); addType(COLOR); addType(JSON); addType(CODE_POINTS); addType(IPADDRESS); addParametricType(VarcharParametricType.VARCHAR); addParametricType(CharParametricType.CHAR); addParametricType(DecimalParametricType.DECIMAL);
public TestIntegerArrayType() { super(new TypeRegistry().getType(parseTypeSignature("array(integer)")), List.class, createTestBlock(new TypeRegistry().getType(parseTypeSignature("array(integer)")))); }
private TypeCompatibility typeCompatibilityForCovariantParametrizedType(Type fromType, Type toType) { checkState(fromType.getClass().equals(toType.getClass())); ImmutableList.Builder<TypeSignatureParameter> commonParameterTypes = ImmutableList.builder(); List<Type> fromTypeParameters = fromType.getTypeParameters(); List<Type> toTypeParameters = toType.getTypeParameters(); if (fromTypeParameters.size() != toTypeParameters.size()) { return TypeCompatibility.incompatible(); } boolean coercible = true; for (int i = 0; i < fromTypeParameters.size(); i++) { TypeCompatibility compatibility = compatibility(fromTypeParameters.get(i), toTypeParameters.get(i)); if (!compatibility.isCompatible()) { return TypeCompatibility.incompatible(); } coercible &= compatibility.isCoercible(); commonParameterTypes.add(TypeSignatureParameter.of(compatibility.getCommonSuperType().getTypeSignature())); } String typeBase = fromType.getTypeSignature().getBase(); return TypeCompatibility.compatible(getType(new TypeSignature(typeBase, commonParameterTypes.build())), coercible); }
@Override public Type getParameterizedType(String baseTypeName, List<TypeSignatureParameter> typeParameters) { return getType(new TypeSignature(baseTypeName, typeParameters)); }
protected void registerTypes(Plugin plugin) { for (Type type : plugin.getTypes()) { typeRegistry.addType(type); } }
public static boolean canCoerce(List<? extends Type> actualTypes, List<Type> expectedTypes) { if (actualTypes.size() != expectedTypes.size()) { return false; } for (int i = 0; i < expectedTypes.size(); i++) { Type expectedType = expectedTypes.get(i); Type actualType = actualTypes.get(i); if (!canCoerce(actualType, expectedType)) { return false; } } return true; }
if (!canCoerce(source, result)) { return false; String resultTypeBase = result.getTypeSignature().getBase(); if (sourceTypeBase.equals(resultTypeBase) && isCovariantParametrizedType(source)) { List<Type> sourceTypeParameters = source.getTypeParameters(); List<Type> resultTypeParameters = result.getTypeParameters(); checkState(sourceTypeParameters.size() == resultTypeParameters.size()); for (int i = 0; i < sourceTypeParameters.size(); i++) { if (!isTypeOnlyCoercion(sourceTypeParameters.get(i), resultTypeParameters.get(i))) { return false;
@Override @Deprecated public Type getParameterizedType(String baseTypeName, List<TypeSignature> typeParameters, List<String> literalParameters) { if (baseTypeName.equals(StandardTypes.ROW)) { return getType(new TypeSignature(baseTypeName, typeParameters, literalParameters)); } return getParameterizedType( baseTypeName, typeParameters.stream().map(TypeSignatureParameter::of).collect(toList())); }
public static RowType rowType(List<NamedTypeSignature> elementTypeSignatures) { return (RowType) TYPE_MANAGER.getParameterizedType( StandardTypes.ROW, ImmutableList.copyOf(elementTypeSignatures.stream() .map(TypeSignatureParameter::of) .collect(toList()))); }
private static boolean typesMatchForInsert(Iterable<Type> tableTypes, Iterable<Type> queryTypes) { if (Iterables.size(tableTypes) != Iterables.size(queryTypes)) { return false; } Iterator<Type> tableTypesIterator = tableTypes.iterator(); Iterator<Type> queryTypesIterator = queryTypes.iterator(); while (tableTypesIterator.hasNext()) { Type tableType = tableTypesIterator.next(); Type queryType = queryTypesIterator.next(); if (isStructuralType(tableType)) { if (!tableType.getTypeSignature().getBase().equals(queryType.getTypeSignature().getBase())) { return false; } if (!typesMatchForInsert(tableType.getTypeParameters(), queryType.getTypeParameters())) { return false; } } else { if (!Objects.equals(tableType, queryType) && !isTypeOnlyCoercion(queryType.getTypeSignature(), tableType.getTypeSignature())) { return false; } } } return true; }
public static boolean isTypeOnlyCoercion(TypeSignature actualType, TypeSignature expectedType) if (!canCoerce(actualType, expectedType)) { return false; actualType.getParameters().size() == expectedType.getParameters().size()) { for (int i = 0; i < actualType.getParameters().size(); i++) { if (!isCovariantParameterPosition(actualType.getBase(), i)) { return false; if (!isTypeOnlyCoercion(actualParameterSignature.get(), expectedParameterSignature.get())) { return false;
public static boolean canCoerce(TypeSignature actualType, TypeSignature expectedType) { Optional<TypeSignature> commonSuperTypeSignature = getCommonSuperTypeSignature(actualType, expectedType); return commonSuperTypeSignature.isPresent() && commonSuperTypeSignature.get().equals(expectedType); }
Optional<String> commonSuperTypeBase = getCommonSuperTypeBase(firstType.getBase(), secondType.getBase()); if (!commonSuperTypeBase.isPresent()) { return Optional.empty(); secondParameter.getLongLiteral()))); else if (isCovariantParameterPosition(commonSuperTypeBase.get(), i)) { Optional<TypeSignature> firstParameterSignature = firstParameter.getTypeSignatureOrNamedTypeSignature(); Optional<TypeSignature> secondParameterSignature = secondParameter.getTypeSignatureOrNamedTypeSignature(); Optional<TypeSignature> commonSuperType = getCommonSuperTypeSignature( firstParameterSignature.get(), secondParameterSignature.get()); if (!commonSuperType.isPresent()) {
public static List<Type> getTypes(List<? extends ColumnHandle> columnHandles) { ImmutableList.Builder<Type> types = ImmutableList.builder(); for (ColumnHandle columnHandle : columnHandles) { types.add(TYPE_MANAGER.getType(((HiveColumnHandle) columnHandle).getTypeSignature())); } return types.build(); }
protected void registerTypes(Plugin plugin) { for (Type type : plugin.getTypes()) { functionAssertions.getTypeRegistry().addType(type); } }
private void coerceType(StackableAstVisitorContext<AnalysisContext> context, Expression expression, Type expectedType, String message) { Type actualType = process(expression, context); if (!actualType.equals(expectedType)) { if (!canCoerce(actualType, expectedType)) { throw new SemanticException(TYPE_MISMATCH, expression, message + " must evaluate to a %s (actual: %s)", expectedType, actualType); } expressionCoercions.put(expression, expectedType); } }
public static ArrayType arrayType(Type elementType) { return (ArrayType) TYPE_MANAGER.getParameterizedType( StandardTypes.ARRAY, ImmutableList.of(TypeSignatureParameter.of(elementType.getTypeSignature()))); }
@Test public void testIsTypeOnlyCoercion() { assertTrue(TypeRegistry.isTypeOnlyCoercion(BIGINT.getTypeSignature(), BIGINT.getTypeSignature())); assertTrue(TypeRegistry.isTypeOnlyCoercion(parseTypeSignature("varchar(42)"), parseTypeSignature("varchar(44)"))); assertFalse(TypeRegistry.isTypeOnlyCoercion(parseTypeSignature("varchar(44)"), parseTypeSignature("varchar(42)"))); assertTrue(TypeRegistry.isTypeOnlyCoercion(parseTypeSignature("array(varchar(42))"), parseTypeSignature("array(varchar(44))"))); assertFalse(TypeRegistry.isTypeOnlyCoercion(parseTypeSignature("array(varchar(44))"), parseTypeSignature("array(varchar(42))"))); }
@Override public Optional<Type> getCommonSuperType(List<? extends Type> types) { checkArgument(!types.isEmpty(), "types is empty"); Optional<TypeSignature> commonSuperTypeSignature = getCommonSuperTypeSignature( types.stream() .map(Type::getTypeSignature) .collect(toImmutableList())); return commonSuperTypeSignature.map(this::getType); }