Skip to content

Commit

Permalink
Fix null result in federated query for a single projected column (#32444
Browse files Browse the repository at this point in the history
)
  • Loading branch information
zihaoAK47 authored Aug 12, 2024
1 parent 4d448e5 commit 57b084b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
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>

0 comments on commit 57b084b

Please sign in to comment.