Example #1
0
    public SqlNode visit(SqlIdentifier id) {
      // First check for builtin functions which don't have parentheses,
      // like "LOCALTIME".
      final SqlCall call = SqlUtil.makeCall(getScope().getValidator().getOperatorTable(), id);
      if (call != null) {
        return call;
      }

      return getScope().fullyQualify(id).identifier;
    }
Example #2
0
  /**
   * Derives an alias for a node, and invents a mangled identifier if it cannot.
   *
   * <p>Examples:
   *
   * <ul>
   *   <li>Alias: "1 + 2 as foo" yields "foo"
   *   <li>Identifier: "foo.bar.baz" yields "baz"
   *   <li>Anything else yields "expr$<i>ordinal</i>"
   * </ul>
   *
   * @return An alias, if one can be derived; or a synthetic alias "expr$<i>ordinal</i>" if ordinal
   *     &lt; 0; otherwise null
   */
  public static String getAlias(SqlNode node, int ordinal) {
    switch (node.getKind()) {
      case AS:
        // E.g. "1 + 2 as foo" --> "foo"
        return ((SqlCall) node).operand(1).toString();

      case OVER:
        // E.g. "bids over w" --> "bids"
        return getAlias(((SqlCall) node).operand(0), ordinal);

      case IDENTIFIER:
        // E.g. "foo.bar" --> "bar"
        return Util.last(((SqlIdentifier) node).names);

      default:
        if (ordinal < 0) {
          return null;
        } else {
          return SqlUtil.deriveAliasFromOrdinal(ordinal);
        }
    }
  }
Example #3
0
 /**
  * Creates a character string literal from an {@link NlsString}.
  *
  * <p>If the string's charset and collation are not set, uses the system defaults.
  */
 public RexLiteral makeCharLiteral(NlsString str) {
   assert str != null;
   RelDataType type = SqlUtil.createNlsStringType(typeFactory, str);
   return makeLiteral(str, type, SqlTypeName.CHAR);
 }