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

The following examples show how to use org.apache.calcite.sql.SqlSyntax#FUNCTION . 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: CalciteCatalogReader.java    From Bats with Apache License 2.0 6 votes vote down vote up
public void lookupOperatorOverloads(final SqlIdentifier opName,
    SqlFunctionCategory category,
    SqlSyntax syntax,
    List<SqlOperator> operatorList) {
  if (syntax != SqlSyntax.FUNCTION) {
    return;
  }

  final Predicate<Function> predicate;
  if (category == null) {
    predicate = function -> true;
  } else if (category.isTableFunction()) {
    predicate = function ->
        function instanceof TableMacro
            || function instanceof TableFunction;
  } else {
    predicate = function ->
        !(function instanceof TableMacro
            || function instanceof TableFunction);
  }
  getFunctionsFrom(opName.names)
      .stream()
      .filter(predicate)
      .map(function -> toOp(opName, function))
      .forEachOrdered(operatorList::add);
}
 
Example 2
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 3
Source File: OperatorTable.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
@Override
public void lookupOperatorOverloads(SqlIdentifier opName, SqlFunctionCategory category, SqlSyntax syntax, List<SqlOperator> operatorList) {
  // don't try to evaluate operators that have non name.
  if(opName == null || opName.names == null) {
    return;
  }

  inner.lookupOperatorOverloads(opName, category, syntax, operatorList);

  if (operatorList.isEmpty() && syntax == SqlSyntax.FUNCTION && opName.isSimple()) {
    List<SqlOperator> ops = opMap.get(opName.getSimple().toUpperCase());
    if (ops != null) {
      operatorList.addAll(ops);
    }
  }
}
 
Example 4
Source File: CalciteCatalogReader.java    From calcite with Apache License 2.0 5 votes vote down vote up
public void lookupOperatorOverloads(final SqlIdentifier opName,
    SqlFunctionCategory category,
    SqlSyntax syntax,
    List<SqlOperator> operatorList,
    SqlNameMatcher nameMatcher) {
  if (syntax != SqlSyntax.FUNCTION) {
    return;
  }

  final Predicate<Function> predicate;
  if (category == null) {
    predicate = function -> true;
  } else if (category.isTableFunction()) {
    predicate = function ->
        function instanceof TableMacro
            || function instanceof TableFunction;
  } else {
    predicate = function ->
        !(function instanceof TableMacro
            || function instanceof TableFunction);
  }
  getFunctionsFrom(opName.names)
      .stream()
      .filter(predicate)
      .map(function -> toOp(opName, function))
      .forEachOrdered(operatorList::add);
}
 
Example 5
Source File: ReflectiveSqlOperatorTable.java    From calcite with Apache License 2.0 5 votes vote down vote up
private static SqlSyntax normalize(SqlSyntax syntax) {
  switch (syntax) {
  case BINARY:
  case PREFIX:
  case POSTFIX:
    return syntax;
  default:
    return SqlSyntax.FUNCTION;
  }
}
 
Example 6
Source File: ReflectiveSqlOperatorTable.java    From Bats with Apache License 2.0 5 votes vote down vote up
private static SqlSyntax normalize(SqlSyntax syntax) {
  switch (syntax) {
  case BINARY:
  case PREFIX:
  case POSTFIX:
    return syntax;
  default:
    return SqlSyntax.FUNCTION;
  }
}
 
Example 7
Source File: FindPartitionConditions.java    From Bats with Apache License 2.0 5 votes vote down vote up
private boolean isHolisticExpression(RexCall call) {
  /* If we are already processing a holistic expression then all
   * nested expressions should be treated holistically as well
   */
  if (holisticExpression > 0) {
    return true;
  }

  if (call.getOperator().getSyntax() == SqlSyntax.SPECIAL ||
      call.getOperator().getSyntax() == SqlSyntax.FUNCTION) {
    return true;
  }
  return false;
}
 
Example 8
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 9
Source File: SqlOperatorImpl.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public SqlOperatorImpl(String name, int argCountMin, int argCountMax, boolean isDeterministic,
    SqlReturnTypeInference sqlReturnTypeInference) {
  this(name,
      argCountMin,
      argCountMax,
      isDeterministic,
      false,
      sqlReturnTypeInference,
      SqlSyntax.FUNCTION);
}
 
Example 10
Source File: HiveSqlOperatorTable.java    From marble with Apache License 2.0 5 votes vote down vote up
private SqlSyntax[] getSqlSyntaxInCalcite(Class hiveUDFClass) {
  if (GenericUDFBaseBinary.class.isAssignableFrom(hiveUDFClass)) {
    return new SqlSyntax[]{SqlSyntax.BINARY, SqlSyntax.FUNCTION};
  } else if (GenericUDFBaseUnary.class.isAssignableFrom(hiveUDFClass)) {
    return new SqlSyntax[]{SqlSyntax.PREFIX, SqlSyntax.FUNCTION};
  } else if (hiveUDFClass.equals(UDFRegExp.class)) {
    //rlike
    return new SqlSyntax[]{SqlSyntax.SPECIAL, SqlSyntax.FUNCTION};
  } else {
    //we treat other udf classes as SqlSyntax.FUNCTION
    return new SqlSyntax[]{SqlSyntax.FUNCTION};
  }
}
 
