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


Java SqlFunction类代码示例

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


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

示例1: populateWrappedCalciteOperators

import org.apache.calcite.sql.SqlFunction; //导入依赖的package包/类
private void populateWrappedCalciteOperators() {
  for(SqlOperator calciteOperator : inner.getOperatorList()) {
    final SqlOperator wrapper;
    if(calciteOperator instanceof SqlAggFunction) {
      wrapper = new DrillCalciteSqlAggFunctionWrapper((SqlAggFunction) calciteOperator,
          getFunctionListWithInference(calciteOperator.getName()));
    } else if(calciteOperator instanceof SqlFunction) {
      wrapper = new DrillCalciteSqlFunctionWrapper((SqlFunction) calciteOperator,
          getFunctionListWithInference(calciteOperator.getName()));
    } else {
      final String drillOpName = FunctionCallFactory.replaceOpWithFuncName(calciteOperator.getName());
      final List<DrillFuncHolder> drillFuncHolders = getFunctionListWithInference(drillOpName);
      if(drillFuncHolders.isEmpty() || calciteOperator == SqlStdOperatorTable.UNARY_MINUS || calciteOperator == SqlStdOperatorTable.UNARY_PLUS) {
        continue;
      }

      wrapper = new DrillCalciteSqlOperatorWrapper(calciteOperator, drillOpName, drillFuncHolders);
    }
    calciteToWrapper.put(calciteOperator, wrapper);
  }
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:22,代码来源:DrillOperatorTable.java

示例2: apply

import org.apache.calcite.sql.SqlFunction; //导入依赖的package包/类
@Override
public RexNode apply(RexBuilderContext context) {
	RelOptCluster cluster = context.getCluster();
	RelDataTypeFactory typeFactory = cluster.getTypeFactory();
	final SqlFunction UDF =
			new SqlUserDefinedFunction(
					new SqlIdentifier("RESOLVE_SIMPLE", SqlParserPos.ZERO),
					ReturnTypes.explicit(typeFactory.createJavaType(Object.class)),
					null,
					OperandTypes.ANY_ANY,
					ImmutableList.of(typeFactory.createTypeWithNullability(typeFactory.createJavaType(IObject.class), false),
							typeFactory.createJavaType(int.class)),
					ScalarFunctionImpl.create(IObjectMethods.class, "resolveSimpleValue"));
	RexBuilder b = context.getBuilder();
	RexNode rexNode = b.makeCall(UDF, context.getIObject(), b.makeLiteral(name));
	return b.makeCast(dataType, rexNode);
}
 
开发者ID:vlsi,项目名称:mat-calcite-plugin,代码行数:18,代码来源:ClassRowTypeCache.java

示例3: getSnapshot

import org.apache.calcite.sql.SqlFunction; //导入依赖的package包/类
@Override
public RexNode getSnapshot() {
    if (snapshot == null) {
        RelDataTypeFactory typeFactory = getCluster().getTypeFactory();
        RexBuilder b = getBuilder();
        final SqlFunction UDF =
                new SqlUserDefinedFunction(
                        new SqlIdentifier("GET_SNAPSHOT", SqlParserPos.ZERO),
                        ReturnTypes.explicit(typeFactory.createTypeWithNullability(typeFactory.createJavaType(ISnapshot.class), false)),
                        null,
                        OperandTypes.NUMERIC,
                        ImmutableList.of(typeFactory.createJavaType(Integer.class)),
                        ScalarFunctionImpl.create(SnapshotHolder.class, "get"));
        snapshot = b.makeCall(UDF, b.makeLiteral(snapshotId, typeFactory.createSqlType(SqlTypeName.INTEGER), false));
    }
    return snapshot;
}
 
开发者ID:vlsi,项目名称:mat-calcite-plugin,代码行数:18,代码来源:ExecutionRexBuilderContext.java

示例4: getIObject

import org.apache.calcite.sql.SqlFunction; //导入依赖的package包/类
public RexNode getIObject() {
    if (object == null) {
        RelDataTypeFactory typeFactory = getCluster().getTypeFactory();
        RexBuilder b = getBuilder();
        final SqlFunction GET_IOBJECT =
                new SqlUserDefinedFunction(
                        new SqlIdentifier("GET_IOBJECT", SqlParserPos.ZERO),
                        ReturnTypes.explicit(typeFactory.createTypeWithNullability(typeFactory.createJavaType(IObject.class), false)),
                        null,
                        OperandTypes.ANY_ANY,
                        ImmutableList.of(typeFactory.createTypeWithNullability(typeFactory.createJavaType(ISnapshot.class), false),
                                typeFactory.createJavaType(int.class)),
                        ScalarFunctionImpl.create(ISnapshotMethods.class, "getIObject"));
        object = b.makeCall(GET_IOBJECT, getSnapshot(), getIObjectId());
    }
    return object;
}
 
开发者ID:vlsi,项目名称:mat-calcite-plugin,代码行数:18,代码来源:RexBuilderContext.java

示例5: convertFunction

import org.apache.calcite.sql.SqlFunction; //导入依赖的package包/类
public RexNode convertFunction(
    SqlRexContext cx,
    SqlFunction fun,
    SqlCall call) {
  final List<SqlNode> operands = call.getOperandList();
  final List<RexNode> exprs = convertExpressionList(cx, operands,
      SqlOperandTypeChecker.Consistency.NONE);
  if (fun.getFunctionType() == SqlFunctionCategory.USER_DEFINED_CONSTRUCTOR) {
    return makeConstructorCall(cx, fun, exprs);
  }
  RelDataType returnType =
      cx.getValidator().getValidatedNodeTypeIfKnown(call);
  if (returnType == null) {
    returnType = cx.getRexBuilder().deriveReturnType(fun, exprs);
  }
  return cx.getRexBuilder().makeCall(returnType, fun, exprs);
}
 
开发者ID:apache,项目名称:calcite,代码行数:18,代码来源:StandardConvertletTable.java

示例6: unparseDatetimeFunction

import org.apache.calcite.sql.SqlFunction; //导入依赖的package包/类
/**
 * Most dialects that natively support datetime floor will use this.
 * In those cases the call will look like TRUNC(datetime, 'year').
 *
 * @param writer SqlWriter
 * @param call SqlCall
 * @param funName Name of the sql function to call
 * @param datetimeFirst Specify the order of the datetime &amp; timeUnit
 * arguments
 */
public static void unparseDatetimeFunction(SqlWriter writer, SqlCall call,
    String funName, Boolean datetimeFirst) {
  SqlFunction func = new SqlFunction(funName, SqlKind.OTHER_FUNCTION,
      ReturnTypes.ARG0_NULLABLE_VARYING, null, null,
      SqlFunctionCategory.STRING);

  SqlCall call1;
  if (datetimeFirst) {
    call1 = call;
  } else {
    // switch order of operands
    SqlNode op1 = call.operand(0);
    SqlNode op2 = call.operand(1);

    call1 = call.getOperator().createCall(call.getParserPosition(), op2, op1);
  }

  SqlUtil.unparseFunctionSyntax(func, writer, call1);
}
 
开发者ID:apache,项目名称:calcite,代码行数:30,代码来源:SqlFloorFunction.java

示例7: getHistogramOp

import org.apache.calcite.sql.SqlFunction; //导入依赖的package包/类
/**
 * Returns the histogram operator corresponding to a given aggregate
 * function.
 *
 * <p>For example, <code>getHistogramOp
 *({@link SqlStdOperatorTable#MIN}}</code> returns
 * {@link SqlStdOperatorTable#HISTOGRAM_MIN}.
 *
 * @param aggFunction An aggregate function
 * @return Its histogram function, or null
 */
SqlFunction getHistogramOp(SqlAggFunction aggFunction) {
	if (aggFunction == SqlStdOperatorTable.MIN) {
		return SqlStdOperatorTable.HISTOGRAM_MIN;
	} else if (aggFunction == SqlStdOperatorTable.MAX) {
		return SqlStdOperatorTable.HISTOGRAM_MAX;
	} else if (aggFunction == SqlStdOperatorTable.FIRST_VALUE) {
		return SqlStdOperatorTable.HISTOGRAM_FIRST_VALUE;
	} else if (aggFunction == SqlStdOperatorTable.LAST_VALUE) {
		return SqlStdOperatorTable.HISTOGRAM_LAST_VALUE;
	} else {
		return null;
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:25,代码来源:SqlToRelConverter.java

示例8: DrillCalciteSqlFunctionWrapper

import org.apache.calcite.sql.SqlFunction; //导入依赖的package包/类
public DrillCalciteSqlFunctionWrapper(
    final SqlFunction wrappedFunction,
  final List<DrillFuncHolder> functions) {
  super(wrappedFunction.getName(),
      wrappedFunction.getSqlIdentifier(),
      wrappedFunction.getKind(),
      TypeInferenceUtils.getDrillSqlReturnTypeInference(
          wrappedFunction.getName(),
          functions),
      wrappedFunction.getOperandTypeInference(),
      Checker.ANY_CHECKER,
      wrappedFunction.getParamTypes(),
      wrappedFunction.getFunctionType());
  this.operator = wrappedFunction;
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:16,代码来源:DrillCalciteSqlFunctionWrapper.java

示例9: extractSqlOperatorFromWrapper

import org.apache.calcite.sql.SqlFunction; //导入依赖的package包/类
/**
 * This static method will extract the SqlFunction inside the given SqlFunction if the given SqlFunction is wrapped
 * in DrillCalciteSqlFunctionWrapper and will just return the given SqlFunction if it is not wrapped.
 */
public static SqlFunction extractSqlOperatorFromWrapper(final SqlFunction sqlFunction) {
  if(sqlFunction instanceof DrillCalciteSqlWrapper) {
    return (SqlFunction) ((DrillCalciteSqlWrapper) sqlFunction).getOperator();
  } else {
    return sqlFunction;
  }
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:12,代码来源:DrillCalciteWrapperUtility.java

示例10: visit

import org.apache.calcite.sql.SqlFunction; //导入依赖的package包/类
@Override
public Expression visit(SqlCall call) {
    SqlOperator sqlOperator = call.getOperator();
    if (sqlOperator instanceof SqlBinaryOperator) {
        return visitBinaryOperator((SqlBinaryOperator) sqlOperator, call.getOperandList().get(0),
                call.getOperandList().get(1));
    } else if (sqlOperator instanceof SqlSpecialOperator) {
        return visitSqlSpecialOperator((SqlSpecialOperator) sqlOperator, call.getOperandList());
    } else if (sqlOperator instanceof SqlFunction) {
        SqlFunction sqlFunction = (SqlFunction) sqlOperator;
        if (sqlFunction instanceof SqlAggFunction) {
            return visitAggregateFunction(sqlFunction.getName(), call.getOperandList());
        } else if (sqlFunction instanceof SqlUnresolvedFunction) {
            String udfName = sqlFunction.getName().toUpperCase();
            if (catalogUdfs.containsKey(udfName)) {
                Udf udfInfo = catalogUdfs.get(udfName);
                if (udfInfo.isAggregate()) {
                    return visitUserDefinedAggregateFunction(udfInfo, call.getOperandList());
                } else {
                    return visitUserDefinedFunction(udfInfo, call.getOperandList());
                }
            } else {
                throw new UnsupportedOperationException("Unknown built-in or User defined function '" + udfName + "'");
            }
        } else {
            return visitFunction(sqlFunction.getName(), call.getOperandList());
        }
    } else {
        throw new UnsupportedOperationException("Operator " + sqlOperator.getName() + " is not supported");
    }
}
 
开发者ID:hortonworks,项目名称:streamline,代码行数:32,代码来源:ExpressionGenerator.java

示例11: getHistogramOp

import org.apache.calcite.sql.SqlFunction; //导入依赖的package包/类
/**
 * Returns the histogram operator corresponding to a given aggregate
 * function.
 *
 * <p>For example, <code>getHistogramOp
 *({@link SqlStdOperatorTable#MIN}}</code> returns
 * {@link SqlStdOperatorTable#HISTOGRAM_MIN}.
 *
 * @param aggFunction An aggregate function
 * @return Its histogram function, or null
 */
SqlFunction getHistogramOp(SqlAggFunction aggFunction) {
  if (aggFunction == SqlStdOperatorTable.MIN) {
    return SqlStdOperatorTable.HISTOGRAM_MIN;
  } else if (aggFunction == SqlStdOperatorTable.MAX) {
    return SqlStdOperatorTable.HISTOGRAM_MAX;
  } else if (aggFunction == SqlStdOperatorTable.FIRST_VALUE) {
    return SqlStdOperatorTable.HISTOGRAM_FIRST_VALUE;
  } else if (aggFunction == SqlStdOperatorTable.LAST_VALUE) {
    return SqlStdOperatorTable.HISTOGRAM_LAST_VALUE;
  } else {
    return null;
  }
}
 
开发者ID:apache,项目名称:kylin,代码行数:25,代码来源:SqlToRelConverter.java

示例12: convertFloorCeil

import org.apache.calcite.sql.SqlFunction; //导入依赖的package包/类
protected RexNode convertFloorCeil(SqlRexContext cx, SqlCall call) {
  final boolean floor = call.getKind() == SqlKind.FLOOR;
  // Rewrite floor, ceil of interval
  if (call.operandCount() == 1
      && call.operand(0) instanceof SqlIntervalLiteral) {
    final SqlIntervalLiteral literal = call.operand(0);
    SqlIntervalLiteral.IntervalValue interval =
        (SqlIntervalLiteral.IntervalValue) literal.getValue();
    BigDecimal val =
        interval.getIntervalQualifier().getStartUnit().multiplier;
    RexNode rexInterval = cx.convertExpression(literal);

    final RexBuilder rexBuilder = cx.getRexBuilder();
    RexNode zero = rexBuilder.makeExactLiteral(BigDecimal.valueOf(0));
    RexNode cond = ge(rexBuilder, rexInterval, zero);

    RexNode pad =
        rexBuilder.makeExactLiteral(val.subtract(BigDecimal.ONE));
    RexNode cast = rexBuilder.makeReinterpretCast(
        rexInterval.getType(), pad, rexBuilder.makeLiteral(false));
    RexNode sum = floor
        ? minus(rexBuilder, rexInterval, cast)
        : plus(rexBuilder, rexInterval, cast);

    RexNode kase = floor
        ? case_(rexBuilder, rexInterval, cond, sum)
        : case_(rexBuilder, sum, cond, rexInterval);

    RexNode factor = rexBuilder.makeExactLiteral(val);
    RexNode div = divideInt(rexBuilder, kase, factor);
    return multiply(rexBuilder, div, factor);
  }

  // normal floor, ceil function
  return convertFunction(cx, (SqlFunction) call.getOperator(), call);
}
 
开发者ID:apache,项目名称:calcite,代码行数:37,代码来源:StandardConvertletTable.java

示例13: convertExtract

import org.apache.calcite.sql.SqlFunction; //导入依赖的package包/类
/**
 * Converts a call to the {@code EXTRACT} function.
 *
 * <p>Called automatically via reflection.
 */
public RexNode convertExtract(
    SqlRexContext cx,
    SqlExtractFunction op,
    SqlCall call) {
  return convertFunction(cx, (SqlFunction) call.getOperator(), call);
}
 
开发者ID:apache,项目名称:calcite,代码行数:12,代码来源:StandardConvertletTable.java

示例14: makeConstructorCall

import org.apache.calcite.sql.SqlFunction; //导入依赖的package包/类
private static RexNode makeConstructorCall(
    SqlRexContext cx,
    SqlFunction constructor,
    List<RexNode> exprs) {
  final RexBuilder rexBuilder = cx.getRexBuilder();
  RelDataType type = rexBuilder.deriveReturnType(constructor, exprs);

  int n = type.getFieldCount();
  ImmutableList.Builder<RexNode> initializationExprs =
      ImmutableList.builder();
  final InitializerContext initializerContext = new InitializerContext() {
    public RexBuilder getRexBuilder() {
      return rexBuilder;
    }

    public RexNode convertExpression(SqlNode e) {
      throw new UnsupportedOperationException();
    }
  };
  for (int i = 0; i < n; ++i) {
    initializationExprs.add(
        cx.getInitializerExpressionFactory().newAttributeInitializer(
            type, constructor, i, exprs, initializerContext));
  }

  List<RexNode> defaultCasts =
      RexUtil.generateCastExpressions(
          rexBuilder,
          type,
          initializationExprs.build());

  return rexBuilder.makeNewInvocation(type, defaultCasts);
}
 
开发者ID:apache,项目名称:calcite,代码行数:34,代码来源:StandardConvertletTable.java

示例15: handleUnresolvedFunction

import org.apache.calcite.sql.SqlFunction; //导入依赖的package包/类
public CalciteException handleUnresolvedFunction(SqlCall call,
    SqlFunction unresolvedFunction, List<RelDataType> argTypes,
    List<String> argNames) {
  // For builtins, we can give a better error message
  final List<SqlOperator> overloads = new ArrayList<>();
  opTab.lookupOperatorOverloads(unresolvedFunction.getNameAsId(), null,
      SqlSyntax.FUNCTION, overloads);
  if (overloads.size() == 1) {
    SqlFunction fun = (SqlFunction) overloads.get(0);
    if ((fun.getSqlIdentifier() == null)
        && (fun.getSyntax() != SqlSyntax.FUNCTION_ID)) {
      final int expectedArgCount =
          fun.getOperandCountRange().getMin();
      throw newValidationError(call,
          RESOURCE.invalidArgCount(call.getOperator().getName(),
              expectedArgCount));
    }
  }

  AssignableOperandTypeChecker typeChecking =
      new AssignableOperandTypeChecker(argTypes, argNames);
  String signature =
      typeChecking.getAllowedSignatures(
          unresolvedFunction,
          unresolvedFunction.getName());
  throw newValidationError(call,
      RESOURCE.validatorUnknownFunction(signature));
}
 
开发者ID:apache,项目名称:calcite,代码行数:29,代码来源:SqlValidatorImpl.java


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