Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Server T-SQL Recipes

Authors: David Dye, Jason Brimhall

4th Edition

1484200616, 9781484200612

More Books

Students also viewed these Databases questions

Question

Consider the benefits and limitations of financial analysis.

Answered: 1 week ago

Question

Explain the key components of an assessment center (AC).

Answered: 1 week ago