





"""simple docstring"""
import sys
from dataclasses import dataclass
from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, Union

import pandas as pd
import pyarrow as pa

import datasets
import datasets.config
from datasets.features.features import require_storage_cast
from datasets.table import table_cast


if TYPE_CHECKING:
   import sqlitea

   import sqlalchemy


lowerCAmelCase:	Tuple							      =datasets.utils.logging.get_logger(__name__)
@dataclass
class lowerCamelCase__  (    datasets.BuilderConfig				):
   __UpperCAmelCase        =					None
   __UpperCAmelCase        =					None
   __UpperCAmelCase        =					None
   __UpperCAmelCase        =					True
   __UpperCAmelCase        =					None
   __UpperCAmelCase        =					None
   __UpperCAmelCase        =					None
   __UpperCAmelCase        =					10000
   __UpperCAmelCase        =					None



   def    _UpperCAmelCase	(       self	) ->    str:







      """simple docstring"""
      if self.sql is None:
         raise ValueError("""sql must be specified"""	)
      if self.con is None:
         raise ValueError("""con must be specified"""	)



   def    _UpperCAmelCase	(       self      ,   snake_case      ,   snake_case = None      ,   ) ->    str:







      """simple docstring"""
      lowercase    :			Union[str, Any]  =       config_kwargs.copy()
      # We need to stringify the Selectable object to make its hash deterministic

      # The process of stringifying is explained here: http://docs.sqlalchemy.org/en/latest/faq/sqlexpressions.html
      lowercase    :			Union[str, Any]  =       config_kwargs["""sql"""]
      if not isinstance(snake_case      ,   snake_case	):
         if datasets.config.SQLALCHEMY_AVAILABLE and "sqlalchemy" in sys.modules:
            import sqlalchemy

            if isinstance(snake_case      ,   sqlalchemy.sql.Selectable	):
               lowercase    :			List[str]  =       sqlalchemy.create_engine(config_kwargs["""con"""].split("""://"""	)[0] + """://"""	)
               lowercase    :			Optional[Any]  =       str(sql.compile(dialect=engine.dialect	)	)
               lowercase    :			Union[str, Any]  =       sql_str
            else:
               raise TypeError(
                   f'''Supported types for \'sql\' are string and sqlalchemy.sql.Selectable but got {type(snake_case	)}: {sql}'''	)
         else:
            raise TypeError(
                f'''Supported types for \'sql\' are string and sqlalchemy.sql.Selectable but got {type(snake_case	)}: {sql}'''	)
      lowercase    :			Union[str, Any]  =       config_kwargs["""con"""]
      if not isinstance(snake_case      ,   snake_case	):
         lowercase    :			List[str]  =       id(snake_case	)
         logger.info(
             f'''SQL connection \'con\' of type {type(snake_case	)} couldn\'t be hashed properly. To enable hashing, specify \'con\' as URI string instead.'''	)

      return super().create_config_id(snake_case      ,   custom_features=snake_case	)





   @property
   def    _UpperCAmelCase	(       self	) ->    Optional[int]:







      """simple docstring"""
      lowercase    :			Tuple  =       {
          """index_col""": self.index_col,
          """columns""": self.columns,
          """params""": self.params,
          """coerce_float""": self.coerce_float,
          """parse_dates""": self.parse_dates,
      }
      return pd_read_sql_kwargs




class lowerCamelCase__  (    datasets.ArrowBasedBuilder				):
   __UpperCAmelCase        =					SqlConfig



   def    _UpperCAmelCase	(       self	) ->    str:







      """simple docstring"""
      return datasets.DatasetInfo(features=self.config.features	)



   def    _UpperCAmelCase	(       self      ,   snake_case	) ->    int:







      """simple docstring"""
      return [datasets.SplitGenerator(name=datasets.Split.TRAIN      ,   gen_kwargs={}	)]



   def    _UpperCAmelCase	(       self      ,   snake_case	) ->    pa.Table:







      """simple docstring"""
      if self.config.features is not None:
         lowercase    :			Optional[int]  =       self.config.features.arrow_schema
         if all(not require_storage_cast(snake_case	) for feature in self.config.features.values()	):
            # cheaper cast
            lowercase    :			str  =       pa.Table.from_arrays([pa_table[field.name] for field in schema]      ,   schema=snake_case	)
         else:
            # more expensive cast; allows str <-> int/float or str to Audio for example
            lowercase    :			int  =       table_cast(snake_case      ,   snake_case	)
      return pa_table





   def    _UpperCAmelCase	(       self	) ->    str:







      """simple docstring"""
      lowercase    :			int  =       self.config.chunksize
      lowercase    :			Dict  =       pd.read_sql(
          self.config.sql      ,   self.config.con      ,   chunksize=snake_case      ,   **self.config.pd_read_sql_kwargs	)
      lowercase    :			str  =       [sql_reader] if chunksize is None else sql_reader
      for chunk_idx, df in enumerate(snake_case	):
         lowercase    :			Optional[Any]  =       pa.Table.from_pandas(snake_case	)
         yield chunk_idx, self._cast_table(snake_case	)









"""simple docstring"""
from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


lowerCAmelCase:	Union[str, Any]							      ={
    "configuration_deberta_v2": ["DEBERTA_V2_PRETRAINED_CONFIG_ARCHIVE_MAP", "DebertaV2Config", "DebertaV2OnnxConfig"],
    "tokenization_deberta_v2": ["DebertaV2Tokenizer"],
}

try:
   if not is_tokenizers_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   lowerCAmelCase:	Dict							      =["DebertaV2TokenizerFast"]

try:
   if not is_tf_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   lowerCAmelCase:	Optional[Any]							      =[
       "TF_DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST",
       "TFDebertaV2ForMaskedLM",
       "TFDebertaV2ForQuestionAnswering",
       "TFDebertaV2ForSequenceClassification",
       "TFDebertaV2ForTokenClassification",
       "TFDebertaV2Model",
       "TFDebertaV2PreTrainedModel",
   ]

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   lowerCAmelCase:	str							      =[
       "DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST",
       "DebertaV2ForMaskedLM",
       "DebertaV2ForMultipleChoice",
       "DebertaV2ForQuestionAnswering",
       "DebertaV2ForSequenceClassification",
       "DebertaV2ForTokenClassification",
       "DebertaV2Model",
       "DebertaV2PreTrainedModel",
   ]


if TYPE_CHECKING:
   from .configuration_deberta_va import (
       DEBERTA_V2_PRETRAINED_CONFIG_ARCHIVE_MAP,
       DebertaVaConfig,
       DebertaVaOnnxConfig,
   )
   from .tokenization_deberta_va import DebertaVaTokenizer

   try:
      if not is_tokenizers_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .tokenization_deberta_va_fast import DebertaVaTokenizerFast

   try:
      if not is_tf_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_tf_deberta_va import (
          TF_DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST,
          TFDebertaVaForMaskedLM,
          TFDebertaVaForQuestionAnswering,
          TFDebertaVaForSequenceClassification,
          TFDebertaVaForTokenClassification,
          TFDebertaVaModel,
          TFDebertaVaPreTrainedModel,
      )

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_deberta_va import (
          DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST,
          DebertaVaForMaskedLM,
          DebertaVaForMultipleChoice,
          DebertaVaForQuestionAnswering,
          DebertaVaForSequenceClassification,
          DebertaVaForTokenClassification,
          DebertaVaModel,
          DebertaVaPreTrainedModel,
      )

else:
   import sys

   lowerCAmelCase:	Optional[Any]							      =_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)


