




"""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								=						datasets.utils.logging.get_logger(__name__)

@dataclass
class    A_     (					datasets.BuilderConfig       ):



							"""simple docstring"""






							SCREAMING_SNAKE_CASE_     				=       None
							SCREAMING_SNAKE_CASE_     				=       None
							SCREAMING_SNAKE_CASE_     				=       None
							SCREAMING_SNAKE_CASE_     				=       True
							SCREAMING_SNAKE_CASE_     				=       None
							SCREAMING_SNAKE_CASE_     				=       None
							SCREAMING_SNAKE_CASE_     				=       None
							SCREAMING_SNAKE_CASE_     				=       10_000
							SCREAMING_SNAKE_CASE_     				=       None





							def 				UpperCAmelCase__							(  self  :Optional[int]	):





										"""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  :Union[str, Any]					,							lowerCamelCase_  :dict					,							lowerCamelCase_  :Optional[datasets.Features] = None					,							):





										"""simple docstring"""

										lowerCamelCase__     :					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
										lowerCamelCase__     :					Any		=config_kwargs['sql']
										if not isinstance(lowerCamelCase_					,							lowerCamelCase_	):
													if datasets.config.SQLALCHEMY_AVAILABLE and "sqlalchemy" in sys.modules:
																import sqlalchemy

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

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





							@property
							def 				UpperCAmelCase__							(  self  :Union[str, Any]	):





										"""simple docstring"""

										lowerCamelCase__     :					Optional[int]		={
										    '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    A_     (					datasets.ArrowBasedBuilder       ):



							"""simple docstring"""






							SCREAMING_SNAKE_CASE_     				=       SqlConfig





							def 				UpperCAmelCase__							(  self  :Dict	):





										"""simple docstring"""

										return datasets.DatasetInfo(features=self.config.features	)





							def 				UpperCAmelCase__							(  self  :Optional[int]					,							lowerCamelCase_  :Tuple	):





										"""simple docstring"""

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





							def 				UpperCAmelCase__							(  self  :Tuple					,							lowerCamelCase_  :pa.Table	):





										"""simple docstring"""

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





							def 				UpperCAmelCase__							(  self  :Union[str, Any]	):





										"""simple docstring"""

										lowerCamelCase__     :					int		=self.config.chunksize
										lowerCamelCase__     :					Tuple		=pd.read_sql(
										    self.config.sql					,							self.config.con					,							chunksize=lowerCamelCase_					,							**self.config.pd_read_sql_kwargs	)
										lowerCamelCase__     :					Dict		=[sql_reader] if chunksize is None else sql_reader
										for chunk_idx, df in enumerate(lowerCamelCase_	):
													lowerCamelCase__     :					List[str]		=pa.Table.from_pandas(lowerCamelCase_	)
													yield chunk_idx, self._cast_table(lowerCamelCase_	)

"""simple docstring"""


from typing import TYPE_CHECKING

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


lowerCAmelCase								=						{
    """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								=						["""DebertaV2TokenizerFast"""]

try:
							if not is_tf_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							lowerCAmelCase								=						[
							    """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								=						[
							    """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								=						_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)