blob: 80e8af7520a09f8b604a8692b3d8f0abb9fc289e [file] [log] [blame]
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# The purpose of this module is to unify a place to settle DB differences in addition to
# differences based on DB API2 libraries (like Impyla vs. psycopg2). Putting the
# handling in a single place will make it easier to track what workarounds exist.
from tests.comparison import db_connection
def setup_ref_database(ref_conn):
"""Set up reference database at query generator runtime.
Because runs are expensive operations, and reference databases tend
to persist across runs, this method should support lightweight options to configure
reference databases as needed, regardless of whether the data is loaded or not. A good
example is loading optional PostgreSQL modules to support comparison with functions
added to Impala.
ref_conn: Open db_connection.DbConnection object. Method assumes no open cursors on
open connection object. Method will close any cursors opened, and leave connection
if ref_conn.db_type == db_connection.POSTGRESQL:
# IMPALA-7759: The Levenshtein function needs the fuzzystrmatch extension.
# References:
# On Ubuntu 16, postgresql-contrib-9.5 provides fuzzystrmatch and is installed as
# part of Impala's bin/
with ref_conn.cursor() as cursor:
cursor.execute('CREATE EXTENSION IF NOT EXISTS fuzzystrmatch')