Repository: jtablesaw/tablesaw
Pull request #416 (2018-11-20 20:46:34)

Add SQL date support
- [X] Tick to sign-off your agreement to the [Developer Certificate of Origin (DCO) 1.1](https://developercertificate.org)

## Description

Adds SQL date support. Fixes https://github.com/jtablesaw/tablesaw/issues/414

## Testing

Expanded existing unit tests to cover date type



Patch:
diff --git a/core/src/main/java/tech/tablesaw/api/DateColumn.java b/core/src/main/java/tech/tablesaw/api/DateColumn.java
index 41557a9e..2af27328 100644
--- a/core/src/main/java/tech/tablesaw/api/DateColumn.java
+++ b/core/src/main/java/tech/tablesaw/api/DateColumn.java
@@ -354,10 +354,13 @@ public class DateColumn extends AbstractColumn<LocalDate> implements DateFilters
         if (obj == null) {
             return appendMissing();
         }
-        if (!(obj instanceof LocalDate)) {
-            throw new IllegalArgumentException("Cannot append " + obj.getClass().getName() + " to DateColumn");
+        if (obj instanceof java.sql.Date) {
+            return append(((java.sql.Date) obj).toLocalDate());
         }
-        return append((LocalDate) obj);
+        if (obj instanceof LocalDate) {
+            return append((LocalDate) obj);
+        }
+        throw new IllegalArgumentException("Cannot append " + obj.getClass().getName() + " to DateColumn");
     }
 
     @Override


Test patch:
diff --git a/core/src/test/java/tech/tablesaw/io/jdbc/SqlResultSetReaderTest.java b/core/src/test/java/tech/tablesaw/io/jdbc/SqlResultSetReaderTest.java
index 89b6251d..859cde3e 100644
--- a/core/src/test/java/tech/tablesaw/io/jdbc/SqlResultSetReaderTest.java
+++ b/core/src/test/java/tech/tablesaw/io/jdbc/SqlResultSetReaderTest.java
@@ -63,7 +63,7 @@ public class SqlResultSetReaderTest {
             sql = "SELECT * FROM Customer";
             try (ResultSet rs = stmt.executeQuery(sql)) {
                 Table customer = SqlResultSetReader.read(rs, "Customer");
-                Assert.assertEquals(6, customer.columnCount());
+                Assert.assertEquals(7, customer.columnCount());
                 Assert.assertEquals(3, customer.rowCount());
             }
 
diff --git a/core/src/test/java/tech/tablesaw/util/TestDb.java b/core/src/test/java/tech/tablesaw/util/TestDb.java
index dae110ac..cb2afc84 100644
--- a/core/src/test/java/tech/tablesaw/util/TestDb.java
+++ b/core/src/test/java/tech/tablesaw/util/TestDb.java
@@ -257,6 +257,7 @@ public class TestDb {
             stmt.execute("CREATE TABLE Customer" +
                     "( CustomerNumber CHAR(10) NOT NULL PRIMARY KEY, " +
                     "  Name CHAR(25)," +
+                    "  RegistrationDate DATE," +
                     "  Address CHAR(25)," +
                     "  City CHAR(12)," +
                     "  State CHAR(2)," +
@@ -264,16 +265,16 @@ public class TestDb {
 
             // Add some rows to the new table.
             stmt.executeUpdate("INSERT INTO Customer VALUES" +
-                    "('101', 'Downtown Cafe', '17 N. Main Street'," +
+                    "('101', 'Downtown Cafe', '2004-01-29', '17 N. Main Street'," +
                     " 'Asheville', 'NC', '55515')");
 
             stmt.executeUpdate("INSERT INTO Customer VALUES" +
-                    "('102', 'Main Street Grocery'," +
+                    "('102', 'Main Street Grocery', '2005-02-10'," +
                     " '110 E. Main Street'," +
                     " 'Canton', 'NC', '55555')");
 
             stmt.executeUpdate("INSERT INTO Customer VALUES" +
-                    "('103', 'The Coffee Place', '101 Center Plaza'," +
+                    "('103', 'The Coffee Place', '2006-08-31', '101 Center Plaza'," +
                     " 'Waynesville', 'NC', '55516')");
         } catch (SQLException ex) {
             System.out.println("ERROR: " + ex.getMessage());