class GridSqlUnion extends GridSqlQuery {
    /** */
    public static final int LEFT_CHILD = 2;

    /** */
    public static final int RIGHT_CHILD = 3;

    /** */
    private SelectUnion.UnionType unionType;

    /** */
    private GridSqlQuery right;

    /** */
    private GridSqlQuery left;

    /** {@inheritDoc} */
    @SuppressWarnings("unchecked")
    @Override public <E extends GridSqlAst> E child(int childIdx) {
        if (childIdx < LEFT_CHILD)
            return super.child(childIdx);

        switch (childIdx) {
            case LEFT_CHILD:
                assert left != null;

                return (E)left;

            case RIGHT_CHILD:
                assert right != null;

                return (E)right;

            default:
                throw new IllegalStateException("Child index: " + childIdx);
        }
    }

    /** {@inheritDoc} */
    @Override public <E extends GridSqlAst> void child(int childIdx, E child) {
        if (childIdx < LEFT_CHILD) {
            super.child(childIdx, child);

            return;
        }

        switch (childIdx) {
            case LEFT_CHILD:
                left = (GridSqlQuery)child;

                break;

            case RIGHT_CHILD:
                right = (GridSqlQuery)child;

                break;

            default:
                throw new IllegalStateException("Child index: " + childIdx);
        }
    }

    /** {@inheritDoc} */
    @Override public int size() {<FILL_FUNCTION_BODY>}

    /** {@inheritDoc} */
    @Override protected int visibleColumns() {
        return left.visibleColumns();
    }

    /** {@inheritDoc} */
    @Override protected GridSqlElement column(int col) {
        throw new IllegalStateException();
    }

    /** {@inheritDoc} */
    @Override public String getSQL() {
        char delim = delimeter();

        StatementBuilder buff = new StatementBuilder(explain() ? "EXPLAIN " + delim : "");

        buff.append('(').append(left.getSQL()).append(')');

        switch (unionType()) {
            case UNION_ALL:
                buff.append(delim).append("UNION ALL").append(delim);
                break;

            case UNION:
                buff.append(delim).append("UNION").append(delim);
                break;

            case INTERSECT:
                buff.append(delim).append("INTERSECT").append(delim);
                break;

            case EXCEPT:
                buff.append(delim).append("EXCEPT").append(delim);
                break;

            default:
                throw new CacheException("type=" + unionType);
        }

        buff.append('(').append(right.getSQL()).append(')');

        getSortLimitSQL(buff);

        return buff.toString();
    }

    /** {@inheritDoc} */
    @Override public boolean skipMergeTable() {
        return unionType() == SelectUnion.UnionType.UNION_ALL && sort().isEmpty() &&
            offset() == null && limit() == null &&
            left().skipMergeTable() && right().skipMergeTable();
    }

    /**
     * @return Union type.
     */
    public SelectUnion.UnionType unionType() {
        return unionType;
    }

    /**
     * @param unionType New union type.
     */
    public void unionType(SelectUnion.UnionType unionType) {
        this.unionType = unionType;
    }

    /**
     * @return Right.
     */
    public GridSqlQuery right() {
        return right;
    }

    /**
     * @param right New right.
     */
    public void right(GridSqlQuery right) {
        this.right = right;
    }

    /**
     * @return Left.
     */
    public GridSqlQuery left() {
        return left;
    }

    /**
     * @param left New left.
     */
    public void left(GridSqlQuery left) {
        this.left = left;
    }
}

        return 4; // OFFSET + LIMIT + LEFT + RIGHT
    
<methods>public non-sealed void <init>() ,public void addSort(org.apache.ignite.internal.processors.query.h2.sql.GridSqlSortColumn) ,public E child() ,public E child(int) ,public void child(int, E) ,public void clearSort() ,public boolean hasOffsetLimit() ,public org.apache.ignite.internal.processors.query.h2.sql.GridSqlAst offset() ,public void offset(org.apache.ignite.internal.processors.query.h2.sql.GridSqlAst) ,public org.apache.ignite.internal.processors.query.h2.sql.GridSqlType resultType() ,public abstract boolean skipMergeTable() ,public List<org.apache.ignite.internal.processors.query.h2.sql.GridSqlSortColumn> sort() <variables>public static final int LIMIT_CHILD,public static final int OFFSET_CHILD,private org.apache.ignite.internal.processors.query.h2.sql.GridSqlAst offset,protected List<org.apache.ignite.internal.processors.query.h2.sql.GridSqlSortColumn> sort