当前位置: 首页>>代码示例>>Java>>正文


Java ScalarFunction类代码示例

本文整理汇总了Java中org.apache.calcite.schema.ScalarFunction的典型用法代码示例。如果您正苦于以下问题:Java ScalarFunction类的具体用法?Java ScalarFunction怎么用?Java ScalarFunction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ScalarFunction类属于org.apache.calcite.schema包,在下文中一共展示了ScalarFunction类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createAll

import org.apache.calcite.schema.ScalarFunction; //导入依赖的package包/类
/**
 * Creates {@link org.apache.calcite.schema.ScalarFunction} for each method in
 * a given class.
 */
public static ImmutableMultimap<String, ScalarFunction> createAll(
    Class<?> clazz) {
  final ImmutableMultimap.Builder<String, ScalarFunction> builder =
      ImmutableMultimap.builder();
  for (Method method : clazz.getMethods()) {
    if (method.getDeclaringClass() == Object.class) {
      continue;
    }
    if (!Modifier.isStatic(method.getModifiers())
        && !classHasPublicZeroArgsConstructor(clazz)) {
      continue;
    }
    final ScalarFunction function = create(method);
    builder.put(method.getName(), function);
  }
  return builder.build();
}
 
开发者ID:apache,项目名称:calcite,代码行数:22,代码来源:ScalarFunctionImpl.java

示例2: infer

import org.apache.calcite.schema.ScalarFunction; //导入依赖的package包/类
private static SqlReturnTypeInference infer(final ScalarFunction function) {
  return new SqlReturnTypeInference() {
    public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
      final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
      final RelDataType type;
      if (function instanceof ScalarFunctionImpl) {
        type = ((ScalarFunctionImpl) function).getReturnType(typeFactory,
            opBinding);
      } else {
        type = function.getReturnType(typeFactory);
      }
      return toSql(typeFactory, type);
    }
  };
}
 
开发者ID:apache,项目名称:calcite,代码行数:16,代码来源:CalciteCatalogReader.java

示例3: create

import org.apache.calcite.schema.ScalarFunction; //导入依赖的package包/类
/**
 * Creates {@link org.apache.calcite.schema.ScalarFunction} from given method.
 * When {@code eval} method does not suit, {@code null} is returned.
 *
 * @param method method that is used to implement the function
 * @return created {@link ScalarFunction} or null
 */
public static ScalarFunction create(Method method) {
  if (!Modifier.isStatic(method.getModifiers())) {
    Class clazz = method.getDeclaringClass();
    if (!classHasPublicZeroArgsConstructor(clazz)) {
      throw RESOURCE.requireDefaultConstructor(clazz.getName()).ex();
    }
  }
  CallImplementor implementor = createImplementor(method);
  return new ScalarFunctionImpl(method, implementor);
}
 
开发者ID:apache,项目名称:calcite,代码行数:18,代码来源:ScalarFunctionImpl.java

示例4: toOp

import org.apache.calcite.schema.ScalarFunction; //导入依赖的package包/类
/** Converts a function to a {@link org.apache.calcite.sql.SqlOperator}.
 *
 * <p>The {@code typeFactory} argument is technical debt; see [CALCITE-2082]
 * Remove RelDataTypeFactory argument from SqlUserDefinedAggFunction
 * constructor. */
private static SqlOperator toOp(RelDataTypeFactory typeFactory,
    SqlIdentifier name, final Function function) {
  List<RelDataType> argTypes = new ArrayList<>();
  List<SqlTypeFamily> typeFamilies = new ArrayList<>();
  for (FunctionParameter o : function.getParameters()) {
    final RelDataType type = o.getType(typeFactory);
    argTypes.add(type);
    typeFamilies.add(
        Util.first(type.getSqlTypeName().getFamily(), SqlTypeFamily.ANY));
  }
  final Predicate<Integer> optional =
      new PredicateImpl<Integer>() {
        public boolean test(Integer input) {
          return function.getParameters().get(input).isOptional();
        }
      };
  final FamilyOperandTypeChecker typeChecker =
      OperandTypes.family(typeFamilies, optional);
  final List<RelDataType> paramTypes = toSql(typeFactory, argTypes);
  if (function instanceof ScalarFunction) {
    return new SqlUserDefinedFunction(name, infer((ScalarFunction) function),
        InferTypes.explicit(argTypes), typeChecker, paramTypes, function);
  } else if (function instanceof AggregateFunction) {
    return new SqlUserDefinedAggFunction(name,
        infer((AggregateFunction) function), InferTypes.explicit(argTypes),
        typeChecker, (AggregateFunction) function, false, false, typeFactory);
  } else if (function instanceof TableMacro) {
    return new SqlUserDefinedTableMacro(name, ReturnTypes.CURSOR,
        InferTypes.explicit(argTypes), typeChecker, paramTypes,
        (TableMacro) function);
  } else if (function instanceof TableFunction) {
    return new SqlUserDefinedTableFunction(name, ReturnTypes.CURSOR,
        InferTypes.explicit(argTypes), typeChecker, paramTypes,
        (TableFunction) function);
  } else {
    throw new AssertionError("unknown function type " + function);
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:44,代码来源:CalciteCatalogReader.java

示例5: registerFunction

import org.apache.calcite.schema.ScalarFunction; //导入依赖的package包/类
/**
 * Register custom function from given static method with this {@link SQLExecEnvironment}
 *
 * @param name Name of the scalar SQL function that needs make available to SQL Statement
 * @param clazz {@link Class} which contains given static method
 * @param methodName Name of the method from given clazz
 *
 * @return Return this {@link SQLExecEnvironment}
 */
public SQLExecEnvironment registerFunction(String name, Class clazz, String methodName)
{
  Preconditions.checkNotNull(name, "Function name cannot be null");
  ScalarFunction scalarFunction = ScalarFunctionImpl.create(clazz, methodName);
  return registerFunction(name, scalarFunction);
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:16,代码来源:SQLExecEnvironment.java


注:本文中的org.apache.calcite.schema.ScalarFunction类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。