@@ -685,15 +685,9 @@ 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 = (dmlStats != null ) ? dmlStats .getNumDmlAffectedRows () : null ;
690+ updateAffectedRowCount (dmlRowCount );
697691 break ;
698692 case TCL :
699693 case DDL :
@@ -726,28 +720,42 @@ void handleQueryResult(String query, TableResult results, SqlType queryType)
726720 }
727721 break ;
728722 case EXPORT :
729- try {
730- Job job = this .bigQuery .getJob (results .getJobId ());
731- Job completedJob = (job != null ) ? job .waitFor () : null ;
732- JobStatistics stats = (completedJob != null ) ? completedJob .getStatistics () : null ;
733-
734- Long rowCount = 0L ;
735- if (stats instanceof JobStatistics .QueryStatistics ) {
736- JobStatistics .QueryStatistics queryStats = (JobStatistics .QueryStatistics ) stats ;
737- JobStatistics .QueryStatistics .ExportDataStats exportStats =
738- queryStats .getExportDataStats ();
739- if (exportStats != null && exportStats .getRowCount () != null ) {
740- rowCount = exportStats .getRowCount ();
741- }
723+ QueryStatistics exportStats = getQueryStatisticsFromJob (results );
724+ Long exportRowCount = 0L ;
725+ if (exportStats != null ) {
726+ QueryStatistics .ExportDataStats dataStats = exportStats .getExportDataStats ();
727+ if (dataStats != null && dataStats .getRowCount () != null ) {
728+ exportRowCount = dataStats .getRowCount ();
742729 }
743- updateAffectedRowCount (rowCount );
744- } catch (InterruptedException ex ) {
745- Thread .currentThread ().interrupt ();
746- throw new BigQueryJdbcRuntimeException (ex );
747730 }
731+ updateAffectedRowCount (exportRowCount );
748732 break ;
749733 case OTHER :
750- throw new BigQueryJdbcException (String .format ("Unexpected value: " + queryType ));
734+ String truncatedQuery =
735+ (query != null && query .length () > 60 ) ? query .substring (0 , 60 ) + "..." : query ;
736+ String jobId = (results .getJobId () != null ) ? results .getJobId ().getJob () : "unknown" ;
737+ LOG .warning (
738+ "Encountered unmapped SQL statement type [Job ID: %s]. Treating as update statement: %s" ,
739+ jobId , truncatedQuery );
740+ updateAffectedRowCount (results .getTotalRows ());
741+ break ;
742+ }
743+ }
744+
745+ private QueryStatistics getQueryStatisticsFromJob (TableResult results ) throws SQLException {
746+ try {
747+ Job job = this .bigQuery .getJob (results .getJobId ());
748+ Job completedJob = (job != null ) ? job .waitFor () : null ;
749+ JobStatistics stats = (completedJob != null ) ? completedJob .getStatistics () : null ;
750+ if (stats instanceof QueryStatistics ) {
751+ return (QueryStatistics ) stats ;
752+ }
753+ return null ;
754+ } catch (InterruptedException ex ) {
755+ Thread .currentThread ().interrupt ();
756+ throw new BigQueryJdbcRuntimeException ("Interrupted while waiting for job completion" , ex );
757+ } catch (BigQueryException ex ) {
758+ throw new BigQueryJdbcException ("BigQueryException while waiting for job completion" , ex );
751759 }
752760 }
753761
0 commit comments