Java Code Examples for org.apache.calcite.sql.type.InferTypes#FIRST_KNOWN

The following examples show how to use org.apache.calcite.sql.type.InferTypes#FIRST_KNOWN . 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: SqlPosixRegexOperator.java    From calcite with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a SqlPosixRegexOperator.
 *
 * @param name    Operator name
 * @param kind    Kind
 * @param negated Whether this is '!~' or '!~*'
 */
SqlPosixRegexOperator(
    String name,
    SqlKind kind,
    boolean caseSensitive,
    boolean negated) {
  super(
      name,
      kind,
      32,
      true,
      ReturnTypes.BOOLEAN_NULLABLE,
      InferTypes.FIRST_KNOWN,
      OperandTypes.STRING_SAME_SAME_SAME);
  this.caseSensitive = caseSensitive;
  this.negated = negated;
}
 
Example 2
Source File: SqlLikeOperator.java    From calcite with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a SqlLikeOperator.
 *
 * @param name    Operator name
 * @param kind    Kind
 * @param negated Whether this is 'NOT LIKE'
 */
SqlLikeOperator(
    String name,
    SqlKind kind,
    boolean negated) {
  // LIKE is right-associative, because that makes it easier to capture
  // dangling ESCAPE clauses: "a like b like c escape d" becomes
  // "a like (b like c escape d)".
  super(
      name,
      kind,
      32,
      false,
      ReturnTypes.BOOLEAN_NULLABLE,
      InferTypes.FIRST_KNOWN,
      OperandTypes.STRING_SAME_SAME_SAME);
  this.negated = negated;
}
 
Example 3
Source File: MysqlSideFunction.java    From alchemy with Apache License 2.0 6 votes vote down vote up
private List<SqlBasicCall> createConditionNodes(List<String> conditions, Alias alias) {
    SqlBinaryOperator equal = new SqlBinaryOperator("=", SqlKind.EQUALS, 30, true, ReturnTypes.BOOLEAN_NULLABLE,
        InferTypes.FIRST_KNOWN, OperandTypes.COMPARABLE_UNORDERED_COMPARABLE_UNORDERED);
    List<SqlBasicCall> nodes = new ArrayList<>(conditions.size());
    int num = 0;
    for (String condition : conditions) {
        List<String> fields = new ArrayList<>(2);
        fields.add(alias.getAlias());
        fields.add(condition);
        SqlIdentifier leftIdentifier = new SqlIdentifier(fields, new SqlParserPos(0, 0));
        SqlDynamicParam sqlDynamicParam = new SqlDynamicParam(num++, new SqlParserPos(0, 0));
        SqlNode[] sqlNodes = new SqlNode[2];
        sqlNodes[0] = leftIdentifier;
        sqlNodes[1] = sqlDynamicParam;
        SqlBasicCall andEqual = new SqlBasicCall(equal, sqlNodes, new SqlParserPos(0, 0));
        nodes.add(andEqual);
    }
    return nodes;
}
 
Example 4
Source File: SqlDatetimeSubtractionOperator.java    From calcite with Apache License 2.0 5 votes vote down vote up
public SqlDatetimeSubtractionOperator() {
  super(
      "-",
      SqlKind.MINUS,
      40,
      true,
      ReturnTypes.ARG2_NULLABLE,
      InferTypes.FIRST_KNOWN, OperandTypes.MINUS_DATE_OPERATOR);
}
 
Example 5
Source File: SqlCastFunction.java    From calcite with Apache License 2.0 5 votes vote down vote up
public SqlCastFunction() {
  super("CAST",
      SqlKind.CAST,
      null,
      InferTypes.FIRST_KNOWN,
      null,
      SqlFunctionCategory.SYSTEM);
}
 
Example 6
Source File: SqlMultisetValueConstructor.java    From calcite with Apache License 2.0 5 votes vote down vote up
protected SqlMultisetValueConstructor(String name, SqlKind kind) {
  super(
      name,
      kind, MDX_PRECEDENCE,
      false,
      ReturnTypes.ARG0,
      InferTypes.FIRST_KNOWN,
      OperandTypes.VARIADIC);
}
 
