from pyspark.sql import SparkSession

spark = SparkSession.builder.appName("SparkSQL").getOrCreate()
people = spark.read.option("header", "true").option("inferSchema", "true").csv("/home/kohei/Workspace/database/customers.csv")
people.createOrReplaceTempView('customers')
# schemaPeople = spark.createDataFrame(people).cache()
# schemaPeople.createOrReplaceTempView("people")

# print("Here is our inferred schema:")
# people.printSchema()

customers = spark.sql("SELECT * FROM customers")
for customer in customers.collect():
    print(customers.first_name)

# print("Let's display the name column:")
# people.select("name").show()

# print("Filter out anyone over 21:")
# people.filter(people.age < 21).show()

# print("Group by age")
# people.groupBy("age").count().show()

# print("Make everyone 10 years older:")
# people.select(people.name, people.age + 10).show()

# spark.stop()
