d983323cd2570af1cf3971763d14ef2d88c06fe4
jcasper
Wed Feb 19 17:00:19 2025 -0800
sqlTableSize needs to support tables with more than 2B rows (rarely, but it does), refs #35262
diff --git src/hg/hgTables/rangeHistogram.c src/hg/hgTables/rangeHistogram.c
index 0e1805e6d4d..48bbeae3bed 100644
--- src/hg/hgTables/rangeHistogram.c
+++ src/hg/hgTables/rangeHistogram.c
@@ -1,107 +1,116 @@
/* ranges - display value ranges and histograms on fields. */
/* Copyright (C) 2013 The Regents of the University of California
* See kent/LICENSE or http://genome.ucsc.edu/license/ for licensing information. */
#include "common.h"
#include "linefile.h"
#include "hash.h"
#include "htmshell.h"
#include "cheapcgi.h"
#include "cart.h"
#include "jksql.h"
#include "hgTables.h"
#include "bedCart.h"
static void printValueHistogram(char *db, char *table, char *field)
/* Print very simple-minded text histogram. */
{
double maxHist = 60;
double scale = -1.0;
struct sqlConnection *conn = hAllocConn(db);
struct sqlResult *sr;
char **row;
char query[256];
+#define TOO_BIG_FOR_HISTO 500000
+boolean tooBig = (sqlTableSize(conn, table) > TOO_BIG_FOR_HISTO);
+if (tooBig)
+ {
+ hPrintf("This table has too many rows for histogram view");
+ hFreeConn(&conn);
+ return;
+ }
+
sqlSafef(query, sizeof(query),
"select %s, count(*) as count from %s group by %s order by count desc",
field, table, field);
sr = sqlGetResult(conn, query);
hTableStart();
hPrintf("
");
hPrintf("value | ");
hPrintf("count | ");
hPrintf("graph | ");
hPrintf("
");
while ((row = sqlNextRow(sr)) != NULL)
{
char *name = htmlEncode(row[0]);
int count = atoi(row[1]);
int starCount;
if (scale < 0)
scale = (maxHist)/count;
hPrintf("%s | ", name);
hPrintf("%d | ", count);
hPrintf("");
starCount = round(scale*count);
if (starCount > 0)
starOut(stdout, starCount);
else
hPrintf(" ");
hPrintf(" |
\n");
freeMem(name);
}
// hPrintf("");
hTableEnd();
hFreeConn(&conn);
}
void doValueHistogram(char *field)
/* Put up value histogram. */
{
char *db = cartString(cart, hgtaDatabase);
char *table = cartString(cart, hgtaHistoTable);
htmlOpen("Value histogram for %s.%s.%s", db, table, field);
printValueHistogram(db, table, field);
htmlClose();
}
static void printValueRange(char *db, char *table, char *field)
/* Print min/max/mean. */
{
struct sqlConnection *conn = hAllocConn(db);
struct sqlResult *sr;
char **row;
char query[256];
sqlSafef(query, sizeof(query),
"select min(%s), max(%s), avg(%s) from %s", field, field, field, table);
sr = sqlGetResult(conn, query);
while ((row = sqlNextRow(sr)) != NULL)
{
hPrintf("min: %s max: %s average: %s\n",
row[0], row[1], row[2]);
}
hFreeConn(&conn);
}
void doValueRange(char *field)
/* Put up value histogram. */
{
char *db = cartString(cart, hgtaDatabase);
char *table = cartString(cart, hgtaHistoTable);
boolean showItemRgb = FALSE;
showItemRgb=bedItemRgb(findTdbForTable(db, curTrack, table, ctLookupName));
// should we expect itemRgb instead of "reserved"
if (showItemRgb && sameWord(field, "reserved"))
htmlOpen("Value range for %s.%s.itemRgb", db, table);
else
htmlOpen("Value range for %s.%s.%s", db, table, field);
printValueRange(db, table, field);
htmlClose();
}