Example 7
Source File: SqlInOperator.java    From calcite with Apache License 2.0 5 votes vote down vote up
protected SqlInOperator(String name, SqlKind kind) {
  super(name, kind,
      32,
      true,
      ReturnTypes.BOOLEAN_NULLABLE,
      InferTypes.FIRST_KNOWN,
      null);
}
 
Example 8
Source File: SqlLiteralChainOperator.java    From calcite with Apache License 2.0 5 votes vote down vote up
SqlLiteralChainOperator() {
  super(
      "$LiteralChain",
      SqlKind.LITERAL_CHAIN,
      80,
      true,

      // precedence tighter than the * and || operators
      ReturnTypes.ARG0,
      InferTypes.FIRST_KNOWN,
      OperandTypes.VARIADIC);
}
 
Example 9
Source File: SqlDatePartFunction.java    From calcite with Apache License 2.0 5 votes vote down vote up
public SqlDatePartFunction(String name, TimeUnit timeUnit) {
  super(name,
      SqlKind.OTHER,
      ReturnTypes.BIGINT_NULLABLE,
      InferTypes.FIRST_KNOWN,
      OperandTypes.DATETIME,
      SqlFunctionCategory.TIMEDATE);
  this.timeUnit = timeUnit;
}
 
Example 10
Source File: MysqlSideFunction.java    From alchemy with Apache License 2.0 5 votes vote down vote up
private String modifySql(SideTable sideTable) throws SqlParseException {
    SqlParser.Config config = SqlParser.configBuilder().setLex(Lex.MYSQL).build();
    SqlParser sqlParser = SqlParser.create(sideTable.getSql(), config);
    SqlNode sqlNode = sqlParser.parseStmt();
    if (SqlKind.SELECT != sqlNode.getKind()) {
        throw new UnsupportedOperationException(
            "MysqlAsyncReqRow only support query sql, sql:" + sideTable.getSql());
    }
    SqlSelect sqlSelect = (SqlSelect)sqlNode;
    SqlNode whereNode = sqlSelect.getWhere();
    SqlBinaryOperator and = new SqlBinaryOperator("AND", SqlKind.AND, 24, true,
        ReturnTypes.BOOLEAN_NULLABLE_OPTIMIZED, InferTypes.BOOLEAN, OperandTypes.BOOLEAN_BOOLEAN);
    List<SqlBasicCall> conditionNodes = createConditionNodes(sideTable.getConditions(), sideTable.getSideAlias());
    List<SqlNode> nodes = new ArrayList<>();
    nodes.addAll(conditionNodes);
    if (whereNode != null) {
        nodes.add(whereNode);
    } else {
        SqlBinaryOperator equal = new SqlBinaryOperator("=", SqlKind.EQUALS, 30, true, ReturnTypes.BOOLEAN_NULLABLE,
            InferTypes.FIRST_KNOWN, OperandTypes.COMPARABLE_UNORDERED_COMPARABLE_UNORDERED);
        SqlBasicCall andEqual
            = new SqlBasicCall(equal, SideParser.createEqualNodes(SqlKind.AND), new SqlParserPos(0, 0));
        nodes.add(andEqual);
    }
    SqlBasicCall sqlBasicCall
        = new SqlBasicCall(and, nodes.toArray(new SqlNode[nodes.size()]), new SqlParserPos(0, 0));
    sqlSelect.setWhere(sqlBasicCall);
    return sqlSelect.toString();
}
 
Example 11
Source File: SqlMultisetSetOperator.java    From calcite with Apache License 2.0 5 votes vote down vote up
public SqlMultisetSetOperator(String name, int prec, boolean all) {
  super(
      name,
      SqlKind.OTHER,
      prec,
      true,
      ReturnTypes.MULTISET_NULLABLE,
      InferTypes.FIRST_KNOWN,
      OperandTypes.MULTISET_MULTISET);
  this.all = all;
}
 
