Github user hotou commented on a diff in the pull request:

    https://github.com/apache/spark/pull/4701#discussion_r25123040
  
    --- Diff: core/src/test/scala/org/apache/spark/rdd/JdbcRDDSuite.scala ---
    @@ -29,22 +29,42 @@ class JdbcRDDSuite extends FunSuite with BeforeAndAfter 
with LocalSparkContext {
         Class.forName("org.apache.derby.jdbc.EmbeddedDriver")
         val conn = 
DriverManager.getConnection("jdbc:derby:target/JdbcRDDSuiteDb;create=true")
         try {
    -      val create = conn.createStatement
    -      create.execute("""
    -        CREATE TABLE FOO(
    -          ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, 
INCREMENT BY 1),
    -          DATA INTEGER
    -        )""")
    -      create.close()
    -      val insert = conn.prepareStatement("INSERT INTO FOO(DATA) VALUES(?)")
    -      (1 to 100).foreach { i =>
    -        insert.setInt(1, i * 2)
    -        insert.executeUpdate
    +
    +      try {
    +        val create = conn.createStatement
    +        create.execute("""
    +          CREATE TABLE FOO(
    +            ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 
1, INCREMENT BY 1),
    +            DATA INTEGER
    +          )""")
    +        create.close()
    +        val insert = conn.prepareStatement("INSERT INTO FOO(DATA) 
VALUES(?)")
    +        (1 to 100).foreach { i =>
    +          insert.setInt(1, i * 2)
    +          insert.executeUpdate
    +        }
    +        insert.close()
    +      } catch {
    +        case e: SQLException if e.getSQLState == "X0Y32" =>
    +        // table exists
           }
    -      insert.close()
    -    } catch {
    -      case e: SQLException if e.getSQLState == "X0Y32" =>
    +
    +      try {
    +        val create = conn.createStatement
    +        create.execute("CREATE TABLE BIGINT_TEST(ID BIGINT NOT NULL, DATA 
INTEGER)")
    +        create.close()
    +        val insert = conn.prepareStatement("INSERT INTO BIGINT_TEST 
VALUES(?,?)")
    +        (1 to 100).foreach { i =>
    +          insert.setLong(1, 100000000000000000L +  4000000000000000L * i)
    +          insert.setInt(2, i)
    +          insert.executeUpdate
    +        }
    +        insert.close()
    +      } catch {
    --- End diff --
    
    There was a problem when I tried to to that. The original writer uses the 
inner catch block to prevent re-creating the table. 
    
    catch {
      case e: SQLException if e.getSQLState == "X0Y32" =>
      // table exists
    }
    
    Which means it has to exist for each table to be created. I was simply 
following that pattern. 
    
    An alternative would be is to drop and re-create the table each time, which 
produce cleaner codes, but may slow down the test suite a little bit



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to