Class SiblingAliasSubstitution

java.lang.Object
dev.frostlake.executor.SiblingAliasSubstitution

public final class SiblingAliasSubstitution extends Object
An expression with every SIBLING SELECT ALIAS it mentions replaced by that alias's defining expression. A select list may name its own output — SELECT d AS dd, MEDIAN(dd) — and a name used that way means the expression behind it, wherever in the expression it appears rather than only when it IS the whole expression.

The substitution repeats, because an alias may be defined in terms of another (SELECT d AS dd, dd AS ee, … ee …), and stops as soon as a pass changes nothing. It is bounded at five passes: that is enough for any chain worth writing, and it means a definition that mentions its own name cannot spin here.

The replacement is by IDENTIFIER TOKEN, so a name inside a string literal or forming part of a longer identifier is left alone. Whether an alias should be substituted at all is the CALLER's decision — a real column of the same name outranks the alias, and only the caller knows the relations in scope.

  • Method Details

    • applied

      public static String applied(String text, List<String> names, List<String> exprs)
      Parameters:
      text - the expression text
      names - the alias names, canonical
      exprs - their defining expressions, 1:1 with names
      Returns:
      the text with those aliases expanded