import os
import sys

sys.path.append(os.path.dirname(sys.path[0]))  # 上级目录
from pyspark.storagelevel import StorageLevel
from utils.templates import Templates
from ..utils.templates import Templates
# from AmazonSpider.pyspark_job.utils.templates_test import Templates
from pyspark.sql.types import StringType, IntegerType
# 分组排序的udf窗口函数
from pyspark.sql.window import Window
from pyspark.sql import functions as F


class TempStRankOldAndNew(Templates):

    def __init__(self, site_name='us', date_type="month", date_info='2022-01'):
        super(TempStRankOldAndNew, self).__init__()
        self.site_name = site_name
        self.date_type = date_type
        self.date_info = date_info
        self.db_save_st_asin = f'temp_st_ran_old_and_new'
        self.spark = self.create_spark_object(app_name=f"{self.db_save}: {self.site_name}, {self.date_type}, {self.date_info}")
        self.df_st_detail = self.spark.sql(f"select 1+1;")

    def read_data(self):
        # 1. 周数据
        sql = f"select search_term, st_rank from dim_st_detail where site_name='{self.site_name}' and date_type in"

        # 2. 日数据

        # 3. 日期数据

    def handle_data(self):
        pass