


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


SCREAMING_SNAKE_CASE__       			=				datasets.utils.logging.get_logger(__name__)







@dataclass
class     __lowerCamelCase     (  datasets.BuilderConfig     ):


							"""simple docstring"""

							lowerCAmelCase__          =				None
							lowerCAmelCase__          =				None
							lowerCAmelCase__          =				None
							lowerCAmelCase__          =				True
							lowerCAmelCase__          =				None
							lowerCAmelCase__          =				None
							lowerCAmelCase__          =				None
							lowerCAmelCase__          =				1_00_00
							lowerCAmelCase__          =				None




							def 				A__      (  self  )     ->       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 				A__      (  self						,       UpperCAmelCase						,       UpperCAmelCase = None						,       )     ->       str:






								'''simple docstring'''






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

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

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




							@property
							def 				A__      (  self  )     ->       Dict:






								'''simple docstring'''






								lowercase_			 = {
								    "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     ):


							"""simple docstring"""

							lowerCAmelCase__          =				SqlConfig




							def 				A__      (  self  )     ->       str:






								'''simple docstring'''






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




							def 				A__      (  self						,       UpperCAmelCase  )     ->       Optional[int]:






								'''simple docstring'''






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




							def 				A__      (  self						,       UpperCAmelCase  )     ->       pa.Table:






								'''simple docstring'''






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




							def 				A__      (  self  )     ->       str:






								'''simple docstring'''






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





from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available, is_torch_available


SCREAMING_SNAKE_CASE__       			=				{
    """configuration_markuplm""": ["""MARKUPLM_PRETRAINED_CONFIG_ARCHIVE_MAP""", """MarkupLMConfig"""],
    """feature_extraction_markuplm""": ["""MarkupLMFeatureExtractor"""],
    """processing_markuplm""": ["""MarkupLMProcessor"""],
    """tokenization_markuplm""": ["""MarkupLMTokenizer"""],
}

try:
							if not is_tokenizers_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							SCREAMING_SNAKE_CASE__       			=				["""MarkupLMTokenizerFast"""]

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							SCREAMING_SNAKE_CASE__       			=				[
							    """MARKUPLM_PRETRAINED_MODEL_ARCHIVE_LIST""",
							    """MarkupLMForQuestionAnswering""",
							    """MarkupLMForSequenceClassification""",
							    """MarkupLMForTokenClassification""",
							    """MarkupLMModel""",
							    """MarkupLMPreTrainedModel""",
							]


if TYPE_CHECKING:
							from .configuration_markuplm import MARKUPLM_PRETRAINED_CONFIG_ARCHIVE_MAP, MarkupLMConfig
							from .feature_extraction_markuplm import MarkupLMFeatureExtractor
							from .processing_markuplm import MarkupLMProcessor
							from .tokenization_markuplm import MarkupLMTokenizer

							try:
														if not is_tokenizers_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .tokenization_markuplm_fast import MarkupLMTokenizerFast

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_markuplm import (
														    MARKUPLM_PRETRAINED_MODEL_ARCHIVE_LIST,
														    MarkupLMForQuestionAnswering,
														    MarkupLMForSequenceClassification,
														    MarkupLMForTokenClassification,
														    MarkupLMModel,
														    MarkupLMPreTrainedModel,
														)


else:
							import sys

							SCREAMING_SNAKE_CASE__       			=				_LazyModule(__name__, globals()["""__file__"""], _import_structure)