Example 12
Source File: SqlMultisetSetOperator.java    From Bats with Apache License 2.0 5 votes vote down vote up
public SqlMultisetSetOperator(String name, int prec, boolean all) {
  super(
      name,
      SqlKind.OTHER,
      prec,
      true,
      ReturnTypes.MULTISET_NULLABLE,
      InferTypes.FIRST_KNOWN,
      OperandTypes.MULTISET_MULTISET);
  this.all = all;
}
 
Example 13
Source File: SqlDatetimeSubtractionOperator.java    From Bats with Apache License 2.0 5 votes vote down vote up
public SqlDatetimeSubtractionOperator() {
  super(
      "-",
      SqlKind.MINUS,
      40,
      true,
      ReturnTypes.ARG2_NULLABLE,
      InferTypes.FIRST_KNOWN, OperandTypes.MINUS_DATE_OPERATOR);
}
 
Example 14
Source File: SqlMultisetValueConstructor.java    From Bats with Apache License 2.0 5 votes vote down vote up
protected SqlMultisetValueConstructor(String name, SqlKind kind) {
  super(
      name,
      kind, MDX_PRECEDENCE,
      false,
      ReturnTypes.ARG0,
      InferTypes.FIRST_KNOWN,
      OperandTypes.VARIADIC);
}
 
Example 15
Source File: SqlInOperator.java    From Bats with Apache License 2.0 5 votes vote down vote up
protected SqlInOperator(String name, SqlKind kind) {
  super(name, kind,
      32,
      true,
      ReturnTypes.BOOLEAN_NULLABLE,
      InferTypes.FIRST_KNOWN,
      null);
}
 
Example 16
Source File: SqlLiteralChainOperator.java    From Bats with Apache License 2.0 5 votes vote down vote up
SqlLiteralChainOperator() {
  super(
      "$LiteralChain",
      SqlKind.LITERAL_CHAIN,
      80,
      true,

      // precedence tighter than the * and || operators
      ReturnTypes.ARG0,
      InferTypes.FIRST_KNOWN,
      OperandTypes.VARIADIC);
}
 
Example 17
Source File: SqlDatePartFunction.java    From Bats with Apache License 2.0 5 votes vote down vote up
public SqlDatePartFunction(String name, TimeUnit timeUnit) {
  super(name,
      SqlKind.OTHER,
      ReturnTypes.BIGINT_NULLABLE,
      InferTypes.FIRST_KNOWN,
      OperandTypes.DATETIME,
      SqlFunctionCategory.TIMEDATE);
  this.timeUnit = timeUnit;
}
 
Example 18
Source File: SqlBetweenOperator.java    From Bats with Apache License 2.0 4 votes vote down vote up
public SqlBetweenOperator(Flag flag, boolean negated) {
  super(negated ? NOT_BETWEEN_NAMES : BETWEEN_NAMES, SqlKind.BETWEEN, 32,
      null, InferTypes.FIRST_KNOWN, OTC_CUSTOM);
  this.flag = flag;
  this.negated = negated;
}
 
Example 19
Source File: SqlOverlapsOperator.java    From calcite with Apache License 2.0 4 votes vote down vote up
SqlOverlapsOperator(SqlKind kind) {
  super(kind.sql, kind, 30, true, ReturnTypes.BOOLEAN_NULLABLE,
      InferTypes.FIRST_KNOWN,
      OperandTypes.sequence("'<PERIOD> " + kind.sql + " <PERIOD>'",
          OperandTypes.PERIOD, OperandTypes.PERIOD));
}
 
Example 20
Source File: SqlCastOperator.java    From calcite with Apache License 2.0 4 votes vote down vote up
SqlCastOperator() {
  super("::", SqlKind.CAST, 94, true, null, InferTypes.FIRST_KNOWN, null);
}