Problem Statement
You are given 4 JSON files named products, reviews, users, transactions that contains information about various products sold by an e-commerce company, user information, reviews written by users and all transactions made on the products.
Your task is to develop a SQL query engine that can execute SQL queries on JSON data. The engine is expected to handle the following types of queries -
• SELECT
• WHERE
• JOIN (INNER type only)
• GROUP BY
• ORDER BY
• LIMIT
• Aggregate functions (COUNT(*), AVG, SUM, MIN, MAX)
•
The SQL query will be provided as input will always follow the syntax below. The way to read the syntax definition is - square brackets [ ] indicate optional presence of that element in the query and curly braces { } indicates mandatory where applicable. Pipe | separated values indicates any one of the options. ... indicates one or many such elements can exist.

`SELECT
    {table_alias | join_table_alias}.col_name AS column_alias,
    …
FROM table table_alias
[ JOIN table join_table_alias on joinexpr [AND joinexpr ... ] ] …
[WHERE expr [AND expr ... ] ]
[GROUP BY {table_alias.col_name, … }]
ORDER BY {column_alias, … } { ASC | DESC }
[LIMIT n]`

The joinexpr in JOIN can have multiple conditions, however it will be always AND clauses. One condition will always be of form below,

`{table_alias | join_table_alias}.col_name = {value | {table_alias | join_table_alias}.col_name}}`
The expr in WHERE can have multiple conditions, however it will be always AND clauses. One condition will always be of form below,

`{table_alias | join_table_alias}.col_name {operator} {value}`
The supported operators in WHERE expr for the engine are the ones below only:
• = (equals)
• <> (not equals)
• > (greater than)
• >= (greater than or equal to )
• < (less than)
• <= (less than or equal to)

Supported aggregations:
1 COUNT(*)
◦ provides the count of rows in the result set.
◦ Result must be integer type
2 SUM( {table_alias|join_table_alias}.col_name )
◦ Only one column supported
◦ For Double column, result must be rounded to 2 decimal places and always have 2 decimal places
3 AVG( {table_alias|join_table_alias}.col_name )
◦ Only one column supported
◦ For Double column, result must be rounded to 2 decimal places and always have 2 decimal places
4 MIN( {table_alias|join_table_alias}.col_name )
◦ Only one column supported
◦ For Double column, result must be rounded to 2 decimal places and always have 2 decimal places
5 MAX( {table_alias|join_table_alias}.col_name )
◦ Only one column supported
◦ For Double column, result must be rounded to 2 decimal places and always have 2 decimal places
The engine will be tested with four JSON files: products, reviews, users, transactions with each file representing a table name.

Input Format

Data Files
Data Files are available in your program current directory :
• products_public.json
• users_public.json
• reviews_public.json
• transactions_public.json

Sample Input
The input will be the below string available in standard input:
SELECT p.id AS product_id, p.name AS product_name FROM products p WHERE p.price > 10.00 ORDER BY product_id ASC

Reading the Input
You can read the input SQL query as standard input.
To read the data files (e.g. products_public.json, user_public.json ... etc) , you can use some of the below code snippets:

Python
` //read from standard input line = input()
// Get the current directory  current_directory = os.getcwd()  // Get all files in the directory  files = os.listdir(current_directory)  `

Constraints
Product attributes:
• id: Unique product id, type: int32, constraint: unique in file
• name: Product name, type: string, constraint: none
• category: Product category, type: string, constraint: none
• price: Price of the product, type: double, constraint: positive with 2 decimal precision
User attributes:
• user_id: Unique user id, type: int32, constraint: unique in file
• name: User name, type: string, constraint: none
• age: Age of the user, type: int32, constraint: positive number
• location: City of the user, type: string, constraint: none
Review attributes:
• product_id: Id of product, type: int32, constraint: part of unique key in file
• user_id: Id of user, type: int32, constraint: part of unique key in file
• rating: Rating by user, type: int32, constraint: 0 - 5 both inclusive
• comment: Comment by user, type: string, constraint: none
Transaction attributes:
• transaction_id: Unique id of transaction, type: int32, constraint: unique in file
• product_id: Id of product, type: int32, constraint: none
• user_id: Id of user, type: int32, constraint: none
• price: Price at which 1 unit of product was sold, type: double, constraint: positive with 2 decimal precision
• quantity: Total units bought, type: int32, constraint: positive number
• date: Date when transaction happened, type: string, constraint: format YYYY-MM-DD
• total_amount: Quantity * price, type: double, constraint: always greater than 0

Output Format
Guidelines
• The output must be a string
• Since we expect several rows and columns, essentially a tabular output, please use comma separator with no spaces before and after to separate out columns and line separator \n to separate out rows.
• the first line of the output must be the column names expected in the result, separated by comma with no spaces before and after. The order of the column names also matters and must match with what is provided in SQL query input.

Sample Input 0

SELECT p.id AS product_id, p.name AS product_name FROM products p WHERE p.price > 95.00 ORDER BY product_id ASC

Sample Output 0

product_id,product_name\n6,product6\n11,product11\n62,product62\n67,product67\n78,product78

Explanation 0

    The column names appear as the first line in output. They are in the order in what appears in SELECT clause in SQL query input, separated by comma with no spaces before or after.
    Rest follows the result from the products table

Sample Input 1

SELECT u.user_id AS user_id, u.name AS user_name FROM users u WHERE u.age > 48 AND u.location = 'Delhi' ORDER BY user_id DESC

Sample Output 1

user_id,user_name\n9943,user9943\n9493,user9493\n9364,user9364\n8650,user8650\n8515,user8515\n8495,user8495\n6849,user6849\n6387,user6387\n6090,user6090\n4100,user4100\n3660,user3660\n3390,user3390\n2908,user2908\n2773,user2773\n2272,user2272\n373,user373

Sample Input 2

SELECT p.category AS product_category, COUNT(*) AS product_counts FROM products p GROUP BY p.category ORDER BY product_counts DESC LIMIT 1

Sample Output 2

product_category,product_counts\nBOOKS,32

use [json.loads(line) for line in f]