Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

README.md

Outline

Problems 4 -> Get Shortest and Longest City Name

Query the two cities in STATION with the shortest and longest CITY names, as well as their respective lengths (i.e.: number of characters in the name). If there is more than one smallest or largest city, choose the one that comes first when ordered alphabetically. The STATION table is described as follows:

Problem Difficulty Level : Hard

Data Structure

  • ID
  • City
  • State
  • Lattitude
  • Longitude

image

Data for station table

In CSV Format

Sample Input

For example, CITY has four entries: DEF, ABC, PQRS and WXY.

Sample Output

ABC 3
PQRS 4

Solving using PySpark

In Spark we will solve this problem using two ways

  1. Using PySpark Functions
  2. Using Spark SQL

Use below notebook for solution

Problem Solution First Part

Solving using PostgreSQL

In Postgre SQL We will load data from CSV using PostgreSQL Import functionality. And then we will solve this problem.

Output Query

Problem Solution

Please also follow below blog for understanding this problem

Morty Proxy This is a proxified and sanitized view of the page, visit original site.