Question: Please help me with my code, is it because of the TimestamTyoe of data? The QUERY WHERE and ORDER BY does not work. The WHERE

Please help me with my code, is it because of the TimestamTyoe of data? The QUERY
WHERE and ORDER BY does not work. The WHERE first part without the ORDER BY works.
Consider a warc.csv file related data. An indicative line is:
2017-03-22T22:13:57Z, record id, reposnse, 40802, ip addres, URL, Server, HTML DOC
Columns in order: first the Warc date, the warc record id, the Warc type (e.g. metadata,
response, etc), the content length, the public IP address, the target URL, the server running
the site (eg apache, DginX, etc), and finally the overall content of the page with the entire
HTML DOM. For the time range between 2017-03-2222:00 and 2017-03-2223:00, find the 5
most used servers. Results to be given in descending order of servers.
My code:
from datetime import datetime
from pyspark, sql import SparkSession
from pyspark.sql.types import StructType, StructField, StringType, IntegerType,
FloaType ,TimestampType.
# Initialize Spark Session
spark = SparkSession.builder.appName("WarcAnalysis").getOrCreate()
# Define the schema
schema = StructType[
StructField["date", TimestamaType), True),
StructField["recordid", StringType, True),
StructField("type", StringType(), True),
StructField ["content_length", IntegerType(), True),
StructField("public _p", StringType(), True),
StructField("target,_rl", StringType, True),
StructField ("server", StrionfType(), True),
StructField ("btmldom", StringType(), True)
# Load the data into RataFrame
df= spark.read.format('csv')}
options(header='false')\
schema(schema)\
load("warc.csv")
# Register the Bata Frame as a temporary table
df. createOrReplaceTempView("warc")
##Filter the data using Spark SQL
id quex = "SELECT warc
FROM wars \
WHERE warc.date ='2017-03-22T22:00:00Z' AND warc.date '2017-03-
22T22:00:00Z'
ORDER BY warc.date ASC "
filtered.df = spack.sql(id_query)
# Show the result
filtered df.show(5)
# Stop Spark Session
spark.stop()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!