<commit_before>package edu.washington.escience.myria.profiling;

import java.sql.BatchUpdateException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
import java.util.concurrent.TimeUnit;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;

import edu.washington.escience.myria.DbException;
import edu.washington.escience.myria.MyriaConstants;
import edu.washington.escience.myria.Schema;
import edu.washington.escience.myria.accessmethod.AccessMethod;
import edu.washington.escience.myria.accessmethod.AccessMethod.IndexRef;
import edu.washington.escience.myria.accessmethod.ConnectionInfo;
import edu.washington.escience.myria.accessmethod.JdbcAccessMethod;
import edu.washington.escience.myria.operator.Operator;
import edu.washington.escience.myria.parallel.WorkerSubQuery;

/**
 * A logger for profiling data.
 */
public class ProfilingLogger {
  /** The logger for this class. */
  private static final org.slf4j.Logger LOGGER = org.slf4j.LoggerFactory.getLogger(ProfilingLogger.class);

  /** The connection to the database database. */
  private final JdbcAccessMethod accessMethod;

  /** The jdbc connection. */
  private final Connection connection;

  /** A query statement for batching. */
  private PreparedStatement statementEvent;

  /** A query statement for batching. */
  private PreparedStatement statementSent;

  /** Number of rows in batch in {@link #statementEvent}. */
  private int batchSizeEvents = 0;

  /** Number of rows in batch in {@link #statementSent}. */
  private int batchSizeSent = 0;

  /**
   * Default constructor.
   * 
   * @param connectionInfo connection information
   * 
   * @throws DbException if any error occurs
   */
  public ProfilingLogger(final ConnectionInfo connectionInfo) throws DbException {
    Preconditions.checkArgument(connectionInfo.getDbms().equals(MyriaConstants.STORAGE_SYSTEM_POSTGRESQL),
        "Profiling only supported with Postgres JDBC connection");

    /* open the database connection */
    accessMethod = (JdbcAccessMethod) AccessMethod.of(connectionInfo.getDbms(), connectionInfo, false);

    accessMethod.createTableIfNotExists(MyriaConstants.PROFILING_RELATION, MyriaConstants.PROFILING_SCHEMA);
    accessMethod.createTableIfNotExists(MyriaConstants.SENT_RELATION, MyriaConstants.SENT_SCHEMA);

    createProfilingIndexes();
    createSentIndex();

    connection = accessMethod.getConnection();
    try {
      statementEvent =
          connection.prepareStatement(accessMethod.insertStatementFromSchema(MyriaConstants.PROFILING_SCHEMA,
              MyriaConstants.PROFILING_RELATION));
    } catch (SQLException e) {
      throw new DbException(e);
    }

    try {
      statementSent =
          connection.prepareStatement(accessMethod.insertStatementFromSchema(MyriaConstants.SENT_SCHEMA,
              MyriaConstants.SENT_RELATION));
    } catch (SQLException e) {
      throw new DbException(e);
    }

  }

  /**
   * @throws DbException if index cannot be created
   */
  protected void createSentIndex() throws DbException {
    final Schema schema = MyriaConstants.SENT_SCHEMA;<commit_msg>Create profiling relation as unlogged table to see how much this affects the performance. <commit_after>package edu.washington.escience.myria.profiling;

import java.sql.BatchUpdateException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
import java.util.concurrent.TimeUnit;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;

import edu.washington.escience.myria.DbException;
import edu.washington.escience.myria.MyriaConstants;
import edu.washington.escience.myria.Schema;
import edu.washington.escience.myria.accessmethod.AccessMethod;
import edu.washington.escience.myria.accessmethod.AccessMethod.IndexRef;
import edu.washington.escience.myria.accessmethod.ConnectionInfo;
import edu.washington.escience.myria.accessmethod.JdbcAccessMethod;
import edu.washington.escience.myria.operator.Operator;
import edu.washington.escience.myria.parallel.WorkerSubQuery;

/**
 * A logger for profiling data.
 */
public class ProfilingLogger {
  /** The logger for this class. */
  private static final org.slf4j.Logger LOGGER = org.slf4j.LoggerFactory.getLogger(ProfilingLogger.class);

  /** The connection to the database database. */
  private final JdbcAccessMethod accessMethod;

  /** The jdbc connection. */
  private final Connection connection;

  /** A query statement for batching. */
  private PreparedStatement statementEvent;

  /** A query statement for batching. */
  private PreparedStatement statementSent;

  /** Number of rows in batch in {@link #statementEvent}. */
  private int batchSizeEvents = 0;

  /** Number of rows in batch in {@link #statementSent}. */
  private int batchSizeSent = 0;

  /**
   * Default constructor.
   * 
   * @param connectionInfo connection information
   * 
   * @throws DbException if any error occurs
   */
  public ProfilingLogger(final ConnectionInfo connectionInfo) throws DbException {
    Preconditions.checkArgument(connectionInfo.getDbms().equals(MyriaConstants.STORAGE_SYSTEM_POSTGRESQL),
        "Profiling only supported with Postgres JDBC connection");

    /* open the database connection */
    accessMethod = (JdbcAccessMethod) AccessMethod.of(connectionInfo.getDbms(), connectionInfo, false);

    accessMethod.createUnloggedTableIfNotExists(MyriaConstants.PROFILING_RELATION, MyriaConstants.PROFILING_SCHEMA);
    accessMethod.createTableIfNotExists(MyriaConstants.SENT_RELATION, MyriaConstants.SENT_SCHEMA);

    createProfilingIndexes();
    createSentIndex();

    connection = accessMethod.getConnection();
    try {
      statementEvent =
          connection.prepareStatement(accessMethod.insertStatementFromSchema(MyriaConstants.PROFILING_SCHEMA,
              MyriaConstants.PROFILING_RELATION));
    } catch (SQLException e) {
      throw new DbException(e);
    }

    try {
      statementSent =
          connection.prepareStatement(accessMethod.insertStatementFromSchema(MyriaConstants.SENT_SCHEMA,
              MyriaConstants.SENT_RELATION));
    } catch (SQLException e) {
      throw new DbException(e);
    }

  }

  /**
   * @throws DbException if index cannot be created
   */
  protected void createSentIndex() throws DbException {
    final Schema schema = MyriaConstants.SENT_SCHEMA;
{'fraction_non_alphanumeric': 0.08961900354774024, 'fraction_numerical': 0.0012339966065093321, 'mean_word_length': 4.421404682274248, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6271790', 'n_tokens_mistral': 1897, 'n_tokens_neox': 1820, 'n_words': 397}