All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hazelcast.org.apache.calcite.sql.util.SqlBasicVisitor Maven / Gradle / Ivy

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to you under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hazelcast.org.apache.calcite.sql.util;

import com.hazelcast.org.apache.calcite.sql.SqlCall;
import com.hazelcast.org.apache.calcite.sql.SqlDataTypeSpec;
import com.hazelcast.org.apache.calcite.sql.SqlDynamicParam;
import com.hazelcast.org.apache.calcite.sql.SqlIdentifier;
import com.hazelcast.org.apache.calcite.sql.SqlIntervalQualifier;
import com.hazelcast.org.apache.calcite.sql.SqlLiteral;
import com.hazelcast.org.apache.calcite.sql.SqlNode;
import com.hazelcast.org.apache.calcite.sql.SqlNodeList;

/**
 * Basic implementation of {@link SqlVisitor} which does nothing at each node.
 *
 * 

This class is useful as a base class for classes which implement the * {@link SqlVisitor} interface. The derived class can override whichever * methods it chooses. * * @param Return type */ public class SqlBasicVisitor implements SqlVisitor { //~ Methods ---------------------------------------------------------------- public R visit(SqlLiteral literal) { return null; } public R visit(SqlCall call) { return call.getOperator().acceptCall(this, call); } public R visit(SqlNodeList nodeList) { R result = null; for (int i = 0; i < nodeList.size(); i++) { SqlNode node = nodeList.get(i); result = node.accept(this); } return result; } public R visit(SqlIdentifier id) { return null; } public R visit(SqlDataTypeSpec type) { return null; } public R visit(SqlDynamicParam param) { return null; } public R visit(SqlIntervalQualifier intervalQualifier) { return null; } //~ Inner Interfaces ------------------------------------------------------- /** Argument handler. * * @param result type */ public interface ArgHandler { /** Returns the result of visiting all children of a call to an operator, * then the call itself. * *

Typically the result will be the result of the last child visited, or * (if R is {@link Boolean}) whether all children were visited * successfully. */ R result(); /** Visits a particular operand of a call, using a given visitor. */ R visitChild( SqlVisitor visitor, SqlNode expr, int i, SqlNode operand); } //~ Inner Classes ---------------------------------------------------------- /** * Default implementation of {@link ArgHandler} which merely calls * {@link SqlNode#accept} on each operand. * * @param result type */ public static class ArgHandlerImpl implements ArgHandler { private static final ArgHandler INSTANCE = new ArgHandlerImpl(); @SuppressWarnings("unchecked") public static ArgHandler instance() { return INSTANCE; } public R result() { return null; } public R visitChild( SqlVisitor visitor, SqlNode expr, int i, SqlNode operand) { if (operand == null) { return null; } return operand.accept(visitor); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy