@@ -434,13 +434,19 @@ void testAllPurposeClusters_errorHandling() throws Exception {
434434 void testAllPurposeClusters_async () throws Exception {
435435 String jdbcUrl =
436436 "jdbc:databricks://e2-dogfood.staging.cloud.databricks.com:443/default;ssl=1;AuthMech=3;httpPath=sql/protocolv1/o/6051921418418893/1115-130834-ms4m0yv;enableDirectResults=1" ;
437- Connection con = DriverManager .getConnection (jdbcUrl , "token" , "token" );
437+ String token = "token" ;
438+ Connection con = DriverManager .getConnection (jdbcUrl , "token" , token );
438439 System .out .println ("Connection established...... con1" );
439440 Statement s = con .createStatement ();
440441 IDatabricksStatement ids = s .unwrap (IDatabricksStatement .class );
442+ try {
443+ s .execute ("DROP TABLE JDBC_ASYNC_CLUSTER" );
444+ } catch (Exception e ) {
445+ // do nothing
446+ }
441447 long initialTime = System .currentTimeMillis ();
442448 String sql =
443- "CREATE TABLE TMP_P2P_EKKO_EKPO_ASYNC8 AS ("
449+ "CREATE TABLE JDBC_ASYNC_CLUSTER AS ("
444450 + " SELECT * FROM ("
445451 + " SELECT * FROM ("
446452 + " SELECT t1.*"
@@ -471,7 +477,75 @@ void testAllPurposeClusters_async() throws Exception {
471477 + (System .currentTimeMillis () - initialTime ));
472478 }
473479
474- Connection con2 = DriverManager .getConnection (jdbcUrl , "token" , "token" );
480+ Connection con2 = DriverManager .getConnection (jdbcUrl , "token" , token );
481+ System .out .println ("Connection established......con2" );
482+ IDatabricksConnection idc = con2 .unwrap (IDatabricksConnection .class );
483+ Statement stm = idc .getStatement (rs .unwrap (IDatabricksResultSet .class ).getStatementId ());
484+ ResultSet rs2 = stm .unwrap (IDatabricksStatement .class ).getExecutionResult ();
485+
486+ System .out .println (
487+ "Status of async execution using con2 "
488+ + rs2 .unwrap (IDatabricksResultSet .class ).getStatementStatus ().getState ());
489+
490+ stm .cancel ();
491+ stm .execute ("DROP TABLE JDBC_ASYNC_CLUSTER" );
492+ System .out .println ("Statement cancelled using con2" );
493+ s .close ();
494+ System .out .println ("Statement cancelled using con1" );
495+ con2 .close ();
496+ con .close ();
497+ System .out .println ("Connection closed successfully......" );
498+ }
499+
500+ @ Test
501+ void testDBSQL_async () throws Exception {
502+ String jdbcUrl =
503+ "jdbc:databricks://e2-dogfood.staging.cloud.databricks.com:443/default;ssl=1;AuthMech=3;httpPath=/sql/1.0/warehouses/791ba2a31c7fd70a;enableDirectResults=1" ;
504+ String token = "token" ;
505+ Connection con = DriverManager .getConnection (jdbcUrl , "token" , token );
506+ System .out .println ("Connection established...... con1" );
507+ Statement s = con .createStatement ();
508+ IDatabricksStatement ids = s .unwrap (IDatabricksStatement .class );
509+ try {
510+ s .execute ("DROP TABLE JDBC_ASYNC_DBSQL" );
511+ } catch (Exception e ) {
512+ // do nothing
513+ }
514+ long initialTime = System .currentTimeMillis ();
515+ String sql =
516+ "CREATE TABLE JDBC_ASYNC_DBSQL AS ("
517+ + " SELECT * FROM ("
518+ + " SELECT * FROM ("
519+ + " SELECT t1.*"
520+ + " FROM main.streaming.random_large_table t1"
521+ + " INNER JOIN main.streaming.random_large_table t2"
522+ + " ON t1.prompt = t2.prompt"
523+ + " ) nested_t1"
524+ + " ) nested_t2"
525+ + ")" ;
526+ ResultSet rs = ids .executeAsync (sql );
527+ System .out .println ("Time taken: " + (System .currentTimeMillis () - initialTime ));
528+ System .out .println (
529+ "Status of async execution " + rs .unwrap (IDatabricksResultSet .class ).getStatementStatus ());
530+
531+ System .out .println ("StatementId " + rs .unwrap (IDatabricksResultSet .class ).getStatementId ());
532+
533+ int count = 1 ;
534+ StatementState state = rs .unwrap (IDatabricksResultSet .class ).getStatementStatus ().getState ();
535+ while (state != StatementState .SUCCEEDED && state != StatementState .FAILED ) {
536+ Thread .sleep (1000 );
537+ rs = s .unwrap (IDatabricksStatement .class ).getExecutionResult ();
538+ state = rs .unwrap (IDatabricksResultSet .class ).getStatementStatus ().getState ();
539+ System .out .println (
540+ "Status of async execution "
541+ + state
542+ + " attempt "
543+ + count ++
544+ + " time taken "
545+ + (System .currentTimeMillis () - initialTime ));
546+ }
547+
548+ Connection con2 = DriverManager .getConnection (jdbcUrl , "token" , token );
475549 System .out .println ("Connection established......con2" );
476550 IDatabricksConnection idc = con2 .unwrap (IDatabricksConnection .class );
477551 Statement stm = idc .getStatement (rs .unwrap (IDatabricksResultSet .class ).getStatementId ());
@@ -482,7 +556,7 @@ void testAllPurposeClusters_async() throws Exception {
482556 + rs2 .unwrap (IDatabricksResultSet .class ).getStatementStatus ().getState ());
483557
484558 stm .cancel ();
485- stm .execute ("DROP TABLE TMP_P2P_EKKO_EKPO_ASYNC8 " );
559+ stm .execute ("DROP TABLE JDBC_ASYNC_DBSQL " );
486560 System .out .println ("Statement cancelled using con2" );
487561 s .close ();
488562 System .out .println ("Statement cancelled using con1" );
0 commit comments