org.apache.druid.sql.calcite.external.BaseUserDefinedTableMacro 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 org.apache.druid.sql.calcite.external;
import org.apache.calcite.adapter.enumerable.EnumUtils;
import org.apache.calcite.linq4j.tree.BlockBuilder;
import org.apache.calcite.linq4j.tree.Expression;
import org.apache.calcite.linq4j.tree.Expressions;
import org.apache.calcite.linq4j.tree.FunctionExpression;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rel.type.RelDataTypeFactory;
import org.apache.calcite.rel.type.RelDataTypeFactoryImpl;
import org.apache.calcite.schema.Function;
import org.apache.calcite.schema.FunctionParameter;
import org.apache.calcite.schema.TableMacro;
import org.apache.calcite.schema.TranslatableTable;
import org.apache.calcite.sql.SqlIdentifier;
import org.apache.calcite.sql.SqlKind;
import org.apache.calcite.sql.SqlOperatorBinding;
import org.apache.calcite.sql.type.ArraySqlType;
import org.apache.calcite.sql.type.SqlOperandMetadata;
import org.apache.calcite.sql.type.SqlOperandTypeInference;
import org.apache.calcite.sql.type.SqlReturnTypeInference;
import org.apache.calcite.sql.validate.SqlUserDefinedTableMacro;
import org.apache.calcite.util.NlsString;
import org.apache.druid.java.util.common.IAE;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Druid-specific version of {@link SqlUserDefinedTableMacro} which
* copies & overrides a bunch of code to handle string array arguments.
* Would be best if Calcite handled such argument: retire this class if
* we upgrade to a version of Calcite that handles this task.
*/
public class BaseUserDefinedTableMacro extends SqlUserDefinedTableMacro
{
protected final TableMacro macro;
public BaseUserDefinedTableMacro(
final SqlIdentifier opName,
final SqlReturnTypeInference returnTypeInference,
final SqlOperandTypeInference operandTypeInference,
final SqlOperandMetadata operandMetadata,
final TableMacro tableMacro
)
{
super(opName, SqlKind.OTHER_FUNCTION, returnTypeInference, operandTypeInference, operandMetadata, tableMacro);
// Because Calcite's copy of the macro is private
this.macro = tableMacro;
}
/**
* Copy of Calcite method {@link SqlUserDefinedTableMacro#getTable} to add array and named parameter handling.
*/
@Override
public TranslatableTable getTable(SqlOperatorBinding callBinding)
{
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy