private static List<TypeSignatureParameter> buildTypeParameters(int precision, int scale) { List<TypeSignatureParameter> typeParameters = new ArrayList<>(); typeParameters.add(TypeSignatureParameter.of(precision)); typeParameters.add(TypeSignatureParameter.of(scale)); return unmodifiableList(typeParameters); } }
private static List<TypeSignatureParameter> typeParameters(List<Type> argumentTypes, Type returnType) { requireNonNull(returnType, "returnType is null"); requireNonNull(argumentTypes, "argumentTypes is null"); ImmutableList.Builder<TypeSignatureParameter> builder = ImmutableList.builder(); argumentTypes.stream() .map(Type::getTypeSignature) .map(TypeSignatureParameter::of) .forEach(builder::add); builder.add(TypeSignatureParameter.of(returnType.getTypeSignature())); return builder.build(); }
private CharType(long length) { super( new TypeSignature( StandardTypes.CHAR, singletonList(TypeSignatureParameter.of(length))), Slice.class); if (length < 0 || length > MAX_LENGTH) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("CHAR length scale must be in range [0, %s]", MAX_LENGTH)); } this.length = (int) length; }
public ArrayType(Type elementType) { super(new TypeSignature(ARRAY, TypeSignatureParameter.of(elementType.getTypeSignature())), Block.class); this.elementType = requireNonNull(elementType, "elementType is null"); }
private static TypeSignature makeSignature(List<Field> fields) { int size = fields.size(); if (size == 0) { throw new IllegalArgumentException("Row type must have at least 1 field"); } List<TypeSignatureParameter> parameters = fields.stream() .map(field -> TypeSignatureParameter.of(new NamedTypeSignature(field.getName().map(name -> new RowFieldName(name, false)), field.getType().getTypeSignature()))) .collect(Collectors.toList()); return new TypeSignature(ROW, parameters); }
public ClassifierType(Type type) { super(new TypeSignature(ClassifierParametricType.NAME, TypeSignatureParameter.of(type.getTypeSignature()))); checkArgument(type.isComparable(), "type must be comparable"); labelType = type; }
@Override public InternalAggregationFunction specialize(BoundVariables boundVariables, int arity, TypeManager typeManager, FunctionRegistry functionRegistry) { Type keyType = boundVariables.getTypeVariable("K"); Type valueType = boundVariables.getTypeVariable("V"); MapType outputType = (MapType) typeManager.getParameterizedType(StandardTypes.MAP, ImmutableList.of( TypeSignatureParameter.of(keyType.getTypeSignature()), TypeSignatureParameter.of(valueType.getTypeSignature()))); return generateAggregation(keyType, valueType, outputType); }
@Override public InternalAggregationFunction specialize(BoundVariables boundVariables, int arity, TypeManager typeManager, FunctionRegistry functionRegistry) { Type keyType = boundVariables.getTypeVariable("K"); Type valueType = boundVariables.getTypeVariable("V"); MapType outputType = (MapType) typeManager.getParameterizedType(StandardTypes.MAP, ImmutableList.of( TypeSignatureParameter.of(keyType.getTypeSignature()), TypeSignatureParameter.of(valueType.getTypeSignature()))); return generateAggregation(keyType, valueType, outputType); }
@Override public InternalAggregationFunction specialize(BoundVariables boundVariables, int arity, TypeManager typeManager, FunctionRegistry functionRegistry) { Type valueType = boundVariables.getTypeVariable("T"); QuantileDigestType outputType = (QuantileDigestType) typeManager.getParameterizedType(StandardTypes.QDIGEST, ImmutableList.of(TypeSignatureParameter.of(valueType.getTypeSignature()))); return generateAggregation(valueType, outputType); }
@Override public InternalAggregationFunction specialize(BoundVariables boundVariables, int arity, TypeManager typeManager, FunctionRegistry functionRegistry) { Type valueType = boundVariables.getTypeVariable("V"); QuantileDigestType outputType = (QuantileDigestType) typeManager.getParameterizedType( StandardTypes.QDIGEST, ImmutableList.of(TypeSignatureParameter.of(valueType.getTypeSignature()))); return generateAggregation(valueType, outputType, arity); }
private Type getTypeNullName(int numFields) { ImmutableList.Builder<TypeSignatureParameter> typeSignatureParameters = ImmutableList.builder(); for (int i = 0; i < numFields; i++) { typeSignatureParameters.add(TypeSignatureParameter.of(new NamedTypeSignature(Optional.empty(), TEST_DATA_TYPE.getTypeSignature()))); } return TYPE_MANAGER.getParameterizedType(StandardTypes.ROW, typeSignatureParameters.build()); } }
@Override public ScalarFunctionImplementation specialize(BoundVariables boundVariables, int arity, TypeManager typeManager, FunctionRegistry functionRegistry) { Type elementType = boundVariables.getTypeVariable("E"); Type arrayType = typeManager.getParameterizedType(StandardTypes.ARRAY, ImmutableList.of(TypeSignatureParameter.of(elementType.getTypeSignature()))); MethodHandle methodHandle = METHOD_HANDLE.bindTo(elementType).bindTo(arrayType); return new ScalarFunctionImplementation( false, ImmutableList.of(valueTypeArgumentProperty(RETURN_NULL_ON_NULL)), methodHandle, isDeterministic()); }
private Type getType(List<String> fieldNames) { ImmutableList.Builder<TypeSignatureParameter> typeSignatureParameters = ImmutableList.builder(); for (String fieldName : fieldNames) { typeSignatureParameters.add(TypeSignatureParameter.of(new NamedTypeSignature(Optional.of(new RowFieldName(fieldName, false)), TEST_DATA_TYPE.getTypeSignature()))); } return TYPE_MANAGER.getParameterizedType(StandardTypes.ROW, typeSignatureParameters.build()); }
@Test public void testBackwardsCompatible() { ClientTypeSignature signature = new ClientTypeSignature(StandardTypes.ARRAY, ImmutableList.of(new ClientTypeSignatureParameter(TypeSignatureParameter.of(BIGINT.getTypeSignature())))); ClientTypeSignature legacy = CLIENT_TYPE_SIGNATURE_CODEC.fromJson("{\"rawType\":\"array\",\"literalArguments\":[],\"typeArguments\":[{\"rawType\":\"bigint\",\"literalArguments\":[],\"typeArguments\":[]}]}"); assertEquals(legacy, signature); }
@Test public void testLearn() { Type mapType = typeManager.getParameterizedType("map", ImmutableList.of(TypeSignatureParameter.of(parseTypeSignature(StandardTypes.BIGINT)), TypeSignatureParameter.of(parseTypeSignature(StandardTypes.DOUBLE)))); InternalAggregationFunction aggregation = generateInternalAggregationFunction(LearnClassifierAggregation.class, ClassifierType.BIGINT_CLASSIFIER.getTypeSignature(), ImmutableList.of(BIGINT.getTypeSignature(), mapType.getTypeSignature()), typeManager); assertLearnClassifer(aggregation.bind(ImmutableList.of(0, 1), Optional.empty()).createAccumulator()); }
@Test public void testLearnLibSvm() { Type mapType = typeManager.getParameterizedType("map", ImmutableList.of(TypeSignatureParameter.of(parseTypeSignature(StandardTypes.BIGINT)), TypeSignatureParameter.of(parseTypeSignature(StandardTypes.DOUBLE)))); InternalAggregationFunction aggregation = AggregationFromAnnotationsParser.parseFunctionDefinitionWithTypesConstraint( LearnLibSvmClassifierAggregation.class, ClassifierType.BIGINT_CLASSIFIER.getTypeSignature(), ImmutableList.of(BIGINT.getTypeSignature(), mapType.getTypeSignature(), VarcharType.getParametrizedVarcharSignature("x")) ).specialize(BoundVariables.builder().setLongVariable("x", (long) Integer.MAX_VALUE).build(), 3, typeManager); assertLearnClassifer(aggregation.bind(ImmutableList.of(0, 1, 2), Optional.empty()).createAccumulator()); }