public Map<DataType, Long> getTypeHistogram(final DatasetPath datasetPath, DatasetVersion version, String colName, SqlQuery datasetQuery) {
JobUI datasetPreviewJob = DatasetsUtil.getDatasetPreviewJob(executor, datasetQuery, datasetPath, version);
String quotedColName = quoteIdentifier(colName);
String newSql = format("SELECT typeOf(dremio_values_table.%s) AS dremio_value_type, COUNT(*) as dremio_type_count FROM %s AS dremio_values_table GROUP BY typeOf(dremio_values_table.%s)",
quotedColName, datasetPreviewJob.getData().getJobResultsTable(), quotedColName);
JobData completeJobData = executor.runQuery(datasetQuery.cloneWithNewSql(newSql), QueryType.UI_INTERNAL_RUN, datasetPath, version).getData();
final Map<DataType, Long> values = new LinkedHashMap<>();
int offset = 0;
JobDataFragment data = completeJobData.range(offset, BATCH_SIZE);
while(data.getReturnedRowCount() > 0) {
for (int i = 0; i < data.getReturnedRowCount(); i++) {
String typeName = data.extractString("dremio_value_type", i);
DataType dataType = DataTypeUtil.getDataType(MinorType.valueOf(typeName));
Long existing = values.get(dataType);
if (existing == null) {
existing = Long.valueOf(0);
}
Long newValue = (Long) data.extractValue("dremio_type_count", i);
values.put(dataType, existing + newValue);
}
offset += data.getReturnedRowCount();
data = completeJobData.range(offset, BATCH_SIZE);
}
return values;
}