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

SNOW-1853752: Statement batch doesn't reset after statement.executeBatch() #2002

Open
itdv opened this issue Dec 11, 2024 · 1 comment
Open
Assignees
Labels
bug status-triage_done Initial triage done, will be further handled by the driver team

Comments

@itdv
Copy link

itdv commented Dec 11, 2024

JDBC driver version: 3.20.0
According to the JDBC 4.3 specification (Section 14.1.2, Successful Execution):

The statement’s batch is reset to empty once executeBatch returns.

However, this is not how it is implemented in the Snowflake JDBC driver. The batch does not get cleared unless explicitly cleared using statement.clearBatch().

(As noted here, this behavior may be appropriate for unsuccessful executions as well. However, for successful executions, the specification explicitly states that the batch should be cleared.)

@itdv itdv added the bug label Dec 11, 2024
@github-actions github-actions bot changed the title Statement batch doesn't reset after statement.executeBatch() SNOW-1853752: Statement batch doesn't reset after statement.executeBatch() Dec 11, 2024
@sfc-gh-sghosh sfc-gh-sghosh self-assigned this Dec 12, 2024
@sfc-gh-sghosh
Copy link
Contributor

Hello @itdv ,

Thanks for raising the issue, yes, we are able to reproduce the issue, the batch is not getting cleared after executebatch, we will work on it and update.

`try {
stmt.execute("drop table Emp_dept1");
stmt.execute("drop table Emp1");
stmt.execute("drop table Dept1");

	} catch (Exception e) {
		// TODO: handle exception
	}

	
	
	stmt.executeUpdate("create or replace table Emp1(id int, name STRING)");
	stmt.executeUpdate("create or replace table Dept1(id int, deptname String)");
	stmt.executeUpdate("create or replace table Emp_dept1(id int, dept int)");
	
	System.out.println("Done creating demo table\n");
	
	con.setAutoCommit(false);

	
	stmt.addBatch("insert into  Emp1 values (1000,'Jones')");
	stmt.addBatch("insert into  Dept1 values (260,'Shoe')");
	stmt.addBatch("insert into  Emp_dept1 values (1000, 260)");
	
	int[] updatecounts = stmt.executeBatch();

	System.out.println("All inserted via batch");

	
    for (int i = 0; i < updatecounts.length; i++) {
        System.out.println("Statement " + (i + 1) + " affected " + updatecounts[i] + " rows.");
    }


    con.commit();
    
   	    

    int[] emptyUpdateCounts = stmt.executeBatch();
    System.out.println("Re-executed the batch. Update counts:");
 
    for (int i = 0; i < updatecounts.length; i++) {
        System.out.println("Statement " + (i + 1) + " affected " + updatecounts[i] + " rows.");
    }
    con.commit();
    `

output:
All inserted via batch
Statement 1 affected 1 rows.
Statement 2 affected 1 rows.
Statement 3 affected 1 rows.

Re-executed the batch. Update counts:
Statement 1 affected 1 rows.
Statement 2 affected 1 rows.
Statement 3 affected 1 rows.

Regards,
Sujan

@sfc-gh-sghosh sfc-gh-sghosh added the status-triage_done Initial triage done, will be further handled by the driver team label Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug status-triage_done Initial triage done, will be further handled by the driver team
Projects
None yet
Development

No branches or pull requests

3 participants