Java Code Examples for org.apache.calcite.sql.SqlCall#getFunctionQuantifier()

The following examples show how to use org.apache.calcite.sql.SqlCall#getFunctionQuantifier() . 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: ClickHouseSqlDialect.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override public void unparseCall(SqlWriter writer, SqlCall call,
    int leftPrec, int rightPrec) {
  if (call.getOperator() == SqlStdOperatorTable.SUBSTRING) {
    RelToSqlConverterUtil.specialOperatorByName("substring")
        .unparse(writer, call, 0, 0);
  } else {
    switch (call.getKind()) {
    case FLOOR:
      if (call.operandCount() != 2) {
        super.unparseCall(writer, call, leftPrec, rightPrec);
        return;
      }

      unparseFloor(writer, call);
      break;

    case COUNT:
      // CH returns NULL rather than 0 for COUNT(DISTINCT) of NULL values.
      // https://github.com/yandex/ClickHouse/issues/2494
      // Wrap the call in a CH specific coalesce (assumeNotNull).
      if (call.getFunctionQuantifier() != null
          && call.getFunctionQuantifier().toString().equals("DISTINCT")) {
        writer.print("assumeNotNull");
        SqlWriter.Frame frame = writer.startList("(", ")");
        super.unparseCall(writer, call, leftPrec, rightPrec);
        writer.endList(frame);
      } else {
        super.unparseCall(writer, call, leftPrec, rightPrec);
      }
      break;

    default:
      super.unparseCall(writer, call, leftPrec, rightPrec);
    }
  }
}
 
Example 2
Source File: SqlValidatorImpl.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override public SqlNode visit(SqlCall call) {
	SqlKind kind = call.getKind();
	List<SqlNode> operands = call.getOperandList();
	List<SqlNode> newOperands = new ArrayList<>();

	// This code is a workaround for CALCITE-2707
	if (call.getFunctionQuantifier() != null
		&& call.getFunctionQuantifier().getValue() == SqlSelectKeyword.DISTINCT) {
		final SqlParserPos pos = call.getParserPosition();
		throw SqlUtil.newContextException(pos, Static.RESOURCE.functionQuantifierNotAllowed(call.toString()));
	}
	// This code is a workaround for CALCITE-2707

	if (isLogicalNavigation(kind) || isPhysicalNavigation(kind)) {
		SqlNode inner = operands.get(0);
		SqlNode offset = operands.get(1);

		// merge two straight prev/next, update offset
		if (isPhysicalNavigation(kind)) {
			SqlKind innerKind = inner.getKind();
			if (isPhysicalNavigation(innerKind)) {
				List<SqlNode> innerOperands = ((SqlCall) inner).getOperandList();
				SqlNode innerOffset = innerOperands.get(1);
				SqlOperator newOperator = innerKind == kind
					? SqlStdOperatorTable.PLUS : SqlStdOperatorTable.MINUS;
				offset = newOperator.createCall(SqlParserPos.ZERO,
					offset, innerOffset);
				inner = call.getOperator().createCall(SqlParserPos.ZERO,
					innerOperands.get(0), offset);
			}
		}
		SqlNode newInnerNode =
			inner.accept(new NavigationExpander(call.getOperator(), offset));
		if (op != null) {
			newInnerNode = op.createCall(SqlParserPos.ZERO, newInnerNode,
				this.offset);
		}
		return newInnerNode;
	}

	if (operands.size() > 0) {
		for (SqlNode node : operands) {
			if (node != null) {
				SqlNode newNode = node.accept(new NavigationExpander());
				if (op != null) {
					newNode = op.createCall(SqlParserPos.ZERO, newNode, offset);
				}
				newOperands.add(newNode);
			} else {
				newOperands.add(null);
			}
		}
		return call.getOperator().createCall(SqlParserPos.ZERO, newOperands);
	} else {
		if (op == null) {
			return call;
		} else {
			return op.createCall(SqlParserPos.ZERO, call, offset);
		}
	}
}
 
Example 3
Source File: SqlValidatorImpl.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override public SqlNode visit(SqlCall call) {
	SqlKind kind = call.getKind();
	List<SqlNode> operands = call.getOperandList();
	List<SqlNode> newOperands = new ArrayList<>();

	// This code is a workaround for CALCITE-2707
	if (call.getFunctionQuantifier() != null
		&& call.getFunctionQuantifier().getValue() == SqlSelectKeyword.DISTINCT) {
		final SqlParserPos pos = call.getParserPosition();
		throw SqlUtil.newContextException(pos, Static.RESOURCE.functionQuantifierNotAllowed(call.toString()));
	}
	// This code is a workaround for CALCITE-2707

	if (isLogicalNavigation(kind) || isPhysicalNavigation(kind)) {
		SqlNode inner = operands.get(0);
		SqlNode offset = operands.get(1);

		// merge two straight prev/next, update offset
		if (isPhysicalNavigation(kind)) {
			SqlKind innerKind = inner.getKind();
			if (isPhysicalNavigation(innerKind)) {
				List<SqlNode> innerOperands = ((SqlCall) inner).getOperandList();
				SqlNode innerOffset = innerOperands.get(1);
				SqlOperator newOperator = innerKind == kind
					? SqlStdOperatorTable.PLUS : SqlStdOperatorTable.MINUS;
				offset = newOperator.createCall(SqlParserPos.ZERO,
					offset, innerOffset);
				inner = call.getOperator().createCall(SqlParserPos.ZERO,
					innerOperands.get(0), offset);
			}
		}
		SqlNode newInnerNode =
			inner.accept(new NavigationExpander(call.getOperator(), offset));
		if (op != null) {
			newInnerNode = op.createCall(SqlParserPos.ZERO, newInnerNode,
				this.offset);
		}
		return newInnerNode;
	}

	if (operands.size() > 0) {
		for (SqlNode node : operands) {
			if (node != null) {
				SqlNode newNode = node.accept(new NavigationExpander());
				if (op != null) {
					newNode = op.createCall(SqlParserPos.ZERO, newNode, offset);
				}
				newOperands.add(newNode);
			} else {
				newOperands.add(null);
			}
		}
		return call.getOperator().createCall(SqlParserPos.ZERO, newOperands);
	} else {
		if (op == null) {
			return call;
		} else {
			return op.createCall(SqlParserPos.ZERO, call, offset);
		}
	}
}
 
Example 4
Source File: DruidTable.java    From calcite with Apache License 2.0 4 votes vote down vote up
private boolean isCountDistinct(SqlCall call) {
  return call.getKind() == SqlKind.COUNT
          && call.getFunctionQuantifier() != null
          && call.getFunctionQuantifier().getValue() == SqlSelectKeyword.DISTINCT;
}