public MapToMapCast() { super(CAST, ImmutableList.of(typeVariable("FK"), typeVariable("FV"), typeVariable("TK"), typeVariable("TV")), ImmutableList.of(), parseTypeSignature("map(TK,TV)"), ImmutableList.of(parseTypeSignature("map(FK,FV)"))); }
private MapZipWithFunction() { super(new Signature( "map_zip_with", FunctionKind.SCALAR, ImmutableList.of(typeVariable("K"), typeVariable("V1"), typeVariable("V2"), typeVariable("V3")), ImmutableList.of(), parseTypeSignature("map(K,V3)"), ImmutableList.of(parseTypeSignature("map(K,V1)"), parseTypeSignature("map(K,V2)"), parseTypeSignature("function(K,V1,V2,V3)")), false)); }
@Test public void testPartiallyFixedTypeParameterParse() { Signature expectedSignature = new Signature( "partially_fixed_type_parameter_scalar_function", FunctionKind.SCALAR, ImmutableList.of(typeVariable("T1"), typeVariable("T2")), ImmutableList.of(), BIGINT.getTypeSignature(), ImmutableList.of(BIGINT.getTypeSignature()), false); List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinition(PartiallyFixedTypeParameterScalarFunction.class); assertEquals(functions.size(), 1); ParametricScalar scalar = (ParametricScalar) functions.get(0); assertImplementationCount(scalar, 0, 0, 1); List<ImplementationDependency> dependencies = scalar.getImplementations().getGenericImplementations().get(0).getDependencies(); assertEquals(dependencies.size(), 1); assertEquals(scalar.getSignature(), expectedSignature); assertTrue(scalar.isDeterministic()); assertFalse(scalar.isHidden()); assertEquals(scalar.getDescription(), "Parametric scalar that uses TypeParameter with partially fixed type"); } }
@Test public void testResolveTypeParametrizedFunction() { assertThatResolveFunction() .among(functionSignature(ImmutableList.of("T", "T"), "boolean", ImmutableList.of(typeVariable("T")))) .forParameters("bigint", "bigint") .returns(functionSignature("bigint", "bigint")); }
.returnType(parseTypeSignature("V")) .argumentTypes(parseTypeSignature("T"), parseTypeSignature("function(T,U)"), parseTypeSignature("function(U,V)")) .typeVariableConstraints(typeVariable("T"), typeVariable("U"), typeVariable("V")) .build(); assertThat(applyTwice) .returnType(parseTypeSignature("array(T)")) .argumentTypes(parseTypeSignature("array(T)"), parseTypeSignature("function(T, array(T))")) .typeVariableConstraints(typeVariable("T")) .build(); assertThat(flatMap) .returnType(parseTypeSignature("T")) .argumentTypes(parseTypeSignature("T"), parseTypeSignature("function(T, T)")) .typeVariableConstraints(typeVariable("T")) .setVariableArity(true) .build(); .returnType(parseTypeSignature("T")) .argumentTypes(parseTypeSignature("T"), parseTypeSignature("function(T, T)")) .typeVariableConstraints(typeVariable("T")) .build(); assertThat(loop) .returnType(parseTypeSignature("array(T)")) .argumentTypes(parseTypeSignature("array(T)"), parseTypeSignature("function(T,E)")) .typeVariableConstraints(typeVariable("T"), orderableTypeParameter("E")) .build(); assertThat(sortByKey)
private MapTransformKeyFunction() { super(new Signature( "transform_keys", FunctionKind.SCALAR, ImmutableList.of(typeVariable("K1"), typeVariable("K2"), typeVariable("V")), ImmutableList.of(), parseTypeSignature("map(K2,V)"), ImmutableList.of(parseTypeSignature("map(K1,V)"), parseTypeSignature("function(K1,V,K2)")), false)); }
private ArrayToArrayCast() { super(CAST, ImmutableList.of(typeVariable("F"), typeVariable("T")), ImmutableList.of(), parseTypeSignature("array(T)"), ImmutableList.of(parseTypeSignature("array(F)"))); }
@Test public void testAmbiguousCallWithNoCoercion() { assertThatResolveFunction() .among( functionSignature("decimal(p,s)", "decimal(p,s)"), functionSignature(ImmutableList.of("T", "T"), "boolean", ImmutableList.of(typeVariable("T")))) .forParameters("decimal(3,1)", "decimal(3,1)") .returns(functionSignature("decimal(3,1)", "decimal(3,1)")); }
@Test public void testPartiallyFixedTypeParameterInjectionAggregateFunctionParse() Signature expectedSignature = new Signature( "partially_fixed_type_parameter_injection", FunctionKind.AGGREGATE, ImmutableList.of(typeVariable("T1"), typeVariable("T2")), ImmutableList.of(), DoubleType.DOUBLE.getTypeSignature(), ImmutableList.of(DoubleType.DOUBLE.getTypeSignature()), false);
private MapTransformValueFunction() { super(new Signature( "transform_values", FunctionKind.SCALAR, ImmutableList.of(typeVariable("K"), typeVariable("V1"), typeVariable("V2")), ImmutableList.of(), parseTypeSignature("map(K,V2)"), ImmutableList.of(parseTypeSignature("map(K,V1)"), parseTypeSignature("function(K,V1,V2)")), false)); }
private MapToJsonCast() { super(OperatorType.CAST, ImmutableList.of(typeVariable("K"), typeVariable("V")), ImmutableList.of(), parseTypeSignature(StandardTypes.JSON), ImmutableList.of(parseTypeSignature("map(K,V)"))); }
@Test public void testGetTypeVariableConstraints() { assertGetTypeVariableConstraints(ImmutableList.of("array(varchar)"), "varchar", ImmutableList.of()); assertGetTypeVariableConstraints(ImmutableList.of("K", "V"), "map(K,V)", ImmutableList.of(typeVariable("K"), typeVariable("V"))); assertGetTypeVariableConstraints(ImmutableList.of("K", "K"), "bigint", ImmutableList.of(typeVariable("K"))); assertGetTypeVariableConstraints(ImmutableList.of("bigint", "bigint"), "K", ImmutableList.of(typeVariable("K"))); assertGetTypeVariableConstraints(ImmutableList.of("array(map(K,varchar))", "row(V,integer)"), "map(integer,S)", ImmutableList.of(typeVariable("K"), typeVariable("S"), typeVariable("V"))); }
private ZipWithFunction() { super(new Signature( "zip_with", FunctionKind.SCALAR, ImmutableList.of(typeVariable("T"), typeVariable("U"), typeVariable("R")), ImmutableList.of(), parseTypeSignature("array(R)"), ImmutableList.of(parseTypeSignature("array(T)"), parseTypeSignature("array(U)"), parseTypeSignature("function(T,U,R)")), false)); }
public MapSubscriptOperator(boolean legacyMissingKey) { super(SUBSCRIPT, ImmutableList.of(typeVariable("K"), typeVariable("V")), ImmutableList.of(), parseTypeSignature("V"), ImmutableList.of(parseTypeSignature("map(K,V)"), parseTypeSignature("K"))); this.legacyMissingKey = legacyMissingKey; }
private ApplyFunction() { super(new Signature( "apply", FunctionKind.SCALAR, ImmutableList.of(typeVariable("T"), typeVariable("U")), ImmutableList.of(), parseTypeSignature("U"), ImmutableList.of(parseTypeSignature("T"), parseTypeSignature("function(T,U)")), false)); }
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)"))); }
private MapConcatFunction() { super(new Signature(FUNCTION_NAME, FunctionKind.SCALAR, ImmutableList.of(typeVariable("K"), typeVariable("V")), ImmutableList.of(), parseTypeSignature("map(K,V)"), ImmutableList.of(parseTypeSignature("map(K,V)")), true)); }
public CountColumn() { super(NAME, ImmutableList.of(typeVariable("T")), ImmutableList.of(), parseTypeSignature(StandardTypes.BIGINT), ImmutableList.of(parseTypeSignature("T"))); }
private ArrayReduceFunction() { super(new Signature( "reduce", FunctionKind.SCALAR, ImmutableList.of(typeVariable("T"), typeVariable("S"), typeVariable("R")), ImmutableList.of(), parseTypeSignature("R"), ImmutableList.of(parseTypeSignature("array(T)"), parseTypeSignature("S"), parseTypeSignature("function(S,T,S)"), parseTypeSignature("function(S,R)")), false)); }
private JsonToArrayCast() { super(OperatorType.CAST, ImmutableList.of(typeVariable("T")), ImmutableList.of(), parseTypeSignature("array(T)"), ImmutableList.of(parseTypeSignature(StandardTypes.JSON))); }