alibaba / alibaba/QLExpress

针对 Express4Runner.replaceDefaultOperator 覆盖基本操作符的情况,Express4Runner.addAlias的逻辑优先级存在问题

Open Beginner friendly
#472 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
5.6k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

目前 operatorManager 的addOperatorAlias 方法:

public boolean addOperatorAlias(String lexeme, String operator) {

	
	BinaryOperator originDefaultOp = DEFAULT_BINARY_OPERATOR_MAP.get(operator);
	if (originDefaultOp != null) {
		BinaryOperator newOperator = adaptOriginOperator(originDefaultOp, lexeme);
		BinaryOperator prev = customBinaryOperatorMap.putIfAbsent(lexeme, newOperator);
		return prev == null;
	}

          BinaryOperator originCusOp = customBinaryOperatorMap.get(operator);
	if (originCusOp != null) {
		BinaryOperator newOperator = adaptOriginOperator(originCusOp, lexeme);
		BinaryOperator prev = customBinaryOperatorMap.putIfAbsent(lexeme, newOperator);
		return prev == null;
	}


	return false;
}

这样的逻辑在覆盖了基本操作符并且继续设置别名的时候,永远先从DEFAULT_BINARY_OPERATOR_MAP获取操作符的定义,导致不能绑定到自定义操作符方法中。例如:

runner.replaceDefaultOperator(">", new CustomGreaterCompareOperator());
runner.addAlias("大于", ">");

此时,对于 ">" 获取到的实现是CustomGreaterCompareOperator 而对于 "大于" 获取到的实现类是com.alibaba.qlexpress4.runtime.operator.compare.GreaterOperator.

是否应该对换addOperatorAlias 中的取值顺序?先从customBinaryOperatorMap中取?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at operatorManager.addOperatorAlias and trace how it resolves entries from customBinaryOperatorMap and DEFAULT_BINARY_OPERATOR_MAP. Reproduce the sequence using replaceDefaultOperator(">", new CustomGreaterCompareOperator()) followed by addAlias("大于", ">"), then add or run a focused test showing that the alias resolves to the customized operator.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.