# Path: impala/interface.py
# def _bind_parameters(operation, parameters, paramstyle=None):
#     # If parameters is a list, assume either qmark, format, or numeric
#     # format. If not, assume either named or pyformat parameters
#     if isinstance(parameters, (list, tuple)):
#         return _bind_parameters_list(operation, parameters, paramstyle)
#     elif isinstance(parameters, dict):
#         return _bind_parameters_dict(operation, parameters)
#     else:
#         raise ProgrammingError("Query parameters argument should be a "
#                                "list, tuple, or dict object")
# 
# Path: impala/dbapi.py
# AUTH_MECHANISMS = ['NOSASL', 'PLAIN', 'GSSAPI', 'LDAP', 'JWT']
# STRING = _DBAPITypeObject('STRING')
# BINARY = _DBAPITypeObject('BINARY')
# NUMBER = _DBAPITypeObject('BOOLEAN', 'TINYINT', 'SMALLINT', 'INT', 'BIGINT',
#                           'FLOAT', 'DOUBLE', 'DECIMAL')
# DATETIME = _DBAPITypeObject('TIMESTAMP')
# DATE = _DBAPITypeObject('DATE')
# ROWID = _DBAPITypeObject()
# def connect(host='localhost', port=21050, database=None, timeout=None,
#             use_ssl=False, ca_cert=None, auth_mechanism='NOSASL', user=None,
#             password=None, kerberos_service_name='impala', use_ldap=None,
#             ldap_user=None, ldap_password=None, use_kerberos=None,
#             protocol=None, krb_host=None, use_http_transport=False,
#             http_path='', auth_cookie_names=None, http_cookie_names=None,
#             retries=3, jwt=None):
#     def __init__(self, *values):
#     def __cmp__(self, other):
#     def __eq__(self, other):
# def DateFromTicks(ticks):
# def TimeFromTicks(ticks):
# def TimestampFromTicks(ticks):
# class _DBAPITypeObject(object):


from pytest import raises
from impala.interface import _bind_parameters
from impala.dbapi import ProgrammingError
    import datetime
  dt("select * from test where a='string :2 ? %s :named' and b='42'",
      "select * from test where a=:1 and b=:2",
     ['string :2 ? %s :named', '42'], paramstyle='numeric')

  # BUG: %s picks up named parameters as stringified dict when dict is passed.
  dt('select ?, {\'x\': "\'string\'"}, :1 from test where a=\'string\'',
     "select ?, %s, :1 from test where a=:x",
     {'x': 'string'}, paramstyle='named')
  dt("select * from test where a='string :2 ? %s :named' and b='42'",
      "select * from test where a=:x and b=:y",
      {'x': 'string :2 ? %s :named', 'y':'42'}, paramstyle='named')

  # BUG: if a parameter is substituted with a string containing another parameter
  # specifier, double substitution can occur.
  dt("select * from test where a='string '42'' and b='42'",
     "select * from test where a=%s and b=%s",
     ['string :2', '42'])

def test_date_type():
    today = datetime.date(2016, 5, 7)
    query = 'select %(today)s'
    dt("select '2016-05-07'", query, {'today': today})

    today = datetime.datetime(2016, 5, 7, 12, 0)
    query = 'select %(today)s'
    dt("select '2016-05-07 12:00:00'", query, {'today': today})


def test_bad_argument_type():
    with raises(ProgrammingError):

# Path: impala/interface.py
# def _bind_parameters(operation, parameters, paramstyle=None):
#     # If parameters is a list, assume either qmark, format, or numeric
#     # format. If not, assume either named or pyformat parameters
#     if isinstance(parameters, (list, tuple)):
#         return _bind_parameters_list(operation, parameters, paramstyle)
#     elif isinstance(parameters, dict):
#         return _bind_parameters_dict(operation, parameters)
#     else:
#         raise ProgrammingError("Query parameters argument should be a "
#                                "list, tuple, or dict object")
# 
# Path: impala/dbapi.py
# AUTH_MECHANISMS = ['NOSASL', 'PLAIN', 'GSSAPI', 'LDAP', 'JWT']
# STRING = _DBAPITypeObject('STRING')
# BINARY = _DBAPITypeObject('BINARY')
# NUMBER = _DBAPITypeObject('BOOLEAN', 'TINYINT', 'SMALLINT', 'INT', 'BIGINT',
#                           'FLOAT', 'DOUBLE', 'DECIMAL')
# DATETIME = _DBAPITypeObject('TIMESTAMP')
# DATE = _DBAPITypeObject('DATE')
# ROWID = _DBAPITypeObject()
# def connect(host='localhost', port=21050, database=None, timeout=None,
#             use_ssl=False, ca_cert=None, auth_mechanism='NOSASL', user=None,
#             password=None, kerberos_service_name='impala', use_ldap=None,
#             ldap_user=None, ldap_password=None, use_kerberos=None,
#             protocol=None, krb_host=None, use_http_transport=False,
#             http_path='', auth_cookie_names=None, http_cookie_names=None,
#             retries=3, jwt=None):
#     def __init__(self, *values):
#     def __cmp__(self, other):
#     def __eq__(self, other):
# def DateFromTicks(ticks):
# def TimeFromTicks(ticks):
# def TimestampFromTicks(ticks):
# class _DBAPITypeObject(object):


# Path: impala/tests/test_query_parameters.py
from pytest import raises
from impala.interface import _bind_parameters
from impala.dbapi import ProgrammingError
    import datetime

  dt("select * from test where a='string :2 ? %s :named' and b='42'",
      "select * from test where a=:1 and b=:2",
     ['string :2 ? %s :named', '42'], paramstyle='numeric')

  # BUG: %s picks up named parameters as stringified dict when dict is passed.
  dt('select ?, {\'x\': "\'string\'"}, :1 from test where a=\'string\'',
     "select ?, %s, :1 from test where a=:x",
     {'x': 'string'}, paramstyle='named')
  dt("select * from test where a='string :2 ? %s :named' and b='42'",
      "select * from test where a=:x and b=:y",
      {'x': 'string :2 ? %s :named', 'y':'42'}, paramstyle='named')

  # BUG: if a parameter is substituted with a string containing another parameter
  # specifier, double substitution can occur.
  dt("select * from test where a='string '42'' and b='42'",
     "select * from test where a=%s and b=%s",
     ['string :2', '42'])

def test_date_type():
    today = datetime.date(2016, 5, 7)
    query = 'select %(today)s'
    dt("select '2016-05-07'", query, {'today': today})

    today = datetime.datetime(2016, 5, 7, 12, 0)
    query = 'select %(today)s'
    dt("select '2016-05-07 12:00:00'", query, {'today': today})


def test_bad_argument_type():
    with raises(ProgrammingError):

        _bind_parameters("select * from test", 1)