talweksler
talweksler

Reputation: 1

Slow mysql JDBC connection in Google Data Studio

I am building a community connector in Google Data Studio and I am trying to build a mysql connector and testing it on AWS RDS. For the test, I am just doing a simple select col_name1, col_name2, col_name3, col_name4 from table. The table has around 3,500 rows. The query itself is running pretty fast (less than 1 sec). If I am building a report using the official mysql connector, the data refresh super fast when I initialize refresh (I also catch the query on the mysql side with slow queries log set to 0 seconds) I made sure this is not cached, I am initializing refresh data. However when I'm trying to run my own custom connector, the loop on the result dataset is super slow and can take even 60 seconds for just 3,500 rows. I tried setFetchSize(100) and also tried 1000, 10000 and nothing helps. I already made sure that it is not the query itself, it is the looping over the resultset. Any thoughts what I'm missing?

Here is my code:

let conn = getDbConnection(request.configParams);
    conn.setReadOnly(true);
    let statement = conn.prepareStatement(query);
    statement.setFetchSize(100);
    
    let resultSet = statement.executeQuery(query);
    let metadata = resultSet.getMetaData();
    let numColumns = metadata.getColumnCount();

    let columnTypes = [];
    for (let i = 1; i <= numColumns; i++) {
      columnTypes.push(convertJAVAToLookerTypes(metadata.getColumnType(i)));
    }

    let data = [];
    let counter = 0;
    while (resultSet.next()) {
      let values = Array(numColumns);
      for (let i = 1; i <= numColumns; i++) {
        values[i - 1] = getValueByTypeObject(resultSet, i, columnTypes[i - 1]);
      }

      data.push({ values: values });
    }


    function getValueByTypeObject(resultSet, index, sqlType) {
    your text`let date;
    switch (sqlType) {
       case 'DATE':
          date = resultSet.getObject(index);
          return date ? date.getTime() : null;
       case 'TIMESTAMP':
          date = resultSet.getObject(index);
          return date ? date.getTime() : null;
       default:
          return resultSet.getObject(index);
  }
}

I'm expecting it to run as quickly as the official mysql connector.

Upvotes: 0

Views: 28

Answers (0)

Related Questions