Record Class ScalarFunctionSymbol

java.lang.Object
java.lang.Record
com.darkcollective.relix.symbol.function.ScalarFunctionSymbol
Record Components:
namespace - the namespace this symbol belongs to; must not be blank
declaredName - the name as written by the user; must not be blank
provenance - built-in or user-defined; must not be null
shadowPolicy - replacement policy; must not be null
parameters - ordered parameter definitions; must not be null
returnType - the scalar type returned; must not be null
properties - optimizer hint flags; must not be null
body - the expression body for user-defined functions; absent for opaque built-ins
All Implemented Interfaces:
FunctionSymbol, Symbol

public record ScalarFunctionSymbol(String namespace, String declaredName, Provenance provenance, ShadowPolicy shadowPolicy, List<ParameterDefinition> parameters, ScalarType returnType, Set<FunctionProperty> properties, Optional<Operand> body) extends Record implements FunctionSymbol
A scalar function symbol — a function that accepts zero or more scalar arguments and returns a single scalar value.

Both built-in and user-defined functions are represented by this type; the Provenance field distinguishes them. Built-in functions typically have an absent body(), while user-defined functions carry the body as a parsed Operand expression.

Construction

Use the builder(String) factory to avoid specifying every optional field:


 // A built-in, deterministic, pure absolute-value function
 ScalarFunctionSymbol abs = ScalarFunctionSymbol.builder("abs")
     .namespace("builtin")
     .provenance(Provenance.BUILTIN)
     .shadowPolicy(ShadowPolicy.FORBIDDEN)
     .parameter("x", ScalarType.NUMBER)
     .returnType(ScalarType.NUMBER)
     .property(FunctionProperty.PURE)
     .property(FunctionProperty.DETERMINISTIC)
     .build();

 // A user-defined function with a body expression
 ScalarFunctionSymbol discount = ScalarFunctionSymbol.builder("discount")
     .parameter("price", ScalarType.NUMBER)
     .parameter("pct",   ScalarType.NUMBER)
     .returnType(ScalarType.NUMBER)
     .body(arith(attr("price"), ArithmeticOperator.MULTIPLY,
                 arith(num("1"), ArithmeticOperator.MINUS,
                       arith(attr("pct"), ArithmeticOperator.DIVIDE, num("100")))))
     .build();
 

Both the parameter list and the property set are defensive-copied on construction; the record is therefore immutable.

  • Constructor Details

  • Method Details

    • builder

      public static ScalarFunctionSymbol.Builder builder(String name)
      Returns a new ScalarFunctionSymbol.Builder for constructing a ScalarFunctionSymbol with the given declared name.

      Defaults applied by the builder:

      Parameters:
      name - the declared function name; must not be blank
      Returns:
      a fresh builder
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • namespace

      public String namespace()
      Returns the value of the namespace record component.
      Specified by:
      namespace in interface Symbol
      Returns:
      the value of the namespace record component
    • declaredName

      public String declaredName()
      Returns the value of the declaredName record component.
      Specified by:
      declaredName in interface Symbol
      Returns:
      the value of the declaredName record component
    • provenance

      public Provenance provenance()
      Returns the value of the provenance record component.
      Specified by:
      provenance in interface Symbol
      Returns:
      the value of the provenance record component
    • shadowPolicy

      public ShadowPolicy shadowPolicy()
      Returns the value of the shadowPolicy record component.
      Specified by:
      shadowPolicy in interface Symbol
      Returns:
      the value of the shadowPolicy record component
    • parameters

      public List<ParameterDefinition> parameters()
      Returns the value of the parameters record component.
      Specified by:
      parameters in interface FunctionSymbol
      Returns:
      the value of the parameters record component
    • returnType

      public ScalarType returnType()
      Returns the value of the returnType record component.
      Specified by:
      returnType in interface FunctionSymbol
      Returns:
      the value of the returnType record component
    • properties

      public Set<FunctionProperty> properties()
      Returns the value of the properties record component.
      Specified by:
      properties in interface FunctionSymbol
      Returns:
      the value of the properties record component
    • body

      public Optional<Operand> body()
      Returns the value of the body record component.
      Returns:
      the value of the body record component