apache calcite源码阅读(一)org.apache.calcite.sql下的SqlNode.class

SqlNode是一个抽象类,代表SQL语句语法树的节点,实现了Cloneable接口。类中包含位置信息、克隆方法、节点类型获取、验证和转换为SQL字符串等功能。它支持表达式验证、单调性检查和访问者模式,用于处理和解析SQL语句。
public abstract class SqlNode implements Cloneable {
    public static final SqlNode[] EMPTY_ARRAY = new SqlNode[0];
    protected final SqlParserPos pos;

    SqlNode(SqlParserPos pos) {
        this.pos = (SqlParserPos)Objects.requireNonNull(pos, "pos");
    }

    /** @deprecated */
    @Deprecated
    public Object clone() {
        return this.clone(this.getParserPosition());
    }

    public static <E extends SqlNode> E clone(E e) {
        return e.clone(e.pos);
    }

    public abstract SqlNode clone(SqlParserPos var1);

    public SqlKind getKind() {
        return SqlKind.OTHER;
    }

    public final boolean isA(Set<SqlKind> category) {
        return this.getKind().belongsTo(category);
    }

    /** @deprecated */
    @Deprecated
    public static SqlNode[] cloneArray(SqlNode[] nodes) {
        SqlNode[] clones = (SqlNode[])nodes.clone();

        for(int i = 0; i < clones.length; ++i) {
            SqlNode node = clones[i];
            if (node != null) {
                clones[i] = clone(node);
            }
        }

        return clones;
    }

    public String toString() {
        return this.toSqlString((c) -> {
            return c.withDialect(AnsiSqlDialect.DEFAULT).withAlwaysUseParentheses(false).withSelectListItemsOnSeparateLines(false).withUpdateSetListNewline(false).withIndentation(0);
        }).getSql();
    }

    public SqlString toSqlString(UnaryOperator<SqlWriterConfig> transform) {
        SqlWriterConfig config = (SqlWriterConfig)transform.apply(SqlPrettyWriter.config());
        SqlPrettyWriter writer = new SqlPrettyWriter(config);
        this.unparse(writer, 0, 0);
        return writer.toSqlString();
    }

    public SqlString toSqlString(@Nullable SqlDialect dialect, boolean forceParens) {
        return this.toSqlString((c) -> {
            return c.withDialect((SqlDialect)Util.first(dialect, AnsiSqlDialect.DEFAULT)).withAlwaysUseParentheses(forceParens).withSelectListItemsOnSeparateLines(false).withUpdateSetListNewl
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值