Java Code Examples for org.apache.calcite.sql.SqlKind#valueOf()

The following examples show how to use org.apache.calcite.sql.SqlKind#valueOf() . 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: RelJson.java    From calcite with Apache License 2.0 6 votes vote down vote up
SqlOperator toOp(Map<String, Object> map) {
  // in case different operator has the same kind, check with both name and kind.
  String name = map.get("name").toString();
  String kind = map.get("kind").toString();
  String syntax = map.get("syntax").toString();
  SqlKind sqlKind = SqlKind.valueOf(kind);
  SqlSyntax  sqlSyntax = SqlSyntax.valueOf(syntax);
  List<SqlOperator> operators = new ArrayList<>();
  SqlStdOperatorTable.instance().lookupOperatorOverloads(
      new SqlIdentifier(name, new SqlParserPos(0, 0)),
      null,
      sqlSyntax,
      operators,
      SqlNameMatchers.liberal());
  for (SqlOperator operator: operators) {
    if (operator.kind == sqlKind) {
      return operator;
    }
  }
  String class_ = (String) map.get("class");
  if (class_ != null) {
    return AvaticaUtils.instantiatePlugin(SqlOperator.class, class_);
  }
  return null;
}
 
Example 2
Source File: SqlAvgAggFunction.java    From Bats with Apache License 2.0 4 votes vote down vote up
@Deprecated // to be removed before 2.0
public SqlAvgAggFunction(
    RelDataType type,
    Subtype subtype) {
  this(SqlKind.valueOf(subtype.name()));
}
 
Example 3
Source File: SqlCovarAggFunction.java    From Bats with Apache License 2.0 4 votes vote down vote up
@Deprecated // to be removed before 2.0
public SqlCovarAggFunction(RelDataType type, Subtype subtype) {
  this(SqlKind.valueOf(subtype.name()));
}
 
Example 4
Source File: SqlAvgAggFunction.java    From calcite with Apache License 2.0 4 votes vote down vote up
@Deprecated // to be removed before 2.0
public SqlAvgAggFunction(
    RelDataType type,
    Subtype subtype) {
  this(SqlKind.valueOf(subtype.name()));
}
 
Example 5
Source File: SqlCovarAggFunction.java    From calcite with Apache License 2.0 4 votes vote down vote up
@Deprecated // to be removed before 2.0
public SqlCovarAggFunction(RelDataType type, Subtype subtype) {
  this(SqlKind.valueOf(subtype.name()));
}
 
Example 6
Source File: CalciteSqlParser.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
private static Expression updateComparisonPredicate(Expression expression) {
  Function functionCall = expression.getFunctionCall();
  if (functionCall != null) {
    SqlKind sqlKind = SqlKind.OTHER_FUNCTION;
    try {
      sqlKind = SqlKind.valueOf(functionCall.getOperator().toUpperCase());
    } catch (Exception e) {
      // Do nothing
    }
    switch (sqlKind) {
      case EQUALS:
      case NOT_EQUALS:
      case GREATER_THAN:
      case GREATER_THAN_OR_EQUAL:
      case LESS_THAN:
      case LESS_THAN_OR_EQUAL:
        // Handle predicate like 'WHERE 10=a'
        if (functionCall.getOperands().get(0).getLiteral() != null) {
          functionCall.setOperator(getOppositeOperator(functionCall.getOperator()));
          List<Expression> oldOperands = functionCall.getOperands();
          Expression tempExpr = oldOperands.get(0);
          oldOperands.set(0, oldOperands.get(1));
          oldOperands.set(1, tempExpr);
        }
        if (functionCall.getOperands().get(1).getLiteral() != null) {
          return expression;
        }
        Expression comparisonFunction = RequestUtils.getFunctionExpression(functionCall.getOperator());
        List<Expression> exprList = new ArrayList<>();
        exprList.add(getLeftOperand(functionCall));
        exprList.add(RequestUtils.getLiteralExpression(0));
        comparisonFunction.getFunctionCall().setOperands(exprList);
        return comparisonFunction;
      default:
        List<Expression> newOperands = new ArrayList<>();
        int operandsSize = functionCall.getOperandsSize();
        for (int i = 0; i < operandsSize; i++) {
          Expression operand = functionCall.getOperands().get(i);
          newOperands.add(updateComparisonPredicate(operand));
        }
        functionCall.setOperands(newOperands);
    }
  }
  return expression;
}