Repository: apache/shardingsphere
Issue: wrong result for the null value in  int column 

age null 
mysql> insert into my_orders(name,create_time,age,ttt,dc) values('ruiaylin1', '2019-04-16 18:00:00', null,null, 14.56) ;
Query OK, 1 row affected (0.10 sec)

【proxy】
mysql> select * from my_orders ;                  
+------+-----------+-----------------------+------+------+-------+
| id   | name      | create_time           | age  | ttt  | dc    |
+------+-----------+-----------------------+------+------+-------+
|    1 | ruiaylin  | 2019-04-15 18:00:00.0 |    0 | NULL |  NULL |
|    2 | ruiaylin1 | 2019-04-16 18:00:00.0 |   15 | NULL |  NULL |
|    3 | ruiaylin1 | 2019-04-16 18:00:00.0 |   15 | NULL | 14.56 |
|    4 | ruiaylin1 | 2019-04-16 18:00:00.0 |    0 | NULL | 14.56 |   # age 0
+------+-----------+-----------------------+------+------+-------+
4 rows in set (0.03 sec)

【mysql】
mysql> mysql> select * from  my_orders_201904 ;
+----+-----------+---------------------+------+------+-------+
| id | name      | create_time         | age  | ttt  | dc    |
+----+-----------+---------------------+------+------+-------+
|  1 | ruiaylin  | 2019-04-15 18:00:00 | NULL | NULL |  NULL |
|  2 | ruiaylin1 | 2019-04-16 18:00:00 |   15 | NULL |  NULL |
|  3 | ruiaylin1 | 2019-04-16 18:00:00 |   15 | NULL | 14.56 |
|  4 | ruiaylin1 | 2019-04-16 18:00:00 | NULL | NULL | 14.56 |    # age NULL
+----+-----------+---------------------+------+------+-------+
4 rows in set (0.00 sec)



Changed files:
sharding-core/sharding-core-execute/src/main/java/org/apache/shardingsphere/core/execute/sql/execute/result/MemoryQueryResult.java
sharding-core/sharding-core-execute/src/main/java/org/apache/shardingsphere/core/execute/sql/execute/result/QueryResultUtil.java
sharding-core/sharding-core-execute/src/test/java/org/apache/shardingsphere/core/execute/sql/execute/result/QueryResultUtilTest.java

