public ReduceAggregationFunction() { super(NAME, ImmutableList.of(typeVariable("T"), typeVariable("S")), ImmutableList.of(), parseTypeSignature("S"), ImmutableList.of( parseTypeSignature("T"), parseTypeSignature("S"), parseTypeSignature("function(S,T,S)"), parseTypeSignature("function(S,S,S)"))); }
public static TypeSignature applyBoundVariables(TypeSignature typeSignature, BoundVariables boundVariables) { String baseType = typeSignature.getBase(); if (boundVariables.containsTypeVariable(baseType)) { checkState(typeSignature.getParameters().isEmpty(), "Type parameters cannot have parameters"); return boundVariables.getTypeVariable(baseType).getTypeSignature(); } List<TypeSignatureParameter> parameters = typeSignature.getParameters().stream() .map(typeSignatureParameter -> applyBoundVariables(typeSignatureParameter, boundVariables)) .collect(toList()); return new TypeSignature(baseType, parameters); }
private static void assertRowSignature( String typeName, Set<String> literalParameters, TypeSignature expectedSignature) { TypeSignature signature = parseTypeSignature(typeName, literalParameters); assertEquals(signature, expectedSignature); assertEquals(signature.toString(), typeName); }
private static ClientTypeSignature toClientTypeSignature(TypeSignature signature) { return new ClientTypeSignature(signature.getBase(), signature.getParameters().stream() .map(Query::toClientTypeSignatureParameter) .collect(toImmutableList())); }
@Test public void parseSignatureWithLiterals() { TypeSignature result = parseTypeSignature("decimal(X,42)", ImmutableSet.of("X")); assertEquals(result.getParameters().size(), 2); assertEquals(result.getParameters().get(0).isVariable(), true); assertEquals(result.getParameters().get(1).isLongLiteral(), true); }
public static boolean isMapType(Type type) { return type.getTypeSignature().getBase().equals(StandardTypes.MAP); } }
@Test public void testVarchar() { assertEquals(VARCHAR.getTypeSignature().toString(), "varchar"); assertEquals(createVarcharType(42).getTypeSignature().toString(), "varchar(42)"); assertEquals(parseTypeSignature("varchar"), createUnboundedVarcharType().getTypeSignature()); assertEquals(createUnboundedVarcharType().getTypeSignature(), parseTypeSignature("varchar")); assertEquals(parseTypeSignature("varchar").hashCode(), createUnboundedVarcharType().getTypeSignature().hashCode()); assertNotEquals(createUnboundedVarcharType().getTypeSignature(), parseTypeSignature("varchar(10)")); }
public static String generateAggregationName(String baseName, TypeSignature outputType, List<TypeSignature> inputTypes) { StringBuilder sb = new StringBuilder(); sb.append(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, outputType.toString())); for (TypeSignature inputType : inputTypes) { sb.append(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, inputType.toString())); } sb.append(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, baseName.toLowerCase(ENGLISH))); return sb.toString(); }
private UnknownType() { // We never access the native container for UNKNOWN because its null check is always true. // The actual native container type does not matter here. // We choose boolean to represent UNKNOWN because it's the smallest primitive type. super(new TypeSignature(NAME), boolean.class, 1); }
private static boolean isTypeWithLiteralParameters(TypeSignature typeSignature) { return typeSignature.getParameters().stream() .map(TypeSignatureParameter::getKind) .allMatch(kind -> kind == ParameterKind.LONG || kind == ParameterKind.VARIABLE); }
@Test public void parseSignatureWithLiterals() { TypeSignature result = parseTypeSignature("decimal(X,42)", ImmutableSet.of("X")); assertEquals(result.getParameters().size(), 2); assertEquals(result.getParameters().get(0).isVariable(), true); assertEquals(result.getParameters().get(1).isLongLiteral(), true); }
private static void validateOperatorSignature(OperatorType operatorType, TypeSignature returnType, List<TypeSignature> argumentTypes, int expectedArgumentCount) { String signature = formatSignature(operatorType, returnType, argumentTypes); checkArgument(!returnType.getBase().equals(UnknownType.NAME), "%s operator return type can not be NULL: %s", operatorType, signature); checkArgument(argumentTypes.size() == expectedArgumentCount, "%s operator must have exactly %s argument: %s", operatorType, expectedArgumentCount, signature); }
@Test public void testVarchar() { assertEquals(VARCHAR.getTypeSignature().toString(), "varchar"); assertEquals(createVarcharType(42).getTypeSignature().toString(), "varchar(42)"); assertEquals(parseTypeSignature("varchar"), createUnboundedVarcharType().getTypeSignature()); assertEquals(createUnboundedVarcharType().getTypeSignature(), parseTypeSignature("varchar")); assertEquals(parseTypeSignature("varchar").hashCode(), createUnboundedVarcharType().getTypeSignature().hashCode()); assertNotEquals(createUnboundedVarcharType().getTypeSignature(), parseTypeSignature("varchar(10)")); }
private static ClientTypeSignature toClientTypeSignature(TypeSignature signature) { return new ClientTypeSignature(signature.getBase(), signature.getParameters().stream() .map(TestFixJsonDataUtils::toClientTypeSignatureParameter) .collect(toImmutableList())); }
public static String generateAggregationName(String baseName, TypeSignature outputType, List<TypeSignature> inputTypes) { StringBuilder sb = new StringBuilder(); sb.append(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, outputType.toString())); for (TypeSignature inputType : inputTypes) { sb.append(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, inputType.toString())); } sb.append(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, baseName.toLowerCase(ENGLISH))); return sb.toString(); }
private RegressorType() { super(new TypeSignature(NAME)); } }
private RowEqualOperator() { super(EQUAL, ImmutableList.of(comparableWithVariadicBound("T", "row")), ImmutableList.of(), parseTypeSignature(StandardTypes.BOOLEAN), ImmutableList.of(parseTypeSignature("T"), parseTypeSignature("T"))); }
private static void assertRowSignature( String typeName, Set<String> literalParameters, TypeSignature expectedSignature) { TypeSignature signature = parseTypeSignature(typeName, literalParameters); assertEquals(signature, expectedSignature); assertEquals(signature.toString(), typeName); }
@Test public void testRowTypeLookup() { functionAssertions.getMetadata().getType(parseTypeSignature("row(a bigint)")); Type type = functionAssertions.getMetadata().getType(parseTypeSignature("row(b bigint)")); assertEquals(type.getTypeSignature().getParameters().size(), 1); assertEquals(type.getTypeSignature().getParameters().get(0).getNamedTypeSignature().getName().get(), "b"); }
public static TypeSignature applyBoundVariables(TypeSignature typeSignature, BoundVariables boundVariables) { String baseType = typeSignature.getBase(); if (boundVariables.containsTypeVariable(baseType)) { checkState(typeSignature.getParameters().isEmpty(), "Type parameters cannot have parameters"); return boundVariables.getTypeVariable(baseType).getTypeSignature(); } List<TypeSignatureParameter> parameters = typeSignature.getParameters().stream() .map(typeSignatureParameter -> applyBoundVariables(typeSignatureParameter, boundVariables)) .collect(toList()); return new TypeSignature(baseType, parameters); }