





import multiprocessing
from typing import TYPE_CHECKING, Optional, Union

from .. import Dataset, Features, config
from ..formatting import query_table
from ..packaged_modules.sql.sql import Sql
from ..utils import logging
from .abc import AbstractDatasetInputStream


if TYPE_CHECKING:
    import sqlitea

    import sqlalchemy



class       A__     ( __snake_case    ):





      def __init__(				self ,							A_ ,							A_ ,							A_ = None ,							A_ = None ,							A_ = False ,							**A_ ,							):
       '''simple docstring'''




       super().__init__(features=A_ ,							cache_dir=A_ ,							keep_in_memory=A_ ,							**A_     )
       UpperCamelCase			:      List[Any] 			=     Sql(
           cache_dir=A_ ,							features=A_ ,							sql=A_ ,							con=A_ ,							**A_ ,							)





      def  __UpperCamelCase(				self     ):
       '''simple docstring'''




       UpperCamelCase			:      Optional[int] 			=     None
       UpperCamelCase			:      List[Any] 			=     None
       UpperCamelCase			:      Union[str, Any] 			=     None
       UpperCamelCase			:      Tuple 			=     None

       self.builder.download_and_prepare(
           download_config=A_ ,							download_mode=A_ ,							verification_mode=A_ ,							base_path=A_ ,							)

       # Build dataset for splits
       UpperCamelCase			:      Dict 			=     self.builder.as_dataset(
           split="train" ,							verification_mode=A_ ,							in_memory=self.keep_in_memory     )
       return dataset



class       A__     :





      def __init__(				self ,							A_ ,							A_ ,							A_ ,							A_ = None ,							A_ = None ,							**A_ ,							):
       '''simple docstring'''




       if num_proc is not None and num_proc <= 0:
        raise ValueError(F"""num_proc {num_proc} must be an integer > 0."""     )

       UpperCamelCase			:      Dict 			=     dataset
       UpperCamelCase			:      List[Any] 			=     name
       UpperCamelCase			:      Tuple 			=     con
       UpperCamelCase			:      Any 			=     batch_size if batch_size else config.DEFAULT_MAX_BATCH_SIZE
       UpperCamelCase			:      Dict 			=     num_proc
       UpperCamelCase			:      str 			=     to_sql_kwargs





      def  __UpperCamelCase(				self     ):
       '''simple docstring'''




       UpperCamelCase			:      int 			=     self.to_sql_kwargs.pop("sql" ,							A_     )
       UpperCamelCase			:      int 			=     self.to_sql_kwargs.pop("con" ,							A_     )
       UpperCamelCase			:      Union[str, Any] 			=     self.to_sql_kwargs.pop("index" ,							A_     )

       UpperCamelCase			:      List[Any] 			=     self._write(index=A_ ,							**self.to_sql_kwargs     )
       return written





      def  __UpperCamelCase(				self ,							A_     ):
       '''simple docstring'''




       UpperCamelCase			,					UpperCamelCase			,					UpperCamelCase			:      List[str] 			=     args
       UpperCamelCase			:      List[str] 			=     {**to_sql_kwargs, "if_exists": "append"} if offset > 0 else to_sql_kwargs
       UpperCamelCase			:      Tuple 			=     query_table(
           table=self.dataset.data ,							key=slice(A_ ,							offset + self.batch_size     ) ,							indices=self.dataset._indices ,							)
       UpperCamelCase			:      Union[str, Any] 			=     batch.to_pandas()
       UpperCamelCase			:      str 			=     df.to_sql(self.name ,							self.con ,							index=A_ ,							**A_     )
       return num_rows or len(A_     )





      def  __UpperCamelCase(				self ,							A_ ,							**A_     ):
       '''simple docstring'''




       UpperCamelCase			:      Optional[Any] 			=     0

       if self.num_proc is None or self.num_proc == 1:
        for offset in logging.tqdm(
            range(0 ,							len(self.dataset     ) ,							self.batch_size     ) ,							unit="ba" ,							disable=not logging.is_progress_bar_enabled() ,							desc="Creating SQL from Arrow format" ,							):
         written += self._batch_sql((offset, index, to_sql_kwargs)     )
       else:
        UpperCamelCase			,					UpperCamelCase			:      List[str] 			=     len(self.dataset     ), self.batch_size
        with multiprocessing.Pool(self.num_proc     ) as pool:
         for num_rows in logging.tqdm(
             pool.imap(
                 self._batch_sql ,							[(offset, index, to_sql_kwargs) for offset in range(0 ,							A_ ,							A_     )] ,							) ,							total=(num_rows // batch_size) + 1 if num_rows % batch_size else num_rows // batch_size ,							unit="ba" ,							disable=not logging.is_progress_bar_enabled() ,							desc="Creating SQL from Arrow format" ,							):
          written += num_rows

       return written







from typing import TYPE_CHECKING

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


__lowerCamelCase :  int										=  {
    """configuration_convbert""": ["""CONVBERT_PRETRAINED_CONFIG_ARCHIVE_MAP""", """ConvBertConfig""", """ConvBertOnnxConfig"""],
    """tokenization_convbert""": ["""ConvBertTokenizer"""],
}

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

try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    __lowerCamelCase :  int										=  [
        """CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST""",
        """ConvBertForMaskedLM""",
        """ConvBertForMultipleChoice""",
        """ConvBertForQuestionAnswering""",
        """ConvBertForSequenceClassification""",
        """ConvBertForTokenClassification""",
        """ConvBertLayer""",
        """ConvBertModel""",
        """ConvBertPreTrainedModel""",
        """load_tf_weights_in_convbert""",
    ]


try:
    if not is_tf_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    __lowerCamelCase :  str										=  [
        """TF_CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST""",
        """TFConvBertForMaskedLM""",
        """TFConvBertForMultipleChoice""",
        """TFConvBertForQuestionAnswering""",
        """TFConvBertForSequenceClassification""",
        """TFConvBertForTokenClassification""",
        """TFConvBertLayer""",
        """TFConvBertModel""",
        """TFConvBertPreTrainedModel""",
    ]


if TYPE_CHECKING:
    from .configuration_convbert import CONVBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, ConvBertConfig, ConvBertOnnxConfig
    from .tokenization_convbert import ConvBertTokenizer

    try:
        if not is_tokenizers_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .tokenization_convbert_fast import ConvBertTokenizerFast

    try:
        if not is_torch_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_convbert import (
            CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
            ConvBertForMaskedLM,
            ConvBertForMultipleChoice,
            ConvBertForQuestionAnswering,
            ConvBertForSequenceClassification,
            ConvBertForTokenClassification,
            ConvBertLayer,
            ConvBertModel,
            ConvBertPreTrainedModel,
            load_tf_weights_in_convbert,
        )

    try:
        if not is_tf_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_tf_convbert import (
            TF_CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
            TFConvBertForMaskedLM,
            TFConvBertForMultipleChoice,
            TFConvBertForQuestionAnswering,
            TFConvBertForSequenceClassification,
            TFConvBertForTokenClassification,
            TFConvBertLayer,
            TFConvBertModel,
            TFConvBertPreTrainedModel,
        )


else:
    import sys

    __lowerCamelCase :  List[str]										=  _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)
