Java Code Examples for org.apache.calcite.sql.SqlOperator#getOperandTypeChecker()

The following examples show how to use org.apache.calcite.sql.SqlOperator#getOperandTypeChecker() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StandardConvertletTable.java    From Bats with Apache License 2.0 6 votes vote down vote up
/** Converts a {@link SqlCall} to a {@link RexCall} with a perhaps different
 * operator. */
private RexNode convertCall(
    SqlRexContext cx,
    SqlCall call,
    SqlOperator op) {
  final List<SqlNode> operands = call.getOperandList();
  final RexBuilder rexBuilder = cx.getRexBuilder();
  final SqlOperandTypeChecker.Consistency consistency =
      op.getOperandTypeChecker() == null
          ? SqlOperandTypeChecker.Consistency.NONE
          : op.getOperandTypeChecker().getConsistency();
  final List<RexNode> exprs =
      convertExpressionList(cx, operands, consistency);
  RelDataType type = rexBuilder.deriveReturnType(op, exprs);
  return rexBuilder.makeCall(type, op, RexUtil.flatten(exprs, op));
}
 
Example 2
Source File: ConvertletTable.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
/** Converts a {@link SqlCall} to a {@link RexCall} with a perhaps different
 * operator. */
private RexNode convertCall(
    SqlRexContext cx,
    SqlCall call,
    SqlOperator op) {
  final List<SqlNode> operands = call.getOperandList();
  final RexBuilder rexBuilder = cx.getRexBuilder();
  final SqlOperandTypeChecker.Consistency consistency =
      op.getOperandTypeChecker() == null
          ? SqlOperandTypeChecker.Consistency.NONE
          : op.getOperandTypeChecker().getConsistency();
  final List<RexNode> exprs =
      convertExpressionList(cx, operands, consistency);
  RelDataType type = rexBuilder.deriveReturnType(op, exprs);
  return rexBuilder.makeCall(type, op, RexUtil.flatten(exprs, op));
}
 
Example 3
Source File: DocumentationTest.java    From calcite with Apache License 2.0 6 votes vote down vote up
private void addOperators(Map<String, PatternOp> map, String prefix,
    List<SqlOperator> operatorList) {
  for (SqlOperator op : operatorList) {
    final String name = op.getName().equals("TRANSLATE3") ? "TRANSLATE"
        : op.getName();
    if (op instanceof SqlSpecialOperator
        || !name.matches("^[a-zA-Z][a-zA-Z0-9_]*$")) {
      continue;
    }
    final String regex;
    if (op instanceof SqlOverlapsOperator) {
      regex = "[ ]*<td>period1 " + name + " period2</td>";
    } else if (op instanceof SqlFunction
        && (op.getOperandTypeChecker() == null
            || op.getOperandTypeChecker().getOperandCountRange().getMin()
                != 0)) {
      regex = prefix + "\\| .*" + name + "\\(.*";
    } else {
      regex = prefix + "\\| .*" + name + ".*";
    }
    map.put(regex, new PatternOp(Pattern.compile(regex), name));
  }
}
 
Example 4
Source File: StandardConvertletTable.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Converts a {@link SqlCall} to a {@link RexCall} with a perhaps different
 * operator. */
private RexNode convertCall(
    SqlRexContext cx, SqlOperator op, List<SqlNode> operands) {
  final RexBuilder rexBuilder = cx.getRexBuilder();
  final SqlOperandTypeChecker.Consistency consistency =
      op.getOperandTypeChecker() == null
          ? SqlOperandTypeChecker.Consistency.NONE
          : op.getOperandTypeChecker().getConsistency();
  final List<RexNode> exprs =
      convertExpressionList(cx, operands, consistency);
  RelDataType type = rexBuilder.deriveReturnType(op, exprs);
  return rexBuilder.makeCall(type, op, RexUtil.flatten(exprs, op));
}
 
Example 5
Source File: SqlValidatorImpl.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
private static void findAllValidFunctionNames(
	List<String> names,
	SqlValidator validator,
	Collection<SqlMoniker> result,
	SqlParserPos pos) {
	// a function name can only be 1 part
	if (names.size() > 1) {
		return;
	}
	for (SqlOperator op : validator.getOperatorTable().getOperatorList()) {
		SqlIdentifier curOpId =
			new SqlIdentifier(
				op.getName(),
				pos);

		final SqlCall call =
			SqlUtil.makeCall(
				validator.getOperatorTable(),
				curOpId);
		if (call != null) {
			result.add(
				new SqlMonikerImpl(
					op.getName(),
					SqlMonikerType.FUNCTION));
		} else {
			if ((op.getSyntax() == SqlSyntax.FUNCTION)
				|| (op.getSyntax() == SqlSyntax.PREFIX)) {
				if (op.getOperandTypeChecker() != null) {
					String sig = op.getAllowedSignatures();
					sig = sig.replaceAll("'", "");
					result.add(
						new SqlMonikerImpl(
							sig,
							SqlMonikerType.FUNCTION));
					continue;
				}
				result.add(
					new SqlMonikerImpl(
						op.getName(),
						SqlMonikerType.FUNCTION));
			}
		}
	}
}
 
Example 6
Source File: SqlValidatorImpl.java    From flink with Apache License 2.0 4 votes vote down vote up
private static void findAllValidFunctionNames(
	List<String> names,
	SqlValidator validator,
	Collection<SqlMoniker> result,
	SqlParserPos pos) {
	// a function name can only be 1 part
	if (names.size() > 1) {
		return;
	}
	for (SqlOperator op : validator.getOperatorTable().getOperatorList()) {
		SqlIdentifier curOpId =
			new SqlIdentifier(
				op.getName(),
				pos);

		final SqlCall call = validator.makeNullaryCall(curOpId);
		if (call != null) {
			result.add(
				new SqlMonikerImpl(
					op.getName(),
					SqlMonikerType.FUNCTION));
		} else {
			if ((op.getSyntax() == SqlSyntax.FUNCTION)
				|| (op.getSyntax() == SqlSyntax.PREFIX)) {
				if (op.getOperandTypeChecker() != null) {
					String sig = op.getAllowedSignatures();
					sig = sig.replaceAll("'", "");
					result.add(
						new SqlMonikerImpl(
							sig,
							SqlMonikerType.FUNCTION));
					continue;
				}
				result.add(
					new SqlMonikerImpl(
						op.getName(),
						SqlMonikerType.FUNCTION));
			}
		}
	}
}