Class SelectItemAccessors

java.lang.Object
dev.frostlake.executor.SelectItemAccessors

public final class SelectItemAccessors extends Object
Stateless accessors over SELECT-item parse-tree nodes — star / qualified-star / braced-star / expression item predicates, plus the alias, qualifier and value/full expression of an item. Extracted from QueryExecutor; pure functions over ANTLR FrostlakeParser contexts with no engine state.
  • Method Details

    • isStarItem

      public static boolean isStarItem(FrostlakeParser.SelectItemContext item)
    • isQualifiedStarItem

      public static boolean isQualifiedStarItem(FrostlakeParser.SelectItemContext item)
    • isObjectStarItem

      public static boolean isObjectStarItem(FrostlakeParser.SelectItemContext item)
      Snowflake's braced star ({*}, {* EXCLUDE (c)}, {t.*}) — an OBJECT constructor over the row, i.e. OBJECT_CONSTRUCT(*). It projects ONE object-valued column, never the star's N columns, so it is deliberately NOT a star item.
    • isExprItem

      public static boolean isExprItem(FrostlakeParser.SelectItemContext item)
    • rejectStandaloneInterval

      public static void rejectStandaloneInterval(FrostlakeParser.SelectListContext selectList)
      Snowflake refuses to project the UNIT-LESS interval literal on its own: SELECT INTERVAL '1 day' and the multi-part SELECT INTERVAL '1 day, 2 hours' both fail with "interval literal is not supported in this form" (live-verified). The UNIT-SUFFIXED spelling is a first-class value and projects fine — SELECT INTERVAL '1' DAY is typed INTERVAL DAY(9), aliases fine, and TO_VARCHAR of it is +1 — so only IntervalStringExpr is rejected here, never IntervalExpr.

      Both spellings stay legal as an operand of date arithmetic, so the test is on each item's ROOT expression: in DATE '2024-01-01' + INTERVAL '1 day' the root is the addition and the item stands.

    • getItemExpression

      public static org.antlr.v4.runtime.ParserRuleContext getItemExpression(FrostlakeParser.SelectItemContext item)
      The select item's full expression context (the booleanExpr wrapper) — for TEXT use: getOriginalText/getText of the whole projected item. Returns the full item even once booleanExpr carries a real OR/AND/NOT body (e.g. SELECT a AND b).
    • getItemValueExpr

      The select item's underlying value expression — for STRUCTURAL use: aggregate/window detection and per-group evaluation. Today booleanExpr is a trivial pass-through so this is simply its inner expression; when booleanExpr gains a real OR/AND/NOT body this becomes "unwrap the value alternative" and is null for a boolean projection.
    • unwrapValue

      Peel a booleanExpr to its underlying value expression (null if it is a boolean AND/OR/NOT).
    • unwrapParens

      The expression under any number of wrapping parentheses; a parenthesized BOOLEAN body ((a AND b)) stays put. Snowflake treats a parenthesized column reference exactly like the bare one when naming and validating a select item — SELECT (amount) projects a column named AMOUNT, and a CTAS accepts it without an alias (both live-verified).
    • isUnnamedExpressionItem

      public static boolean isUnnamedExpressionItem(FrostlakeParser.SelectItemContext item)
      Whether this select item is an EXPRESSION with no name of its own: unaliased and not a column reference. A (possibly parenthesized, possibly qualified) column reference and a CONNECT_BY_ROOT col item take the column's name; every other unaliased expression has only its source text. CTAS and CREATE VIEW refuse such items with "Missing column specification" (live-verified) because the projection cannot supply a declared column name. A boolean-bodied item (SELECT a AND b) has no value expression and no name either.
    • getItemAlias

      public static String getItemAlias(FrostlakeParser.SelectItemContext item)
      A select item's alias as CANONICAL TEXT, or null when it has none. Text rather than a parse context because the two spellings reach different rules: `AS x` matches the wider aliasName (which admits CASE, CAST, CONSTRAINT, CROSS, DEFAULT, INNER, JOIN and WHEN, all live-legal there), while the bare `x` matches identifier. Every caller wanted the canonical name anyway.
    • getStarModifiers

      The EXCLUDE/RENAME/REPLACE/ILIKE modifiers on a *, t.* or {*} item (empty if none).
    • getItemQualifier

      public static String getItemQualifier(FrostlakeParser.SelectItemContext item)
      Returns qualifier for the t.* / {t.*} forms, or null for a bare star.
    • objectStarLabel

      public static String objectStarLabel(FrostlakeParser.SelectItemContext item)
      The output column name Snowflake gives a braced-star item: the item's own source form with its identifiers canonicalised — {*}, {* EXCLUDE (A)}, {T.*} — or its explicit alias when it carries one. Rebuilt from the parse tree rather than re-read off the SQL text.