Last active
May 15, 2022 07:46
-
-
Save nordineb/e163a75f3c42dace3883cecb5f6f3705 to your computer and use it in GitHub Desktop.
USQL demo join
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @customerscsv string = "/Data/Meny/postgres_public_customer.csv"; | |
DECLARE @orderlinescsv string = "/Data/Meny/postgres_public_order_line.csv"; | |
DECLARE @productscsv string = "/Data/Meny/postgres_public_product.csv"; | |
DECLARE @orderscsv string = "/Data/Meny/postgres_public_store_order.csv"; | |
DECLARE @cvsout string = "/Data/Meny/Output/customerorders.csv"; | |
@customers = | |
EXTRACT Id int, | |
FirstName string, | |
LastName string, | |
Address string, | |
Phone string | |
FROM @customerscsv | |
USING Extractors.Csv(); | |
@orders = | |
EXTRACT Id int, | |
CustomerID int | |
FROM @orderscsv | |
USING Extractors.Csv(); | |
@orderline = | |
EXTRACT Id int, | |
OrderId int, | |
ProductId int, | |
Quantity int | |
FROM @orderlinescsv | |
USING Extractors.Csv(); | |
@products = | |
EXTRACT Id int, | |
ProductName string, | |
Price int | |
FROM @productscsv | |
USING Extractors.Csv(encoding: Encoding.UTF8); | |
@ds = | |
SELECT c.Id, c.FirstName, c.LastName, p.ProductName, p.Price, ol.Quantity | |
FROM @customers AS c | |
JOIN @orders AS o ON o.CustomerID == c.Id | |
JOIN @orderline AS ol ON ol.OrderId == o.Id | |
JOIN @products AS p ON p.Id == ol.ProductId; | |
OUTPUT @ds | |
TO @cvsout | |
USING Outputters.Csv(encoding:Encoding.UTF8, quoting: false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment