




"""simple docstring"""




import contextlib
import os
import sqlitea

import pytest

from datasets import Dataset, Features, Value
from datasets.io.sql import SqlDatasetReader, SqlDatasetWriter

from ..utils import assert_arrow_memory_doesnt_increase, assert_arrow_memory_increases, require_sqlalchemy



def 					a__				(       snake_case__ ,				snake_case__       )		->      Tuple:
			assert isinstance(snake_case__ ,				snake_case__       )
			assert dataset.num_rows == 4
			assert dataset.num_columns == 3
			assert dataset.column_names == ["col_1", "col_2", "col_3"]
			for feature, expected_dtype in expected_features.items():
						assert dataset.features[feature].dtype == expected_dtype



@require_sqlalchemy
@pytest.mark.parametrize("""keep_in_memory""" ,				[False, True]       )
def 					a__				(       snake_case__ ,				snake_case__ ,				snake_case__ ,				snake_case__       )		->      List[Any]:
			lowerCamelCase       =      tmp_path / """cache"""
			lowerCamelCase       =      {"""col_1""": """string""", """col_2""": """int64""", """col_3""": """float64"""}
			with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
						lowerCamelCase       =      SqlDatasetReader(
						    """dataset""" ,				"""sqlite:///""" + sqlite_path ,				cache_dir=snake_case__ ,				keep_in_memory=snake_case__       ).read()
			_check_sql_dataset(snake_case__ ,				snake_case__       )



@require_sqlalchemy
@pytest.mark.parametrize(
    """features""" ,				[
        None,
        {"""col_1""": """string""", """col_2""": """int64""", """col_3""": """float64"""},
        {"""col_1""": """string""", """col_2""": """string""", """col_3""": """string"""},
        {"""col_1""": """int32""", """col_2""": """int32""", """col_3""": """int32"""},
        {"""col_1""": """float32""", """col_2""": """float32""", """col_3""": """float32"""},
    ] ,				)
def 					a__				(       snake_case__ ,				snake_case__ ,				snake_case__ ,				snake_case__       )		->      str:
			lowerCamelCase       =      tmp_path / """cache"""
			lowerCamelCase       =      {"""col_1""": """string""", """col_2""": """int64""", """col_3""": """float64"""}
			lowerCamelCase       =      features.copy() if features else default_expected_features
			lowerCamelCase       =      (
			    Features({feature: Value(snake_case__       ) for feature, dtype in features.items()}       ) if features is not None else None
			)
			lowerCamelCase       =      SqlDatasetReader("""dataset""" ,				"""sqlite:///""" + sqlite_path ,				features=snake_case__ ,				cache_dir=snake_case__       ).read()
			_check_sql_dataset(snake_case__ ,				snake_case__       )



def 					a__				(       snake_case__       )		->      Any:
			with contextlib.closing(sqlitea.connect(snake_case__       )       ) as con:
						lowerCamelCase       =      con.cursor()
						cur.execute("""SELECT * FROM dataset"""       )
						for row in cur:
									yield row



@require_sqlalchemy
def 					a__				(       snake_case__ ,				snake_case__ ,				snake_case__       )		->      Optional[int]:
			lowerCamelCase       =      tmp_path / """cache"""
			lowerCamelCase       =      os.path.join(snake_case__ ,				"""tmp.sql"""       )
			lowerCamelCase       =      SqlDatasetReader("""dataset""" ,				"""sqlite:///""" + sqlite_path ,				cache_dir=snake_case__       ).read()
			SqlDatasetWriter(snake_case__ ,				"""dataset""" ,				"""sqlite:///""" + output_sqlite_path ,				num_proc=1       ).write()

			lowerCamelCase       =      iter_sql_file(snake_case__       )
			lowerCamelCase       =      iter_sql_file(snake_case__       )

			for rowa, rowa in zip(snake_case__ ,				snake_case__       ):
						assert rowa == rowa



@require_sqlalchemy
def 					a__				(       snake_case__ ,				snake_case__ ,				snake_case__       )		->      Optional[Any]:
			lowerCamelCase       =      tmp_path / """cache"""
			lowerCamelCase       =      os.path.join(snake_case__ ,				"""tmp.sql"""       )
			lowerCamelCase       =      SqlDatasetReader("""dataset""" ,				"""sqlite:///""" + sqlite_path ,				cache_dir=snake_case__       ).read()
			SqlDatasetWriter(snake_case__ ,				"""dataset""" ,				"""sqlite:///""" + output_sqlite_path ,				num_proc=2       ).write()

			lowerCamelCase       =      iter_sql_file(snake_case__       )
			lowerCamelCase       =      iter_sql_file(snake_case__       )

			for rowa, rowa in zip(snake_case__ ,				snake_case__       ):
						assert rowa == rowa



@require_sqlalchemy
def 					a__				(       snake_case__ ,				snake_case__ ,				snake_case__       )		->      Optional[int]:
			lowerCamelCase       =      tmp_path / """cache"""
			lowerCamelCase       =      os.path.join(snake_case__ ,				"""tmp.sql"""       )
			lowerCamelCase       =      SqlDatasetReader("""dataset""" ,				"""sqlite:///""" + sqlite_path ,				cache_dir=snake_case__       ).read()
			with pytest.raises(snake_case__       ):
						SqlDatasetWriter(snake_case__ ,				"""dataset""" ,				"""sqlite:///""" + output_sqlite_path ,				num_proc=0       ).write()









"""simple docstring"""




from functools import lru_cache



def 					a__				(       snake_case__       )		->      set:
			lowerCamelCase       =      2
			lowerCamelCase       =      set()
			while i * i <= n:
						if n % i:
									i += 1
						else:
									n //= i
									factors.add(snake_case__       )
			if n > 1:
						factors.add(snake_case__       )
			return factors



@lru_cache
def 					a__				(       snake_case__       )		->      int:
			return len(unique_prime_factors(snake_case__       )       )



def 					a__				(       snake_case__       )		->      bool:
			return len(set(snake_case__       )       ) in (0, 1)



def 					a__				(       snake_case__       )		->      list:
			lowerCamelCase       =      2

			while True:
						# Increment each value of a generated range
						lowerCamelCase       =      [base + i for i in range(snake_case__       )]

						# Run elements through out unique_prime_factors function
						# Append our target number to the end.
						lowerCamelCase       =      [upf_len(snake_case__       ) for x in group]
						checker.append(snake_case__       )

						# If all numbers in the list are equal, return the group variable.
						if equality(snake_case__       ):
									return group

						# Increment our base variable by 1
						base += 1



def 					a__				(       snake_case__ = 4       )		->      int:
			lowerCamelCase       =      run(snake_case__       )
			return results[0] if len(snake_case__       ) else None


if __name__ == "__main__":
					print(solution())



