# -*- coding: utf-8 -*-
from pyspark.sql import HiveContext
from pyspark.context import SparkContext
from pyspark.conf import SparkConf
import pytispark.pytispark as pti
from pyspark.sql import SQLContext
from pyspark.sql import SparkSession
import datetime


def test():
    spark = SparkSession.builder.enableHiveSupport().getOrCreate()
    ti = pti.TiContext(spark)
    # ti.tidbMapDatabase("jerry_test")

    data = [(0, 18.0), (1, 19.0), (2, 8.0), (3, 5.0), (4, 2.2), (5, 9.2), (6, 14.4)]
    df = spark.createDataFrame(data, ["id", "hour"]).rdd.map(lambda x:x[0]).collect()
    print(df)

    # validate_date = spark.sql("select max(stat_date) from esmm_train_data").rdd.map(lambda x: str(x[0]))
    # print(validate_date.count())
    # print("validate_date:" + validate_date)
    # temp = datetime.datetime.strptime(validate_date, "%Y-%m-%d")
    # start = (temp - datetime.timedelta(days=10)).strftime("%Y-%m-%d")
    # print(start)


if __name__ == '__main__':
    test()