diff --git a/sharding-core/sharding-core-execute/src/main/java/org/apache/shardingsphere/core/execute/sql/execute/result/MemoryQueryResult.java b/sharding-core/sharding-core-execute/src/main/java/org/apache/shardingsphere/core/execute/sql/execute/result/MemoryQueryResult.java
index 52d81c6e2fe..1e79d31f888 100644
--- a/sharding-core/sharding-core-execute/src/main/java/org/apache/shardingsphere/core/execute/sql/execute/result/MemoryQueryResult.java
+++ b/sharding-core/sharding-core-execute/src/main/java/org/apache/shardingsphere/core/execute/sql/execute/result/MemoryQueryResult.java
@@ -68,7 +68,7 @@ public final class MemoryQueryResult implements QueryResult {
         while (resultSet.next()) {
             List<Object> rowData = new ArrayList<>(resultSet.getMetaData().getColumnCount());
             for (int columnIndex = 1; columnIndex <= resultSet.getMetaData().getColumnCount(); columnIndex++) {
-                rowData.add(QueryResultUtil.getValueByColumnType(resultSet, columnIndex));
+                rowData.add(QueryResultUtil.getValue(resultSet, columnIndex));
             }
             result.add(new QueryRow(rowData));
         }
diff --git a/sharding-core/sharding-core-execute/src/main/java/org/apache/shardingsphere/core/execute/sql/execute/result/QueryResultUtil.java b/sharding-core/sharding-core-execute/src/main/java/org/apache/shardingsphere/core/execute/sql/execute/result/QueryResultUtil.java
index 19dad89f35d..e41c8c2a35b 100644
--- a/sharding-core/sharding-core-execute/src/main/java/org/apache/shardingsphere/core/execute/sql/execute/result/QueryResultUtil.java
+++ b/sharding-core/sharding-core-execute/src/main/java/org/apache/shardingsphere/core/execute/sql/execute/result/QueryResultUtil.java
@@ -29,6 +29,19 @@ import java.sql.Types;
  */
 public class QueryResultUtil {
     
+    /**
+     * Get value.
+     *
+     * @param resultSet result set
+     * @param columnIndex column index of value
+     * @return {@code null} if the column is SQL {@code NULL}, otherwise the value of column
+     * @throws SQLException SQL exception
+     */
+    public static Object getValue(final ResultSet resultSet, final int columnIndex) throws SQLException {
+        Object result = getValueByColumnType(resultSet, columnIndex);
+        return resultSet.wasNull() ? null : result;
+    }
+    
     /**
      * Get value by column type.
      *
diff --git a/sharding-core/sharding-core-execute/src/test/java/org/apache/shardingsphere/core/execute/sql/execute/result/QueryResultUtilTest.java b/sharding-core/sharding-core-execute/src/test/java/org/apache/shardingsphere/core/execute/sql/execute/result/QueryResultUtilTest.java
index 8f93501faec..89531decbcc 100644
--- a/sharding-core/sharding-core-execute/src/test/java/org/apache/shardingsphere/core/execute/sql/execute/result/QueryResultUtilTest.java
+++ b/sharding-core/sharding-core-execute/src/test/java/org/apache/shardingsphere/core/execute/sql/execute/result/QueryResultUtilTest.java
@@ -36,6 +36,7 @@ import java.sql.Timestamp;
 import java.sql.Types;
 
 import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.mock;
@@ -61,7 +62,7 @@ public class QueryResultUtilTest {
     public void assertGetValueByBit() {
         when(resultSetMetaData.getColumnType(1)).thenReturn(Types.BIT);
         when(resultSet.getBoolean(1)).thenReturn(true);
-        assertTrue((boolean) QueryResultUtil.getValueByColumnType(resultSet, 1));
+        assertTrue((boolean) QueryResultUtil.getValue(resultSet, 1));
     }
     
     @Test
@@ -69,7 +70,7 @@ public class QueryResultUtilTest {
     public void assertGetValueByBoolean() {
         when(resultSetMetaData.getColumnType(1)).thenReturn(Types.BOOLEAN);
         when(resultSet.getBoolean(1)).thenReturn(true);
-        assertTrue((boolean) QueryResultUtil.getValueByColumnType(resultSet, 1));
+        assertTrue((boolean) QueryResultUtil.getValue(resultSet, 1));
     }
     
     @Test
@@ -77,7 +78,7 @@ public class QueryResultUtilTest {
     public void assertGetValueByTinyint() {
         when(resultSetMetaData.getColumnType(1)).thenReturn(Types.TINYINT);
         when(resultSet.getByte(1)).thenReturn(Byte.MAX_VALUE);
-        assertThat((byte) QueryResultUtil.getValueByColumnType(resultSet, 1), is(Byte.MAX_VALUE));
+        assertThat((byte) QueryResultUtil.getValue(resultSet, 1), is(Byte.MAX_VALUE));
     }
     
     @Test
@@ -85,7 +86,7 @@ public class QueryResultUtilTest {
     public void assertGetValueBySmallint() {
         when(resultSetMetaData.getColumnType(1)).thenReturn(Types.SMALLINT);
         when(resultSet.getShort(1)).thenReturn(Short.MAX_VALUE);
-        assertThat((short) QueryResultUtil.getValueByColumnType(resultSet, 1), is(Short.MAX_VALUE));
+        assertThat((short) QueryResultUtil.getValue(resultSet, 1), is(Short.MAX_VALUE));
     }
     
     @Test
@@ -93,7 +94,7 @@ public class QueryResultUtilTest {
     public void assertGetValueByInteger() {
         when(resultSetMetaData.getColumnType(1)).thenReturn(Types.INTEGER);
         when(resultSet.getInt(1)).thenReturn(Integer.MAX_VALUE);
-        assertThat((int) QueryResultUtil.getValueByColumnType(resultSet, 1), is(Integer.MAX_VALUE));
+        assertThat((int) QueryResultUtil.getValue(resultSet, 1), is(Integer.MAX_VALUE));
     }
     
     @Test
@@ -101,7 +102,7 @@ public class QueryResultUtilTest {
     public void assertGetValueByBigint() {
         when(resultSetMetaData.getColumnType(1)).thenReturn(Types.BIGINT);
         when(resultSet.getLong(1)).thenReturn(Long.MAX_VALUE);
-        assertThat((long) QueryResultUtil.getValueByColumnType(resultSet, 1), is(Long.MAX_VALUE));
+        assertThat((long) QueryResultUtil.getValue(resultSet, 1), is(Long.MAX_VALUE));
     }
     
     @Test
@@ -109,7 +110,7 @@ public class QueryResultUtilTest {
     public void assertGetValueByNumeric() {
         when(resultSetMetaData.getColumnType(1)).thenReturn(Types.NUMERIC);
         when(resultSet.getBigDecimal(1)).thenReturn(BigDecimal.TEN);
-        assertThat((BigDecimal) QueryResultUtil.getValueByColumnType(resultSet, 1), is(BigDecimal.TEN));
+        assertThat((BigDecimal) QueryResultUtil.getValue(resultSet, 1), is(BigDecimal.TEN));
     }
     
     @Test
@@ -117,7 +118,7 @@ public class QueryResultUtilTest {
     public void assertGetValueByDecimal() {
         when(resultSetMetaData.getColumnType(1)).thenReturn(Types.DECIMAL);
         when(resultSet.getBigDecimal(1)).thenReturn(BigDecimal.TEN);
-        assertThat((BigDecimal) QueryResultUtil.getValueByColumnType(resultSet, 1), is(BigDecimal.TEN));
+        assertThat((BigDecimal) QueryResultUtil.getValue(resultSet, 1), is(BigDecimal.TEN));
     }
     
     @Test
@@ -125,7 +126,7 @@ public class QueryResultUtilTest {
     public void assertGetValueByFloat() {
         when(resultSetMetaData.getColumnType(1)).thenReturn(Types.FLOAT);
         when(resultSet.getDouble(1)).thenReturn(Double.MAX_VALUE);
-        assertThat((double) QueryResultUtil.getValueByColumnType(resultSet, 1), is(Double.MAX_VALUE));
+        assertThat((double) QueryResultUtil.getValue(resultSet, 1), is(Double.MAX_VALUE));
     }
     
     @Test
@@ -133,7 +134,7 @@ public class QueryResultUtilTest {
     public void assertGetValueByDouble() {
         when(resultSetMetaData.getColumnType(1)).thenReturn(Types.DOUBLE);
         when(resultSet.getDouble(1)).thenReturn(Double.MAX_VALUE);
-        assertThat((double) QueryResultUtil.getValueByColumnType(resultSet, 1), is(Double.MAX_VALUE));
+        assertThat((double) QueryResultUtil.getValue(resultSet, 1), is(Double.MAX_VALUE));
     }
     
     @Test
@@ -141,7 +142,7 @@ public class QueryResultUtilTest {
     public void assertGetValueByChar() {
         when(resultSetMetaData.getColumnType(1)).thenReturn(Types.CHAR);
         when(resultSet.getString(1)).thenReturn("x");
-        assertThat((String) QueryResultUtil.getValueByColumnType(resultSet, 1), is("x"));
+        assertThat((String) QueryResultUtil.getValue(resultSet, 1), is("x"));
     }
     
     @Test
@@ -149,7 +150,7 @@ public class QueryResultUtilTest {
     public void assertGetValueByVarchar() {
         when(resultSetMetaData.getColumnType(1)).thenReturn(Types.VARCHAR);
         when(resultSet.getString(1)).thenReturn("xxxxx");
-        assertThat((String) QueryResultUtil.getValueByColumnType(resultSet, 1), is("xxxxx"));
+        assertThat((String) QueryResultUtil.getValue(resultSet, 1), is("xxxxx"));
     }
     
     @Test
@@ -157,7 +158,7 @@ public class QueryResultUtilTest {
     public void assertGetValueByLongVarchar() {
         when(resultSetMetaData.getColumnType(1)).thenReturn(Types.LONGVARCHAR);
         when(resultSet.getString(1)).thenReturn("xxxxx");
-        assertThat((String) QueryResultUtil.getValueByColumnType(resultSet, 1), is("xxxxx"));
+        assertThat((String) QueryResultUtil.getValue(resultSet, 1), is("xxxxx"));
     }
     
     @Test
@@ -165,7 +166,7 @@ public class QueryResultUtilTest {
     public void assertGetValueByBinary() {
         when(resultSetMetaData.getColumnType(1)).thenReturn(Types.BINARY);
         when(resultSet.getBytes(1)).thenReturn("xxxxx".getBytes());
-        assertThat((byte[]) QueryResultUtil.getValueByColumnType(resultSet, 1), is("xxxxx".getBytes()));
+        assertThat((byte[]) QueryResultUtil.getValue(resultSet, 1), is("xxxxx".getBytes()));
     }
     
     @Test
@@ -173,7 +174,7 @@ public class QueryResultUtilTest {
     public void assertGetValueByVarBinary() {
         when(resultSetMetaData.getColumnType(1)).thenReturn(Types.VARBINARY);
         when(resultSet.getBytes(1)).thenReturn("xxxxx".getBytes());
-        assertThat((byte[]) QueryResultUtil.getValueByColumnType(resultSet, 1), is("xxxxx".getBytes()));
+        assertThat((byte[]) QueryResultUtil.getValue(resultSet, 1), is("xxxxx".getBytes()));
     }
     
     @Test
@@ -181,7 +182,7 @@ public class QueryResultUtilTest {
     public void assertGetValueByLongVarBinary() {
         when(resultSetMetaData.getColumnType(1)).thenReturn(Types.LONGVARBINARY);
         when(resultSet.getBytes(1)).thenReturn("xxxxx".getBytes());
-        assertThat((byte[]) QueryResultUtil.getValueByColumnType(resultSet, 1), is("xxxxx".getBytes()));
+        assertThat((byte[]) QueryResultUtil.getValue(resultSet, 1), is("xxxxx".getBytes()));
     }
     
     @Test
@@ -190,7 +191,7 @@ public class QueryResultUtilTest {
         long currentTime = System.currentTimeMillis();
         when(resultSetMetaData.getColumnType(1)).thenReturn(Types.DATE);
         when(resultSet.getDate(1)).thenReturn(new Date(currentTime));
-        assertThat((Date) QueryResultUtil.getValueByColumnType(resultSet, 1), is(new Date(currentTime)));
+        assertThat((Date) QueryResultUtil.getValue(resultSet, 1), is(new Date(currentTime)));
     }
     
     @Test
@@ -199,7 +200,7 @@ public class QueryResultUtilTest {
         long currentTime = System.currentTimeMillis();
         when(resultSetMetaData.getColumnType(1)).thenReturn(Types.TIME);
         when(resultSet.getTime(1)).thenReturn(new Time(currentTime));
-        assertThat((Time) QueryResultUtil.getValueByColumnType(resultSet, 1), is(new Time(currentTime)));
+        assertThat((Time) QueryResultUtil.getValue(resultSet, 1), is(new Time(currentTime)));
     }
     
     @Test
@@ -208,7 +209,7 @@ public class QueryResultUtilTest {
         long currentTime = System.currentTimeMillis();
         when(resultSetMetaData.getColumnType(1)).thenReturn(Types.TIMESTAMP);
         when(resultSet.getTimestamp(1)).thenReturn(new Timestamp(currentTime));
-        assertThat((Timestamp) QueryResultUtil.getValueByColumnType(resultSet, 1), is(new Timestamp(currentTime)));
+        assertThat((Timestamp) QueryResultUtil.getValue(resultSet, 1), is(new Timestamp(currentTime)));
     }
     
     @Test
@@ -217,7 +218,7 @@ public class QueryResultUtilTest {
         Clob clob = mock(Clob.class);
         when(resultSetMetaData.getColumnType(1)).thenReturn(Types.CLOB);
         when(resultSet.getClob(1)).thenReturn(clob);
-        assertThat((Clob) QueryResultUtil.getValueByColumnType(resultSet, 1), is(clob));
+        assertThat((Clob) QueryResultUtil.getValue(resultSet, 1), is(clob));
     }
     
     @Test
@@ -226,7 +227,7 @@ public class QueryResultUtilTest {
         Blob blob = mock(Blob.class);
         when(resultSetMetaData.getColumnType(1)).thenReturn(Types.BLOB);
         when(resultSet.getBlob(1)).thenReturn(blob);
-        assertThat((Blob) QueryResultUtil.getValueByColumnType(resultSet, 1), is(blob));
+        assertThat((Blob) QueryResultUtil.getValue(resultSet, 1), is(blob));
     }
     
     @Test
@@ -235,6 +236,14 @@ public class QueryResultUtilTest {
         Object object = new Object();
         when(resultSetMetaData.getColumnType(1)).thenReturn(Types.OTHER);
         when(resultSet.getObject(1)).thenReturn(object);
-        assertThat(QueryResultUtil.getValueByColumnType(resultSet, 1), is(object));
+        assertThat(QueryResultUtil.getValue(resultSet, 1), is(object));
     }
+    
+    @Test
+    @SneakyThrows
+    public void assertNullResultValue() {
+        when(resultSet.getObject(1)).thenReturn(null);
+        assertNull(QueryResultUtil.getValue(resultSet, 1));
+    }
+    
 }