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

Fix null result in federated query for a single projected column #32444

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public boolean next() {
if (result && null != enumerator.current()) {
currentRows = enumerator.current().getClass().isArray() && !(enumerator.current() instanceof byte[]) ? (Object[]) enumerator.current() : new Object[]{enumerator.current()};
} else {
currentRows = new Object[]{};
currentRows = new Object[]{null};
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ public static String bin(final Object value) {
if (value instanceof Number && !(value instanceof BigInteger)) {
return Long.toBinaryString(((Number) value).longValue());
}
if (value instanceof String && ((String) value).isEmpty()) {
return null;
}
BigInteger bigIntegerValue = value instanceof BigInteger ? (BigInteger) value : new BigInteger(getFirstNumbers(String.valueOf(value)));
return -1 == bigIntegerValue.signum() ? bigIntegerValue.add(BigInteger.ONE.shiftLeft(Long.SIZE).subtract(BigInteger.ONE)).add(BigInteger.ONE).toString(2) : bigIntegerValue.toString(2);
}

private static String getFirstNumbers(final String value) {
if (value.isEmpty()) {
return "0";
}
boolean isNegative = '-' == value.charAt(0);
StringBuilder result = new StringBuilder();
if (isNegative) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public final class MySQLBitCountFunction {
@SuppressWarnings("unused")
public static Object bitCount(final Object value) {
if (null == value) {
return 0;
return null;
}
if (value instanceof byte[]) {
return bitCount((byte[]) value);
Expand Down
16 changes: 16 additions & 0 deletions test/e2e/sql/src/test/resources/cases/dql/e2e-dql-select.xml
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,10 @@
<assertion expected-data-source-name="read_dataset" />
</test-case>

<test-case sql="SELECT BIT_COUNT(NULL)" db-types="MySQL" scenario-types="db_tbl_sql_federation">
<assertion expected-data-source-name="read_dataset" />
</test-case>

<test-case sql="SELECT bit_count(123456), bit_count('123456'), bit_count('abcdefg'), BIT_COUNT('abcdef1234'), bit_count(''), bit_count(1 + 1)" db-types="MySQL" scenario-types="db_tbl_sql_federation">
<assertion expected-data-source-name="read_dataset" />
</test-case>
Expand Down Expand Up @@ -370,4 +374,16 @@
INNER JOIN t_order_item t3 ON t2.product_id = t3.product_id INNER JOIN t_order t4 ON t4.order_id = t3.order_id order by t1.product_id" db-types="MySQL" scenario-types="db_tbl_sql_federation">
<assertion expected-data-source-name="read_dataset" />
</test-case>

<test-case sql="SELECT BIN(NULL)" db-types="MySQL" scenario-types="db_tbl_sql_federation">
<assertion expected-data-source-name="read_dataset" />
</test-case>

<test-case sql="SELECT BIN('')" db-types="MySQL" scenario-types="db_tbl_sql_federation">
<assertion expected-data-source-name="read_dataset" />
</test-case>

<test-case sql="SELECT BIN(NULL), BIN(''), BIN(' ')" db-types="MySQL" scenario-types="db_tbl_sql_federation">
<assertion expected-data-source-name="read_dataset" />
</test-case>
</e2e-test-cases>
Loading