@@ -685,15 +685,12 @@ void handleQueryResult(String query, TableResult results, SqlType queryType)
685685 break ;
686686 case DML :
687687 case DML_EXTRA :
688- try {
689- Job completedJob = this .bigQuery .getJob (results .getJobId ()).waitFor ();
690- JobStatistics .QueryStatistics statistics = completedJob .getStatistics ();
691- updateAffectedRowCount (statistics .getNumDmlAffectedRows ());
692- } catch (InterruptedException ex ) {
693- throw new BigQueryJdbcRuntimeException (ex );
694- } catch (NullPointerException ex ) {
695- throw new BigQueryJdbcException (ex );
696- }
688+ QueryStatistics dmlStats = getQueryStatisticsFromJob (results );
689+ Long dmlRowCount =
690+ (dmlStats != null && dmlStats .getNumDmlAffectedRows () != null )
691+ ? dmlStats .getNumDmlAffectedRows ()
692+ : 0L ;
693+ updateAffectedRowCount (dmlRowCount );
697694 break ;
698695 case TCL :
699696 case DDL :
@@ -725,8 +722,43 @@ void handleQueryResult(String query, TableResult results, SqlType queryType)
725722 throw new BigQueryJdbcException (ex );
726723 }
727724 break ;
725+ case EXPORT :
726+ QueryStatistics exportStats = getQueryStatisticsFromJob (results );
727+ Long exportRowCount = 0L ;
728+ if (exportStats != null ) {
729+ QueryStatistics .ExportDataStats dataStats = exportStats .getExportDataStats ();
730+ if (dataStats != null && dataStats .getRowCount () != null ) {
731+ exportRowCount = dataStats .getRowCount ();
732+ }
733+ }
734+ updateAffectedRowCount (exportRowCount );
735+ break ;
728736 case OTHER :
729- throw new BigQueryJdbcException (String .format ("Unexpected value: " + queryType ));
737+ String truncatedQuery = truncateQuery (query );
738+ String id =
739+ (results .getJobId () != null ) ? results .getJobId ().getJob () : results .getQueryId ();
740+ LOG .warning (
741+ "Encountered unmapped SQL statement type [Job/Query ID: %s]. Treating as update statement: %s" ,
742+ id , truncatedQuery );
743+ updateAffectedRowCount (results .getTotalRows ());
744+ break ;
745+ }
746+ }
747+
748+ private QueryStatistics getQueryStatisticsFromJob (TableResult results ) throws SQLException {
749+ try {
750+ Job job = this .bigQuery .getJob (results .getJobId ());
751+ Job completedJob = (job != null ) ? job .waitFor () : null ;
752+ JobStatistics stats = (completedJob != null ) ? completedJob .getStatistics () : null ;
753+ if (stats instanceof QueryStatistics ) {
754+ return (QueryStatistics ) stats ;
755+ }
756+ return null ;
757+ } catch (InterruptedException ex ) {
758+ Thread .currentThread ().interrupt ();
759+ throw new BigQueryJdbcRuntimeException ("Interrupted while waiting for job completion" , ex );
760+ } catch (BigQueryException ex ) {
761+ throw new BigQueryJdbcException ("BigQueryException while waiting for job completion" , ex );
730762 }
731763 }
732764
@@ -1589,13 +1621,19 @@ protected void logQueryExecutionStart(String sql) {
15891621 if (sql == null ) {
15901622 return ;
15911623 }
1592- String sanitizedSql = sql .trim ().replaceAll ("\\ s+" , " " );
1593- String truncatedSql =
1594- sanitizedSql .length () > 256 ? sanitizedSql .substring (0 , 256 ) + "..." : sanitizedSql ;
1624+ String truncatedSql = truncateQuery (sql );
15951625 LOG .info ("Executing query: " + truncatedSql );
15961626 LOG .info ("Using query settings: " + this .querySettings .toString ());
15971627 }
15981628
1629+ private String truncateQuery (String sql ) {
1630+ if (sql == null ) {
1631+ return null ;
1632+ }
1633+ String sanitizedSql = sql .trim ().replaceAll ("\\ s+" , " " );
1634+ return sanitizedSql .length () > 256 ? sanitizedSql .substring (0 , 256 ) + "..." : sanitizedSql ;
1635+ }
1636+
15991637 /** Throws a {@link BigQueryJdbcException} if this object is closed */
16001638 void checkClosed () throws SQLException {
16011639 if (isClosed ()) {
@@ -1610,6 +1648,7 @@ enum SqlType {
16101648 DDL ,
16111649 SCRIPT ,
16121650 TCL ,
1651+ EXPORT ,
16131652 OTHER
16141653 }
16151654
0 commit comments