Java Code Examples for org.apache.calcite.sql.SqlSyntax#FUNCTION_ID

The following examples show how to use org.apache.calcite.sql.SqlSyntax#FUNCTION_ID . 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: RexCall.java    From calcite with Apache License 2.0 6 votes vote down vote up
protected @Nonnull String computeDigest(boolean withType) {
  final StringBuilder sb = new StringBuilder(op.getName());
  if ((operands.size() == 0)
      && (op.getSyntax() == SqlSyntax.FUNCTION_ID)) {
    // Don't print params for empty arg list. For example, we want
    // "SYSTEM_USER", not "SYSTEM_USER()".
  } else {
    sb.append("(");
    appendOperands(sb);
    sb.append(")");
  }
  if (withType) {
    sb.append(":");

    // NOTE jvs 16-Jan-2005:  for digests, it is very important
    // to use the full type string.
    sb.append(type.getFullTypeString());
  }
  return sb.toString();
}
 
Example 2
Source File: RexCallImpl.java    From Bats with Apache License 2.0 6 votes vote down vote up
protected String computeDigest(boolean withType) {
    final StringBuilder sb = new StringBuilder(op.getName());
    if ((operands.size() == 0) && (op.getSyntax() == SqlSyntax.FUNCTION_ID)) {
        // Don't print params for empty arg list. For example, we want
        // "SYSTEM_USER", not "SYSTEM_USER()".
    } else {
        sb.append("(");
        appendOperands(sb);
        sb.append(")");
    }
    if (withType) {
        sb.append(":");

        // NOTE jvs 16-Jan-2005: for digests, it is very important
        // to use the full type string.
        sb.append(type.getFullTypeString());
    }
    return sb.toString();
}
 
Example 3
Source File: SqlValidatorImpl.java    From flink with Apache License 2.0 6 votes vote down vote up
@Nullable public SqlCall makeNullaryCall(SqlIdentifier id) {
	if (id.names.size() == 1 && !id.isComponentQuoted(0)) {
		final List<SqlOperator> list = new ArrayList<>();
		opTab.lookupOperatorOverloads(id, null, SqlSyntax.FUNCTION, list,
				catalogReader.nameMatcher());
		for (SqlOperator operator : list) {
			if (operator.getSyntax() == SqlSyntax.FUNCTION_ID) {
				// Even though this looks like an identifier, it is a
				// actually a call to a function. Construct a fake
				// call to this function, so we can use the regular
				// operator validation.
				return new SqlBasicCall(operator, SqlNode.EMPTY_ARRAY,
						id.getParserPosition(), true, null);
			}
		}
	}
	return null;
}
 
Example 4
Source File: DrillOperatorTable.java    From Bats with Apache License 2.0 6 votes vote down vote up
private void populateFromTypeInference(SqlIdentifier opName, SqlFunctionCategory category,
                                       SqlSyntax syntax, List<SqlOperator> operatorList) {
  final List<SqlOperator> calciteOperatorList = Lists.newArrayList();
  inner.lookupOperatorOverloads(opName, category, syntax, calciteOperatorList);
  if (!calciteOperatorList.isEmpty()) {
    for (SqlOperator calciteOperator : calciteOperatorList) {
      if (calciteToWrapper.containsKey(calciteOperator)) {
        operatorList.add(calciteToWrapper.get(calciteOperator));
      } else {
        operatorList.add(calciteOperator);
      }
    }
  } else {
    // if no function is found, check in Drill UDFs
    if (operatorList.isEmpty() && (syntax == SqlSyntax.FUNCTION || syntax == SqlSyntax.FUNCTION_ID) && opName.isSimple()) {
      List<SqlOperator> drillOps = drillOperatorsWithInferenceMap.get(opName.getSimple().toLowerCase());
      if (drillOps != null && !drillOps.isEmpty()) {
        operatorList.addAll(drillOps);
      }
    }
  }
}
 
Example 5
Source File: SqlValidatorImpl.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public void validateCall(
	SqlCall call,
	SqlValidatorScope scope) {
	final SqlOperator operator = call.getOperator();
	if ((call.operandCount() == 0)
		&& (operator.getSyntax() == SqlSyntax.FUNCTION_ID)
		&& !call.isExpanded()
		&& !conformance.allowNiladicParentheses()) {
		// For example, "LOCALTIME()" is illegal. (It should be
		// "LOCALTIME", which would have been handled as a
		// SqlIdentifier.)
		throw handleUnresolvedFunction(call, (SqlFunction) operator,
			ImmutableList.of(), null);
	}

	SqlValidatorScope operandScope = scope.getOperandScope(call);

	if (operator instanceof SqlFunction
		&& ((SqlFunction) operator).getFunctionType()
		== SqlFunctionCategory.MATCH_RECOGNIZE
		&& !(operandScope instanceof MatchRecognizeScope)) {
		throw newValidationError(call,
			Static.RESOURCE.functionMatchRecognizeOnly(call.toString()));
	}
	// Delegate validation to the operator.
	operator.validateCall(call, this, scope, operandScope);
}
 
