




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


__a  :		List[Any]		     =   datasets.utils.logging.get_logger(__name__)







@dataclass
class 				UpperCAmelCase(					datasets.BuilderConfig					):



	"""simple docstring"""






	a     : Union[str, "sqlalchemy.sql.Selectable"]	  =					None
	a     : Union[str, "sqlalchemy.engine.Connection", "sqlalchemy.engine.Engine", "sqlite3.Connection"]	  =					None
	a     : Optional[Union[str, List[str]]]	  =					None
	a     : bool	  =					True
	a     : Optional[Union[List, Tuple, Dict]]	  =					None
	a     : Optional[Union[List, Dict]]	  =					None
	a     : Optional[List[str]]	  =					None
	a     : Optional[int]	  =					1_0_0_0_0
	a     : Optional[datasets.Features]	  =					None

	def    __a     (					self    ) ->      Optional[Any]:





								"""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    __a     (					self	,				lowerCamelCase	,				lowerCamelCase = None	,				) ->      str:





								"""simple docstring"""


								lowercase__  :	Tuple        =							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__  :	int        =							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    ):
																													lowercase__  :	Any        =							sqlalchemy.create_engine(config_kwargs["con"].split("://"    )[0] + "://"    )
																													lowercase__  :	int        =							str(sql.compile(dialect=engine.dialect    )    )
																													lowercase__  :	int        =							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}"""    )
								lowercase__  :	Optional[int]        =							config_kwargs["con"]
								if not isinstance(lowerCamelCase	,				lowerCamelCase    ):
															lowercase__  :	Dict        =							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    __a     (					self    ) ->      List[str]:





								"""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 				UpperCAmelCase(					datasets.ArrowBasedBuilder					):



	"""simple docstring"""






	a     : Dict	  =					SqlConfig

	def    __a     (					self    ) ->      Optional[int]:





								"""simple docstring"""


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

	def    __a     (					self	,				lowerCamelCase    ) ->      List[Any]:





								"""simple docstring"""


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

	def    __a     (					self	,				lowerCamelCase    ) ->      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(lowerCamelCase    ) for feature in self.config.features.values()    ):
																						# cheaper cast
																						lowercase__  :	Union[str, Any]        =							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
																						lowercase__  :	str        =							table_cast(lowerCamelCase	,				lowerCamelCase    )
								return pa_table







	def    __a     (					self    ) ->      Optional[int]:





								"""simple docstring"""


								lowercase__  :	Optional[int]        =							self.config.chunksize
								lowercase__  :	int        =							pd.read_sql(
								    self.config.sql	,				self.config.con	,				chunksize=lowerCamelCase	,				**self.config.pd_read_sql_kwargs    )
								lowercase__  :	List[Any]        =							[sql_reader] if chunksize is None else sql_reader
								for chunk_idx, df in enumerate(lowerCamelCase    ):
															lowercase__  :	Any        =							pa.Table.from_pandas(lowerCamelCase    )
															yield chunk_idx, self._cast_table(lowerCamelCase    )





import os
from shutil import copyfile
from typing import Optional, Tuple

from ...file_utils import is_sentencepiece_available
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging


if is_sentencepiece_available():
						from .tokenization_deberta_va import DebertaVaTokenizer
else:
						__a  :		Optional[Any]		     =   None

__a  :		List[str]		     =   logging.get_logger(__name__)

__a  :		Dict		     =   {'''vocab_file''': '''spm.model''', '''tokenizer_file''': '''tokenizer.json'''}

__a  :		int		     =   {
    '''vocab_file''': {
        '''microsoft/deberta-v2-xlarge''': '''https://huggingface.co/microsoft/deberta-v2-xlarge/resolve/main/spm.model''',
        '''microsoft/deberta-v2-xxlarge''': '''https://huggingface.co/microsoft/deberta-v2-xxlarge/resolve/main/spm.model''',
        '''microsoft/deberta-v2-xlarge-mnli''': (
            '''https://huggingface.co/microsoft/deberta-v2-xlarge-mnli/resolve/main/spm.model'''
        ),
        '''microsoft/deberta-v2-xxlarge-mnli''': (
            '''https://huggingface.co/microsoft/deberta-v2-xxlarge-mnli/resolve/main/spm.model'''
        ),
    }
}

__a  :		Any		     =   {
    '''microsoft/deberta-v2-xlarge''': 5_1_2,
    '''microsoft/deberta-v2-xxlarge''': 5_1_2,
    '''microsoft/deberta-v2-xlarge-mnli''': 5_1_2,
    '''microsoft/deberta-v2-xxlarge-mnli''': 5_1_2,
}

__a  :		Union[str, Any]		     =   {
    '''microsoft/deberta-v2-xlarge''': {'''do_lower_case''': False},
    '''microsoft/deberta-v2-xxlarge''': {'''do_lower_case''': False},
    '''microsoft/deberta-v2-xlarge-mnli''': {'''do_lower_case''': False},
    '''microsoft/deberta-v2-xxlarge-mnli''': {'''do_lower_case''': False},
}







class 				UpperCAmelCase(					snake_case_					):



	"""simple docstring"""






	a     : List[Any]	  =					VOCAB_FILES_NAMES
	a     : Optional[int]	  =					PRETRAINED_VOCAB_FILES_MAP
	a     : int	  =					PRETRAINED_INIT_CONFIGURATION
	a     : List[str]	  =					PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
	a     : int	  =					DebertaVaTokenizer

	def __init__(					self	,				lowerCamelCase=None	,				lowerCamelCase=None	,				lowerCamelCase=False	,				lowerCamelCase=False	,				lowerCamelCase="[CLS]"	,				lowerCamelCase="[SEP]"	,				lowerCamelCase="[UNK]"	,				lowerCamelCase="[SEP]"	,				lowerCamelCase="[PAD]"	,				lowerCamelCase="[CLS]"	,				lowerCamelCase="[MASK]"	,				**lowerCamelCase	,				) ->      None:





								"""simple docstring"""


								super().__init__(
								    lowerCamelCase	,				tokenizer_file=lowerCamelCase	,				do_lower_case=lowerCamelCase	,				bos_token=lowerCamelCase	,				eos_token=lowerCamelCase	,				unk_token=lowerCamelCase	,				sep_token=lowerCamelCase	,				pad_token=lowerCamelCase	,				cls_token=lowerCamelCase	,				mask_token=lowerCamelCase	,				split_by_punct=lowerCamelCase	,				**lowerCamelCase	,				)

								lowercase__  :	Optional[int]        =							do_lower_case
								lowercase__  :	Optional[Any]        =							split_by_punct
								lowercase__  :	Tuple        =							vocab_file
								lowercase__  :	Optional[int]        =							False if not self.vocab_file else True

	def    __a     (					self	,				lowerCamelCase	,				lowerCamelCase=None    ) ->      List[Any]:





								"""simple docstring"""


								if token_ids_a is None:
															return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
								lowercase__  :	Union[str, Any]        =							[self.cls_token_id]
								lowercase__  :	Union[str, Any]        =							[self.sep_token_id]
								return cls + token_ids_a + sep + token_ids_a + sep

	def    __a     (					self	,				lowerCamelCase	,				lowerCamelCase=None	,				lowerCamelCase=False    ) ->      Union[str, Any]:





								"""simple docstring"""


								if already_has_special_tokens:
															return super().get_special_tokens_mask(
															    token_ids_a=lowerCamelCase	,				token_ids_a=lowerCamelCase	,				already_has_special_tokens=lowerCamelCase    )

								if token_ids_a is not None:
															return [1] + ([0] * len(lowerCamelCase    )) + [1] + ([0] * len(lowerCamelCase    )) + [1]
								return [1] + ([0] * len(lowerCamelCase    )) + [1]

	def    __a     (					self	,				lowerCamelCase	,				lowerCamelCase=None    ) ->      Optional[int]:





								"""simple docstring"""


								lowercase__  :	Any        =							[self.sep_token_id]
								lowercase__  :	List[str]        =							[self.cls_token_id]
								if token_ids_a is None:
															return len(cls + token_ids_a + sep    ) * [0]
								return len(cls + token_ids_a + sep    ) * [0] + len(token_ids_a + sep    ) * [1]







	def    __a     (					self	,				lowerCamelCase	,				lowerCamelCase = None    ) ->      Tuple[str]:





								"""simple docstring"""


								if not self.can_save_slow_tokenizer:
															raise ValueError(
															    "Your fast tokenizer does not have the necessary information to save the vocabulary for a slow "
															    "tokenizer."    )

								if not os.path.isdir(lowerCamelCase    ):
															logger.error(f"""Vocabulary path ({save_directory}) should be a directory"""    )
															return
								lowercase__  :	int        =							os.path.join(
								    lowerCamelCase	,				(filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]    )

								if os.path.abspath(self.vocab_file    ) != os.path.abspath(lowerCamelCase    ):
															copyfile(self.vocab_file	,				lowerCamelCase    )

								return (out_vocab_file,)