Package dev.frostlake.executor
Class DeclarationTypes
java.lang.Object
dev.frostlake.executor.DeclarationTypes
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final DataTypeThe type a whole number gives an untyped declaration. -
Method Summary
Modifier and TypeMethodDescriptionstatic DataTypeofExpression(Expression expression, Map<String, DataType> typesInScope, QueryExecutor queryExecutor) static DataTypeofInitialiser(FrostlakeParser.ExpressionContext initialiser, Map<String, DataType> typesInScope, QueryExecutor queryExecutor) static ExpressionsqlExpression(FrostlakeParser.ExpressionContext initialiser) The initialiser as a SQL expression, or null when it cannot be read as one.static DataTypestaticType(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.
-
Field Details
-
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 parsedtypesInScope- the declared types of the names in scope, keyed as the resolver folds themqueryExecutor- 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 nulltypesInScope- the declared types of the names in scope, keyed as the resolver folds themqueryExecutor- 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 + 1is NUMBER(7,4) there, whereLET y := 1.7777 + 1declares a FLOAT.- Parameters:
expression- the expression, or nulltypesInScope- the declared types of the names in scope, keyed as the resolver folds themqueryExecutor- the executor whose functions and catalog type the expression- Returns:
- the expression's static type, or null when it cannot be determined
-
sqlExpression
The initialiser as a SQL expression, or null when it cannot be read as one.
-