Example 6
Source File: SqlValidatorImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
public void validateCall(
	SqlCall call,
	SqlValidatorScope scope) {
	final SqlOperator operator = call.getOperator();
	if ((call.operandCount() == 0)
		&& (operator.getSyntax() == SqlSyntax.FUNCTION_ID)
		&& !call.isExpanded()
		&& !conformance.allowNiladicParentheses()) {
		// For example, "LOCALTIME()" is illegal. (It should be
		// "LOCALTIME", which would have been handled as a
		// SqlIdentifier.)
		throw handleUnresolvedFunction(call, (SqlFunction) operator,
			ImmutableList.of(), null);
	}

	SqlValidatorScope operandScope = scope.getOperandScope(call);

	if (operator instanceof SqlFunction
		&& ((SqlFunction) operator).getFunctionType()
		== SqlFunctionCategory.MATCH_RECOGNIZE
		&& !(operandScope instanceof MatchRecognizeScope)) {
		throw newValidationError(call,
			Static.RESOURCE.functionMatchRecognizeOnly(call.toString()));
	}
	// Delegate validation to the operator.
	operator.validateCall(call, this, scope, operandScope);
}
 
Example 7
Source File: SqlValidatorImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
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, catalogReader.nameMatcher());
	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));
}
 
Example 8
Source File: SqlValidatorImpl.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
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));
}
 
Example 9
Source File: DrillOperatorTable.java    From Bats with Apache License 2.0 5 votes vote down vote up
private void populateFromWithoutTypeInference(SqlIdentifier opName, SqlFunctionCategory category,
                                              SqlSyntax syntax, List<SqlOperator> operatorList) {
  inner.lookupOperatorOverloads(opName, category, syntax, operatorList);
  if (operatorList.isEmpty() && (syntax == SqlSyntax.FUNCTION || syntax == SqlSyntax.FUNCTION_ID) && opName.isSimple()) {
    List<SqlOperator> drillOps = drillOperatorsWithoutInferenceMap.get(opName.getSimple().toLowerCase());
    if (drillOps != null) {
      operatorList.addAll(drillOps);
    }
  }
}
 
Example 10
Source File: SqlCurrentDateFunction.java    From Bats with Apache License 2.0 4 votes vote down vote up
public SqlSyntax getSyntax() {
  return SqlSyntax.FUNCTION_ID;
}
 
Example 11
Source File: DrillSqlOperator.java    From Bats with Apache License 2.0 4 votes vote down vote up
public SqlSyntax getSyntax() {
  if(isNiladic) {
    return SqlSyntax.FUNCTION_ID;
  }
  return super.getSyntax();
}
 
Example 12
Source File: SqlStdOperatorTable.java    From Bats with Apache License 2.0 4 votes vote down vote up
public SqlSyntax getSyntax() {
  return SqlSyntax.FUNCTION_ID;
}
 
Example 13
Source File: SqlAbstractTimeFunction.java    From Bats with Apache License 2.0 4 votes vote down vote up
public SqlSyntax getSyntax() {
  return SqlSyntax.FUNCTION_ID;
}
 
Example 14
Source File: SqlCurrentDateFunction.java    From calcite with Apache License 2.0 4 votes vote down vote up
public SqlSyntax getSyntax() {
  return SqlSyntax.FUNCTION_ID;
}
 
Example 15
Source File: SqlBaseContextVariable.java    From calcite with Apache License 2.0 4 votes vote down vote up
public SqlSyntax getSyntax() {
  return SqlSyntax.FUNCTION_ID;
}
 
Example 16
Source File: SqlAbstractTimeFunction.java    From calcite with Apache License 2.0 4 votes vote down vote up
public SqlSyntax getSyntax() {
  return SqlSyntax.FUNCTION_ID;
}
 
Example 17
Source File: SqlStdOperatorTable.java    From calcite with Apache License 2.0 4 votes vote down vote up
public SqlSyntax getSyntax() {
  return SqlSyntax.FUNCTION_ID;
}
 
Example 18
Source File: SqlBaseContextVariable.java    From Bats with Apache License 2.0 4 votes vote down vote up
public SqlSyntax getSyntax() {
  return SqlSyntax.FUNCTION_ID;
}