Example 11
Source File: FindPartitionConditions.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private boolean isHolisticExpression(RexCall call) {
  /* If we are already processing a holistic expression then all
   * nested expressions should be treated holistically as well
   */
  if (holisticExpression > 0) {
    return true;
  }

  if (call.getOperator().getSyntax() == SqlSyntax.SPECIAL ||
      call.getOperator().getSyntax() == SqlSyntax.FUNCTION) {
    return true;
  }
  return false;
}
 
Example 12
Source File: ProctimeMaterializeSqlFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public SqlSyntax getSyntax() {
	return SqlSyntax.FUNCTION;
}
 
Example 13
Source File: ProctimeMaterializeSqlFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public SqlSyntax getSyntax() {
	return SqlSyntax.FUNCTION;
}
 
Example 14
Source File: ReflectiveSqlOperatorTable.java    From calcite with Apache License 2.0 4 votes vote down vote up
public void lookupOperatorOverloads(SqlIdentifier opName,
    SqlFunctionCategory category, SqlSyntax syntax,
    List<SqlOperator> operatorList, SqlNameMatcher nameMatcher) {
  // NOTE jvs 3-Mar-2005:  ignore category until someone cares

  String simpleName;
  if (opName.names.size() > 1) {
    if (opName.names.get(opName.names.size() - 2).equals(IS_NAME)) {
      // per SQL99 Part 2 Section 10.4 Syntax Rule 7.b.ii.1
      simpleName = Util.last(opName.names);
    } else {
      return;
    }
  } else {
    simpleName = opName.getSimple();
  }

  final Collection<SqlOperator> list =
      lookUpOperators(simpleName, syntax, nameMatcher);
  if (list.isEmpty()) {
    return;
  }
  for (SqlOperator op : list) {
    if (op.getSyntax() == syntax) {
      operatorList.add(op);
    } else if (syntax == SqlSyntax.FUNCTION
        && op instanceof SqlFunction) {
      // this special case is needed for operators like CAST,
      // which are treated as functions but have special syntax
      operatorList.add(op);
    }
  }

  // REVIEW jvs 1-Jan-2005:  why is this extra lookup required?
  // Shouldn't it be covered by search above?
  switch (syntax) {
  case BINARY:
  case PREFIX:
  case POSTFIX:
    for (SqlOperator extra
        : lookUpOperators(simpleName, syntax, nameMatcher)) {
      // REVIEW: should only search operators added during this method?
      if (extra != null && !operatorList.contains(extra)) {
        operatorList.add(extra);
      }
    }
    break;
  }
}
 
Example 15
Source File: StreamRecordTimestampSqlFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public SqlSyntax getSyntax() {
	return SqlSyntax.FUNCTION;
}
 
Example 16
Source File: SqlRandFunction.java    From Bats with Apache License 2.0 4 votes vote down vote up
public SqlSyntax getSyntax() {
  return SqlSyntax.FUNCTION;
}
 
Example 17
Source File: SqlRandIntegerFunction.java    From calcite with Apache License 2.0 4 votes vote down vote up
public SqlSyntax getSyntax() {
  return SqlSyntax.FUNCTION;
}
 
Example 18
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 19
Source File: ReflectiveSqlOperatorTable.java    From Bats with Apache License 2.0 4 votes vote down vote up
public void lookupOperatorOverloads(SqlIdentifier opName,
    SqlFunctionCategory category,
    SqlSyntax syntax,
    List<SqlOperator> operatorList) {
  // NOTE jvs 3-Mar-2005:  ignore category until someone cares

  String simpleName;
  if (opName.names.size() > 1) {
    if (opName.names.get(opName.names.size() - 2).equals(IS_NAME)) {
      // per SQL99 Part 2 Section 10.4 Syntax Rule 7.b.ii.1
      simpleName = Util.last(opName.names);
    } else {
      return;
    }
  } else {
    simpleName = opName.getSimple();
  }

  // Always look up built-in operators case-insensitively. Even in sessions
  // with unquotedCasing=UNCHANGED and caseSensitive=true.
  final Collection<SqlOperator> list =
      operators.get(new Key(simpleName, syntax));
  if (list.isEmpty()) {
    return;
  }
  for (SqlOperator op : list) {
    if (op.getSyntax() == syntax) {
      operatorList.add(op);
    } else if (syntax == SqlSyntax.FUNCTION
        && op instanceof SqlFunction) {
      // this special case is needed for operators like CAST,
      // which are treated as functions but have special syntax
      operatorList.add(op);
    }
  }

  // REVIEW jvs 1-Jan-2005:  why is this extra lookup required?
  // Shouldn't it be covered by search above?
  switch (syntax) {
  case BINARY:
  case PREFIX:
  case POSTFIX:
    for (SqlOperator extra : operators.get(new Key(simpleName, syntax))) {
      // REVIEW: should only search operators added during this method?
      if (extra != null && !operatorList.contains(extra)) {
        operatorList.add(extra);
      }
    }
    break;
  }
}
 
Example 20
Source File: SqlRandIntegerFunction.java    From Bats with Apache License 2.0 4 votes vote down vote up
public SqlSyntax getSyntax() {
  return SqlSyntax.FUNCTION;
}