stanfordnlp/CoreNLP · error · RuntimeException

getting table count is not working!

Error message

getting table count is not working! ${e}

What it means

getTotalCount wraps SQL failures in a RuntimeException with this message plus the SQLException details. The count query could not be executed against the n-gram table (bad table, connection, or SQL error).

Solutions

  1. Read the appended SQLException message for the root cause and fix it accordingly
  2. Create the missing GoogleNgrams_<NGRAM> table and index in psql if that is the cause
  3. Check the database connection settings and that the server is reachable

Example fix

// before
int n = GoogleNGramsSQLBacked.getTotalCount(5); // GoogleNgrams_5 missing
// after
psql -c "create table GoogleNgrams_5 (phrase text primary key not null, count bigint not null);"
int n = GoogleNGramsSQLBacked.getTotalCount(5);
Defensive patterns

Strategy: try-catch

Validate before calling

select to_regclass('GoogleNgrams_1') is not null as tableExists;

Try / catch

try { return GoogleNGramsSQLBacked.getTotalCount(ngram); } catch (RuntimeException e) { throw new IllegalStateException("DB count failed for ngram " + ngram, e); }

Prevention

When it happens

Trigger: Calling getTotalCount when the underlying 'select count(*) from GoogleNgrams_<ngram>' throws a SQLException — e.g. table does not exist, connection dropped, or insufficient privileges.

Common situations: Querying an n-gram size whose table was never created; database restart or timeout mid-query; wrong credentials/schema.

Understand the failure class

Background: "query failed", "%w: SQL error" — wrapped database query errors in Go libraries explained — this error's family across 3 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/fec67ffe3d6b3a49. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/util/GoogleNGramsSQLBacked.java:191

  }

  /** Note that this is really really slow for ngram > 1
   * TODO: make this fast (if we had been using mysql we could have)
   * **/
  public static int getTotalCount(int ngram){
    try{
      connect();
      Statement stmt = connection.createStatement();
      String table = tablenamePrefix + ngram;
      String q = "select count(*) from " + table+";";
      ResultSet s = stmt.executeQuery(q);
      if(s.next()){
        return s.getInt(1);
      } else
        throw new RuntimeException("getting table count is not working!");
    }
    catch(SQLException e){
      throw new RuntimeException("getting table count is not working! " + e);
    }
  }

  /** Return rank of 1 gram in google ngeams if it is less than 20k. Otherwise -1. */
  public static int get1GramRank(String str) {
    String query = null;
    try{
      connect();
      str = str.trim();
      if(str.contains("'")){
        str = StringUtils.escapeString(str, new char[]{'\''},'\'');
      }

      int ngram = str.split("\\s+").length;
      if(ngram > 1)
        return -1;
      String table =  "googlengrams_1_ranked20k";

View on GitHub (pinned to 1b7edd19c4)