Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.schema.impl;
import com.hazelcast.org.apache.calcite.DataContext;
import com.hazelcast.org.apache.calcite.adapter.enumerable.CallImplementor;
import com.hazelcast.org.apache.calcite.adapter.enumerable.NullPolicy;
import com.hazelcast.org.apache.calcite.adapter.enumerable.ReflectiveCallNotNullImplementor;
import com.hazelcast.org.apache.calcite.adapter.enumerable.RexImpTable;
import com.hazelcast.org.apache.calcite.adapter.enumerable.RexToLixTranslator;
import com.hazelcast.org.apache.calcite.linq4j.tree.Expression;
import com.hazelcast.org.apache.calcite.linq4j.tree.Expressions;
import com.hazelcast.org.apache.calcite.rel.type.RelDataType;
import com.hazelcast.org.apache.calcite.rel.type.RelDataTypeFactory;
import com.hazelcast.org.apache.calcite.rex.RexCall;
import com.hazelcast.org.apache.calcite.schema.ImplementableFunction;
import com.hazelcast.org.apache.calcite.schema.QueryableTable;
import com.hazelcast.org.apache.calcite.schema.ScannableTable;
import com.hazelcast.org.apache.calcite.schema.SchemaPlus;
import com.hazelcast.org.apache.calcite.schema.Table;
import com.hazelcast.org.apache.calcite.schema.TableFunction;
import com.hazelcast.org.apache.calcite.util.BuiltInMethod;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.List;
import static com.hazelcast.org.apache.calcite.util.Static.RESOURCE;
/**
* Implementation of {@link com.hazelcast.org.apache.calcite.schema.TableFunction} based on a
* method.
*/
public class TableFunctionImpl extends ReflectiveFunctionBase implements
TableFunction, ImplementableFunction {
private final CallImplementor implementor;
/** Private constructor; use {@link #create}. */
private TableFunctionImpl(Method method, CallImplementor implementor) {
super(method);
this.implementor = implementor;
}
/** Creates a {@link TableFunctionImpl} from a class, looking for an "eval"
* method. Returns null if there is no such method. */
public static TableFunction create(Class> clazz) {
return create(clazz, "eval");
}
/** Creates a {@link TableFunctionImpl} from a class, looking for a method
* with a given name. Returns null if there is no such method. */
public static TableFunction create(Class> clazz, String methodName) {
final Method method = findMethod(clazz, methodName);
if (method == null) {
return null;
}
return create(method);
}
/** Creates a {@link TableFunctionImpl} from a method. */
public static TableFunction create(final Method method) {
if (!Modifier.isStatic(method.getModifiers())) {
Class clazz = method.getDeclaringClass();
if (!classHasPublicZeroArgsConstructor(clazz)) {
throw RESOURCE.requireDefaultConstructor(clazz.getName()).ex();
}
}
final Class> returnType = method.getReturnType();
if (!QueryableTable.class.isAssignableFrom(returnType)
&& !ScannableTable.class.isAssignableFrom(returnType)) {
return null;
}
CallImplementor implementor = createImplementor(method);
return new TableFunctionImpl(method, implementor);
}
public RelDataType getRowType(RelDataTypeFactory typeFactory,
List