Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ static SqlType getSqlTypeFromStatementType(StatementType statementType) {
case "ROLLBACK_TRANSACTION":
return SqlType.TCL;
case "EXPORT_DATA":
return SqlType.EXPORT;
case "EXPORT_MODEL":
case "LOAD_DATA":
Comment thread
keshavdandeva marked this conversation as resolved.
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,15 +685,9 @@ void handleQueryResult(String query, TableResult results, SqlType queryType)
break;
case DML:
case DML_EXTRA:
try {
Job completedJob = this.bigQuery.getJob(results.getJobId()).waitFor();
JobStatistics.QueryStatistics statistics = completedJob.getStatistics();
updateAffectedRowCount(statistics.getNumDmlAffectedRows());
} catch (InterruptedException ex) {
throw new BigQueryJdbcRuntimeException(ex);
} catch (NullPointerException ex) {
throw new BigQueryJdbcException(ex);
}
QueryStatistics dmlStats = getQueryStatisticsFromJob(results);
Long dmlRowCount = (dmlStats != null) ? dmlStats.getNumDmlAffectedRows() : null;
Comment thread
keshavdandeva marked this conversation as resolved.
Outdated
updateAffectedRowCount(dmlRowCount);
break;
case TCL:
case DDL:
Expand Down Expand Up @@ -725,8 +719,43 @@ void handleQueryResult(String query, TableResult results, SqlType queryType)
throw new BigQueryJdbcException(ex);
}
break;
case EXPORT:
QueryStatistics exportStats = getQueryStatisticsFromJob(results);
Long exportRowCount = 0L;
if (exportStats != null) {
QueryStatistics.ExportDataStats dataStats = exportStats.getExportDataStats();
if (dataStats != null && dataStats.getRowCount() != null) {
exportRowCount = dataStats.getRowCount();
}
}
updateAffectedRowCount(exportRowCount);
break;
case OTHER:
throw new BigQueryJdbcException(String.format("Unexpected value: " + queryType));
String truncatedQuery =
Comment thread
keshavdandeva marked this conversation as resolved.
Outdated
(query != null && query.length() > 60) ? query.substring(0, 60) + "..." : query;
String jobId = (results.getJobId() != null) ? results.getJobId().getJob() : "unknown";
Comment thread
logachev marked this conversation as resolved.
Outdated
LOG.warning(
"Encountered unmapped SQL statement type [Job ID: %s]. Treating as update statement: %s",
jobId, truncatedQuery);
Comment thread
keshavdandeva marked this conversation as resolved.
Outdated
updateAffectedRowCount(results.getTotalRows());
break;
}
}

private QueryStatistics getQueryStatisticsFromJob(TableResult results) throws SQLException {
try {
Job job = this.bigQuery.getJob(results.getJobId());
Job completedJob = (job != null) ? job.waitFor() : null;
JobStatistics stats = (completedJob != null) ? completedJob.getStatistics() : null;
if (stats instanceof QueryStatistics) {
return (QueryStatistics) stats;
}
return null;
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
throw new BigQueryJdbcRuntimeException("Interrupted while waiting for job completion", ex);
} catch (BigQueryException ex) {
throw new BigQueryJdbcException("BigQueryException while waiting for job completion", ex);
}
}

Expand Down Expand Up @@ -1610,6 +1639,7 @@ enum SqlType {
DDL,
SCRIPT,
TCL,
EXPORT,
OTHER
}

Expand Down
Loading