<commit_before># Copyright (c) 2014 Cloudera, Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import uuid
from functools import wraps
from impala.dbapi import connect as impala_connect
from tests.util.calculation_util import get_random_id

LOG = logging.getLogger(__name__)

class PerfResultDataStore(object):
  '''Allows for interaction with the performance Impala database.

  In order to reduce the number of calls to the database we cache query_id, workload_id,
  file_type_id and run_info_id in _cache. If an id cannot be found in the cache, we make a
  request to the database. Objects not in the database will be automatically inserted.

  In order to avoid creating a new file per query, we create a staging table for execution
  results and query profiles. When all results have been inserted, we insert the data from
  the staging tables into ExecutionResults and RuntimeProfiles. This way, we create on the
  order of 1 parquet file per run.'''

  def __init__(self, host, port, database_name):
    self._connection = impala_connect(host, port)
    self._database_name = database_name
    self._staging_exec_result_table = None
    self._staging_profile_table = None
    self._cache = {}

  def __enter__(self):
    self._staging_exec_result_table = 'ExecutionResultsStaging_' + get_random_id(5)
    self._staging_profile_table = 'RuntimeProfilesStaging_' + get_random_id(5)
    self._create_new_table_as('ExecutionResults', self._staging_exec_result_table)
    self._create_new_table_as('RuntimeProfiles', self._staging_profile_table)
    return self

  def __exit__(self, type, value, traceback):
    self._copy_to_table(self._staging_exec_result_table, 'ExecutionResults')
    self._copy_to_table(self._staging_profile_table, 'RuntimeProfiles')
    self._drop_table(self._staging_exec_result_table)
    self._drop_table(self._staging_profile_table)

  def insert_execution_result(self,<commit_msg>Upload benchmarks using SSL and kerberos<commit_after># Copyright (c) 2014 Cloudera, Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import uuid
from functools import wraps
from impala.dbapi import connect as impala_connect
from tests.util.calculation_util import get_random_id

LOG = logging.getLogger(__name__)

class PerfResultDataStore(object):
  '''Allows for interaction with the performance Impala database.

  In order to reduce the number of calls to the database we cache query_id, workload_id,
  file_type_id and run_info_id in _cache. If an id cannot be found in the cache, we make a
  request to the database. Objects not in the database will be automatically inserted.

  In order to avoid creating a new file per query, we create a staging table for execution
  results and query profiles. When all results have been inserted, we insert the data from
  the staging tables into ExecutionResults and RuntimeProfiles. This way, we create on the
  order of 1 parquet file per run.'''

  def __init__(self, host, port, database_name):
    self._connection = impala_connect(host, port, use_ssl=True, auth_mechanism='GSSAPI')
    self._database_name = database_name
    self._staging_exec_result_table = None
    self._staging_profile_table = None
    self._cache = {}

  def __enter__(self):
    self._staging_exec_result_table = 'ExecutionResultsStaging_' + get_random_id(5)
    self._staging_profile_table = 'RuntimeProfilesStaging_' + get_random_id(5)
    self._create_new_table_as('ExecutionResults', self._staging_exec_result_table)
    self._create_new_table_as('RuntimeProfiles', self._staging_profile_table)
    return self

  def __exit__(self, type, value, traceback):
    self._copy_to_table(self._staging_exec_result_table, 'ExecutionResults')
    self._copy_to_table(self._staging_profile_table, 'RuntimeProfiles')
    self._drop_table(self._staging_exec_result_table)
    self._drop_table(self._staging_profile_table)

  def insert_execution_result(self,
{'fraction_non_alphanumeric': 0.06411290322580646, 'fraction_numerical': 0.004435483870967742, 'mean_word_length': 4.97710843373494, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1070759', 'n_tokens_mistral': 1429, 'n_tokens_neox': 1391, 'n_words': 520}