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

The following examples show how to use org.apache.calcite.sql.SqlCall#getParserPosition() . 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: SqlDatePartFunction.java    From Bats with Apache License 2.0 5 votes vote down vote up
@Override public SqlNode rewriteCall(SqlValidator validator, SqlCall call) {
  final List<SqlNode> operands = call.getOperandList();
  final SqlParserPos pos = call.getParserPosition();
  return SqlStdOperatorTable.EXTRACT.createCall(pos,
      new SqlIntervalQualifier(timeUnit, null, SqlParserPos.ZERO),
      operands.get(0));
}
 
Example 2
Source File: SqlDatePartFunction.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override public SqlNode rewriteCall(SqlValidator validator, SqlCall call) {
  final List<SqlNode> operands = call.getOperandList();
  final SqlParserPos pos = call.getParserPosition();
  return SqlStdOperatorTable.EXTRACT.createCall(pos,
      new SqlIntervalQualifier(timeUnit, null, SqlParserPos.ZERO),
      operands.get(0));
}
 
Example 3
Source File: SqlStdOperatorTable.java    From Bats with Apache License 2.0 4 votes vote down vote up
/** Creates a copy of a call with a new operator. */
private static SqlCall copy(SqlCall call, SqlOperator operator) {
  final List<SqlNode> list = call.getOperandList();
  return new SqlBasicCall(operator, list.toArray(new SqlNode[0]),
      call.getParserPosition());
}
 
Example 4
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 5
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 6
Source File: SqlStdOperatorTable.java    From calcite with Apache License 2.0 4 votes vote down vote up
/** Creates a copy of a call with a new operator. */
private static SqlCall copy(SqlCall call, SqlOperator operator) {
  final List<SqlNode> list = call.getOperandList();
  return new SqlBasicCall(operator, list.toArray(new SqlNode[0]),
      call.getParserPosition());
}