Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Improve][SDK] Improvements to TypeConverter field types and CompareValue in OperatorTools #10809

Closed
2 tasks done
Zkplo opened this issue Aug 18, 2024 · 0 comments · Fixed by #10817
Closed
2 tasks done

Comments

@Zkplo
Copy link
Contributor

Zkplo commented Aug 18, 2024

Description

Data:

numeric1|numeric2|numeric3|numeric4
3.14159265358979323846|4|6|8

SQL Statement:

select if(numeric2 = 4,1,0) from source;

Background:
When parsing 'numeric2=4', the following function will be entered:

org.apache.inlong.sdk.transform.process.operator.OperatorTools#compareValue()
public static int compareValue(Comparable left, Comparable right) {
	if (left == null) {
		return right == null ? 0 : -1;
	}
	if (right == null) {
		return 1;
	}
	/*
		When one of the left and right is a string, the other is assumed to be BigDecimal, but there are other types present during the parsing process. 
		For example, here JSQLParser parses the 4 in the expression as a Long type, while numeric2 is parsed by the SDK as a string "4". In "ObjectUtils.compare()", an error occurs due to inconsistent types on both sides.
	*/
	if (left instanceof String) {
		if (right instanceof String) {
			return ObjectUtils.compare(left, right);
		} else {
			BigDecimal leftValue = parseBigDecimal(left);
			return ObjectUtils.compare(leftValue, right);
		}
	} else {
		if (right instanceof String) {
			BigDecimal rightValue = parseBigDecimal(right);
			return ObjectUtils.compare(left, rightValue);
		} else {
			return ObjectUtils.compare(left, right);
		}
	}
}

Questions:

  1. The Transform reserved a field type interface, but it was not used in subsequent development.
  2. The compareValue method in OperatorTools did not take into account in detail the types involved in comparing the two instances.

InLong Component

InLong SDK

Are you willing to submit PR?

  • Yes, I am willing to submit a PR!

Code of Conduct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants