Class DeclarationTypes

java.lang.Object
dev.frostlake.executor.DeclarationTypes

public final class DeclarationTypes extends Object
The type an UNTYPED declaration (LET y := <expr>, DECLARE y DEFAULT <expr>) takes from an initialiser the direct rules do not cover: the initialiser is typed as a SQL expression over the declared types in scope, then widened the way live declares the name. A text of any length becomes VARCHAR(134217728), a whole number NUMBER(38,0) and a fraction a FLOAT; a date, a timestamp, a boolean and a container keep their own type. So LET y := 'abc', UPPER('ab') and 'x' || 'yz' all declare VARCHAR(134217728), 1 + 1 and ABS(-5) NUMBER(38,0), 1.5 * 2 FLOAT, CURRENT_DATE() DATE and CURRENT_TIMESTAMP() TIMESTAMP_LTZ(9) (live-verified). A bare name hands on its own type, except that a number with a scale becomes a FLOAT.
  • Field Details

    • WHOLE_NUMBER

      public static final DataType WHOLE_NUMBER
      The type a whole number gives an untyped declaration.
  • Method Details

    • ofInitialiser

      public static DataType ofInitialiser(FrostlakeParser.ExpressionContext initialiser, Map<String,DataType> typesInScope, QueryExecutor queryExecutor)
      Parameters:
      initialiser - the initialiser as parsed
      typesInScope - the declared types of the names in scope, keyed as the resolver folds them
      queryExecutor - the executor whose functions and catalog type the expression
      Returns:
      the declared type, or null when the initialiser's type cannot be determined
    • ofExpression

      public static DataType ofExpression(Expression expression, Map<String,DataType> typesInScope, QueryExecutor queryExecutor)
      Parameters:
      expression - the initialiser as a SQL expression, or null
      typesInScope - the declared types of the names in scope, keyed as the resolver folds them
      queryExecutor - the executor whose functions and catalog type the expression
      Returns:
      the declared type, or null when the expression's type cannot be determined
    • staticType

      public static DataType staticType(Expression expression, Map<String,DataType> typesInScope, QueryExecutor queryExecutor)
      The static type an expression carries over the declared types in scope, as SQL types it — before any widening a declaration applies. A routine's RETURN reports this type: 1.7777 + 1 is NUMBER(7,4) there, where LET y := 1.7777 + 1 declares a FLOAT.
      Parameters:
      expression - the expression, or null
      typesInScope - the declared types of the names in scope, keyed as the resolver folds them
      queryExecutor - the executor whose functions and catalog type the expression
      Returns:
      the expression's static type, or null when it cannot be determined
    • sqlExpression

      public static Expression sqlExpression(FrostlakeParser.ExpressionContext initialiser)
      The initialiser as a SQL expression, or null when it cannot be read as one.