Skip to content

Commit

Permalink
Remove column versions for user defined/calcite names (#356)
Browse files Browse the repository at this point in the history
* Remove column versions for user defined named
---------

Signed-off-by: Daniel Henneberger <git@danielhenneberger.com>
  • Loading branch information
henneberger committed Oct 13, 2023
1 parent d4ce31c commit 2d7314f
Show file tree
Hide file tree
Showing 236 changed files with 2,068 additions and 3,432 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,18 @@
*/
package com.datasqrl.engine.database.relational;

import com.datasqrl.engine.PhysicalPlan.StagePlan;
import com.datasqrl.engine.database.DatabasePhysicalPlan;
import com.datasqrl.engine.database.QueryTemplate;
import com.datasqrl.engine.database.relational.ddl.JdbcDDLFactory;
import com.datasqrl.engine.database.relational.ddl.JdbcDDLServiceLoader;
import com.datasqrl.engine.database.relational.ddl.SqlDDLStatement;
import com.datasqrl.io.impl.jdbc.JdbcDataSystemConnector;
import com.datasqrl.plan.global.IndexDefinition;
import com.datasqrl.plan.queries.APIQuery;
import com.datasqrl.plan.queries.IdentifiedQuery;
import com.datasqrl.serializer.Deserializer;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collection;
import java.util.stream.Collectors;
import lombok.Value;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import lombok.Value;

@Value
public class JDBCPhysicalPlan implements DatabasePhysicalPlan {
Expand Down
2 changes: 1 addition & 1 deletion sqrl-examples/mutations/script.sqrl
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
IMPORT schema.createEvent AS event;
IMPORT string.*;
event.name := RTRIM(LTRIM(name));
event.trimmed_name := RTRIM(LTRIM(name));
6 changes: 3 additions & 3 deletions sqrl-examples/nutshop/customer360-adv/customer360-adv.sqrl
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
IMPORT nutshop-small.Products;
IMPORT nutshop-small.Orders TIMESTAMP epoch_to_timestamp(time/1000) AS timestamp;

Orders.items.discount := coalesce(discount, 0.0);
Orders.items.discount0 := coalesce(discount, 0.0);

Customers := SELECT DISTINCT customerid AS id FROM Orders;
Products := DISTINCT Products ON id ORDER BY updated DESC;

Customers.purchases := JOIN Orders ON Orders.customerid = @.id ORDER BY Orders.time DESC;
Orders.items.product := JOIN Products ON Products.id = @.productid;

Orders.items.total := quantity * unit_price - discount;
Orders.totals := SELECT sum(total) as price, sum(discount) as savings FROM @.items;
Orders.items.total := quantity * unit_price - discount0;
Orders.totals := SELECT sum(total) as price, sum(discount0) as savings FROM @.items;

Customers.spending_by_month :=
SELECT endOfmonth(p.timestamp) AS month,
Expand Down
8 changes: 4 additions & 4 deletions sqrl-examples/nutshop/customer360-api/customer360-api.sqrl
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ IMPORT usda-data.nuts;
Products := DISTINCT Products ON id ORDER BY _ingest_time DESC;

Orders.date := EPOCH_TO_TIMESTAMP(time);
Orders.items.discount := coalesce(discount, 0.0);
Orders.items.discount0 := coalesce(discount, 0.0);

-- @api(name="User", query="getusers")
Customers := SELECT DISTINCT customerid AS id FROM Orders;

Customers.purchases := JOIN Orders ON Orders.customerid = @.id ORDER BY Orders.time DESC;
Orders.items.product := JOIN Products ON Products.id = @.productid LIMIT 1;

Orders.items.total := quantity * unit_price - discount;
Orders.items.total := quantity * unit_price - discount0;
Orders.total := sum(items.total);
Orders.savings := sum(items.discount);
Orders.savings := sum(items.discount0);

Customers.spending_by_month :=
SELECT TRUNCATE_TO_MONTH(date) AS month,
sum(total) AS total_spend,
sum(discount) AS total_savings
sum(discount0) AS total_savings
FROM @.purchases
GROUP BY month ORDER BY month DESC;

Expand Down
8 changes: 4 additions & 4 deletions sqrl-examples/nutshop/customer360-ext/customer360-ext.sqrl
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ IMPORT usda-data.nuts;
Products := DISTINCT Products ON id ORDER BY _ingest_time DESC;

Orders.date := EPOCH_TO_TIMESTAMP(time);
Orders.items.discount := coalesce(discount, 0.0);
Orders.items.discount0 := coalesce(discount, 0.0);

Customers := SELECT DISTINCT customerid AS id FROM Orders;

Customers.purchases := JOIN Orders ON Orders.customerid = @.id ORDER BY Orders.time DESC;
Orders.items.product := JOIN Products ON Products.id = @.productid LIMIT 1;

Orders.items.total := quantity * unit_price - discount;
Orders.items.total := quantity * unit_price - discount0;
Orders.total := sum(items.total);
Orders.savings := sum(items.discount);
Orders.savings := sum(items.discount0);

Customers.spending_by_month :=
SELECT TRUNCATE_TO_MONTH(date) AS month,
sum(total) AS total_spend,
sum(discount) AS total_savings
sum(discount0) AS total_savings
FROM @.purchases
GROUP BY month ORDER BY month DESC;

Expand Down
6 changes: 3 additions & 3 deletions sqrl-examples/nutshop/customer360/nutshopv1-small.sqrl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ IMPORT nutshop-small.Products;
IMPORT nutshop-small.Orders TIMESTAMP epochToTimestamp(time/1000) AS timestamp;

/* Some order items are missing the discount field - let's clean that up */
Orders.items.discount := coalesce(discount, 0.0);
Orders.items.discount0 := coalesce(discount, 0.0);

/* The Customers table are all the `customerid` that have placed an order */
Customers := SELECT DISTINCT customerid AS id FROM Orders;
Expand All @@ -19,9 +19,9 @@ Customers.purchases := JOIN Orders ON Orders.customerid = @.id ORDER BY Orders.t
Orders.items.product := JOIN Products ON Products.id = @.productid;

/* Add a column to compute the total for each item in an order */
Orders.items.total := quantity * unit_price - discount;
Orders.items.total := quantity * unit_price - discount0;
/* Adds a nested table `totals` in Orders to compute the totals for each Order */
Orders.totals := SELECT sum(total) as price, sum(discount) as savings FROM @.items;
Orders.totals := SELECT sum(total) as price, sum(discount0) as savings FROM @.items;

/* Aggregates the purchase history for each customer by month */
Customers.spending_by_month :=
Expand Down
6 changes: 3 additions & 3 deletions sqrl-examples/nutshop/customer360/nutshopv2-medium.sqrl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ IMPORT time.*;
IMPORT nutshop-medium.Products;
IMPORT nutshop-medium.Orders TIMESTAMP epochToTimestamp(time/1000) AS timestamp;

Orders.items.discount := coalesce(discount, 0.0);
Orders.items.total := quantity * unit_price - discount;
Orders.totals := SELECT sum(total) as price, sum(discount) as savings FROM @.items;
Orders.items.discount0 := coalesce(discount, 0.0);
Orders.items.total := quantity * unit_price - discount0;
Orders.totals := SELECT sum(total) as price, sum(discount0) as savings FROM @.items;

Products := DISTINCT Products ON id ORDER BY updated DESC;
Orders.items.product := JOIN Products ON Products.id = @.productid;
Expand Down
6 changes: 3 additions & 3 deletions sqrl-examples/nutshop/customer360/nutshopv2-small.sqrl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ IMPORT time.*;
IMPORT nutshop-compress.Products;
IMPORT nutshop-compress.Orders TIMESTAMP epochToTimestamp(time/1000) AS timestamp;

Orders.items.discount := coalesce(discount, 0.0);
Orders.items.total := quantity * unit_price - discount;
Orders.totals := SELECT sum(total) as price, sum(discount) as savings FROM @.items;
Orders.items.discount0 := coalesce(discount, 0.0);
Orders.items.total := quantity * unit_price - discount0;
Orders.totals := SELECT sum(total) as price, sum(discount0) as savings FROM @.items;

Products := DISTINCT Products ON id ORDER BY updated DESC;
Orders.items.product := JOIN Products ON Products.id = @.productid;
Expand Down
6 changes: 3 additions & 3 deletions sqrl-examples/nutshop/customer360/nutshopv3-small.sqrl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ IMPORT time.*;
IMPORT nutshop-small.Products;
IMPORT nutshop-small.Orders TIMESTAMP epochToTimestamp(time/1000) AS timestamp;

Orders.items.discount := coalesce(discount, 0.0);
Orders.items.total := quantity * unit_price - discount;
Orders.totals := SELECT sum(total) as price, sum(discount) as savings FROM @.items;
Orders.items.discount0 := coalesce(discount, 0.0);
Orders.items.total := quantity * unit_price - discount0;
Orders.totals := SELECT sum(total) as price, sum(discount0) as savings FROM @.items;

Products := DISTINCT Products ON id ORDER BY updated DESC;
Orders.items.product := JOIN Products ON Products.id = @.productid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ IMPORT time.*;
IMPORT nutshop-compress.Products;
IMPORT nutshop-compress.Orders TIMESTAMP epochToTimestamp(time/1000) AS timestamp;

Orders.items.discount := coalesce(discount, 0.0);
Orders.items.total := quantity * unit_price - discount;
Orders.totals := SELECT sum(total) as price, sum(discount) as savings FROM @.items;
Orders.items.discount0 := coalesce(discount, 0.0);
Orders.items.total := quantity * unit_price - discount0;
Orders.totals := SELECT sum(total) as price, sum(discount0) as savings FROM @.items;

Products := DISTINCT Products ON id ORDER BY updated DESC;
Orders.items.product := JOIN Products ON Products.id = @.productid;
Expand Down
10 changes: 5 additions & 5 deletions sqrl-examples/quickstart/quickstart-docs.sqrl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ IMPORT datasqrl.seedshop.Products;
IMPORT time.*;
IMPORT datasqrl.seedshop.Customers AS Users TIMESTAMP epochMilliToTimestamp(changed_on) AS timestamp;

Orders.items.discount := discount?0.0;
Orders.items.total := quantity * unit_price - discount;
Orders.items.discount0 := discount?0.0;
Orders.items.total := quantity * unit_price - discount0;
Orders.totals := SELECT sum(total) as price,
sum(discount) as saving FROM @.items;
sum(discount0) as saving FROM @.items;

-- Replacing users from import
Users := DISTINCT Users ON id ORDER BY timestamp DESC;
Expand Down Expand Up @@ -52,12 +52,12 @@ UsersWithSpending := SELECT u.id, u.email, s.spend AS spend FROM Users u JOIN u.
HighSpendingUsers := SELECT u.id, u.email FROM Users u JOIN u.order_stats s WHERE s.spend > 1000;

Users.spending_last_week := SELECT sum(i.total) AS spend,
sum(i.discount) AS saved
sum(i.discount0) AS saved
FROM @.purchases p JOIN p.items i
WHERE p.time > now() - INTERVAL 7 DAY;

Users.total_spend := SELECT sum(i.total) AS spend,
sum(i.discount) AS saved
sum(i.discount0) AS saved
FROM @ JOIN Orders o ON o.customerid = @.id JOIN o.items i;

RecentTotal := SELECT sum(i.total) AS total, sum(i.quantity) AS quantity
Expand Down
16 changes: 8 additions & 8 deletions sqrl-examples/quickstart/quickstart-export-err.sqrl
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
IMPORT datasqrl.seedshop.Orders TIMESTAMP time + INTERVAL 8 DAY AS time;
IMPORT datasqrl.seedshop.Orders TIMESTAMP time + INTERVAL 8 DAY AS timestamp;
IMPORT datasqrl.seedshop.Products;
IMPORT time.*;
IMPORT datasqrl.seedshop.Customers AS Users TIMESTAMP epochMilliToTimestamp(changed_on) AS timestamp;

Orders.items.discount := discount?0.0;
Orders.items.total := quantity * unit_price - discount;
Orders.items.discount0 := discount?0.0;
Orders.items.total := quantity * unit_price - discount0;
Orders.totals := SELECT sum(total) as price,
sum(discount) as saving FROM @.items;
sum(discount0) as saving FROM @.items;

Users := DISTINCT Users ON id ORDER BY timestamp DESC;
Users.purchases := JOIN Orders ON Orders.customerid = @.id;
Users.country := country?'none';
Users.country0 := country?'none';
Orders.user := JOIN Users ON @.customerid = Users.id;

Users.spending := SELECT endOfWeek(p.time) AS week,
Users.spending := SELECT endOfWeek(p.timestamp) AS week,
sum(t.price) AS spend, sum(t.saving) AS saved
FROM @.purchases p JOIN p.totals t
GROUP BY week ORDER BY week DESC;
Expand All @@ -33,10 +33,10 @@ Products.ordered_items := JOIN Orders.items i ON i.productid = @.id;
Products.volume_10day := SELECT u.country, sum(i.quantity) as quantity,
sum(i.total) as spend, sum(i.quantity * @.weight_in_gram) as weight
FROM @ JOIN @.ordered_items i JOIN i.parent o JOIN o.user u
WHERE o.time > now() - INTERVAL 10 DAY GROUP BY u.country;
WHERE o.timestamp > now() - INTERVAL 10 DAY GROUP BY u.country;

--
Users.order_stats := SELECT min(o.time) as first_order,
Users.order_stats := SELECT min(o.timestamp) as first_order,
sum(t.price) as spend, sum(t.saving) as saved, count(1) as num_orders
FROM @.purchases o JOIN o.totals t;

Expand Down
16 changes: 8 additions & 8 deletions sqrl-examples/quickstart/quickstart-export.sqrl
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
IMPORT datasqrl.seedshop.Orders TIMESTAMP time + INTERVAL 8 DAY AS time;
IMPORT datasqrl.seedshop.Orders TIMESTAMP time + INTERVAL 8 DAY AS timestamp;
IMPORT datasqrl.seedshop.Products;
IMPORT time.*;
IMPORT mySourcePackage.Customers AS Users TIMESTAMP epochMilliToTimestamp(changed_on) AS timestamp;

Orders.items.discount := discount?0.0;
Orders.items.total := quantity * unit_price - discount;
Orders.items.discount0 := discount?0.0;
Orders.items.total := quantity * unit_price - discount0;
Orders.totals := SELECT sum(total) as price,
sum(discount) as saving FROM @.items;
sum(discount0) as saving FROM @.items;

Users := DISTINCT Users ON id ORDER BY timestamp DESC;
Users.purchases := JOIN Orders ON Orders.customerid = @.id;
Users.country := country?'none';
Users.country0 := country?'none';
Orders.user := JOIN Users ON @.customerid = Users.id;

Users.spending := SELECT endOfWeek(p.time) AS week,
Users.spending := SELECT endOfWeek(p.timestamp) AS week,
sum(t.price) AS spend, sum(t.saving) AS saved
FROM @.purchases p JOIN p.totals t
GROUP BY week ORDER BY week DESC;
Expand All @@ -30,10 +30,10 @@ Products := DISTINCT Products ON id ORDER BY updated DESC;
Orders.items.product := JOIN Products ON Products.id = @.productid;
Products.ordered_items := JOIN Orders.items i ON i.productid = @.id;

Products.volume_10day := SELECT u.country, sum(i.quantity) as quantity,
Products.volume_10day := SELECT u.country0 AS country, sum(i.quantity) as quantity,
sum(i.total) as spend, sum(i.quantity * @.weight_in_gram) as weight
FROM @ JOIN @.ordered_items i JOIN i.parent o JOIN o.user u
WHERE o.time > now() - INTERVAL 10 DAY GROUP BY u.country;
WHERE o.timestamp > now() - INTERVAL 10 DAY GROUP BY u.country0;

--
Users.order_stats := SELECT sum(t.price) as spend, sum(t.saving) as saved,
Expand Down
16 changes: 8 additions & 8 deletions sqrl-examples/quickstart/quickstart-mutation.sqrl
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
IMPORT datasqrl.seedshop.Orders TIMESTAMP time + INTERVAL 8 DAY AS time;
IMPORT datasqrl.seedshop.Orders TIMESTAMP time + INTERVAL 8 DAY AS timestamp;
IMPORT datasqrl.seedshop.Products;
IMPORT time.*;
IMPORT mySourcePackage.Customers AS Users TIMESTAMP epochMilliToTimestamp(changed_on) AS timestamp;
IMPORT seedshop.ProductVisit;

Orders.items.discount := discount?0.0;
Orders.items.total := quantity * unit_price - discount;
Orders.items.discount0 := discount?0.0;
Orders.items.total := quantity * unit_price - discount0;
Orders.totals := SELECT sum(total) as price,
sum(discount) as saving FROM @.items;
sum(discount0) as saving FROM @.items;

-- Replacing users from import
Users := DISTINCT Users ON id ORDER BY timestamp DESC;
Users.purchases := JOIN Orders ON Orders.customerid = @.id;
Users.country := country?'none';
Users.country0 := country?'none';
Orders.user := JOIN Users ON @.customerid = Users.id;

Users.spending := SELECT endOfWeek(p.time) AS week,
Users.spending := SELECT endOfWeek(p.timestamp) AS week,
sum(t.price) AS spend, sum(t.saving) AS saved
FROM @.purchases p JOIN p.totals t
GROUP BY week ORDER BY week DESC;
Expand All @@ -38,7 +38,7 @@ Orders.items.product := JOIN Products ON Products.id = @.productid;
Products.ordered_items := JOIN Orders.items i ON i.productid = @.id;

-- aggregating by country
Products.volume_10day := SELECT u.country, sum(i.quantity) as quantity,
Products.volume_10day := SELECT u.country0 AS country, sum(i.quantity) as quantity,
sum(i.total) as spend, sum(i.quantity * @.weight_in_gram) as weight
FROM @ JOIN @.ordered_items i JOIN i.parent o JOIN o.user u
WHERE o.time > now() - INTERVAL 10 DAY GROUP BY u.country;
WHERE o.timestamp > now() - INTERVAL 10 DAY GROUP BY u.country0;
6 changes: 3 additions & 3 deletions sqrl-examples/quickstart/quickstart-sqrl.sqrl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ IMPORT datasqrl.seedshop.Orders;
IMPORT datasqrl.seedshop.Products;
IMPORT time.endOfWeek;

Orders.items.discount := discount?0.0; -- Data cleaning
Orders.items.total := quantity * unit_price - discount;
Orders.items.discount0 := discount?0.0; -- Data cleaning
Orders.items.total := quantity * unit_price - discount0;
Orders.totals := SELECT sum(total) as price,
sum(discount) as saving FROM @.items;
sum(discount0) as saving FROM @.items;

Users := SELECT DISTINCT customerid AS id FROM Orders;
Users.purchases := JOIN Orders ON Orders.customerid = @.id ORDER BY Orders.time; -- time ordering
Expand Down
16 changes: 8 additions & 8 deletions sqrl-examples/quickstart/quickstart-user.sqrl
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
IMPORT datasqrl.seedshop.Orders TIMESTAMP time + INTERVAL 8 DAY AS time;
IMPORT datasqrl.seedshop.Orders TIMESTAMP time + INTERVAL 8 DAY AS timestamp;
IMPORT datasqrl.seedshop.Products;
IMPORT time.*;
IMPORT mySourcePackage.Customers AS Users TIMESTAMP epochMilliToTimestamp(changed_on) AS timestamp;

Orders.items.discount := discount?0.0;
Orders.items.total := quantity * unit_price - discount;
Orders.items.discount0 := discount?0.0;
Orders.items.total := quantity * unit_price - discount0;
Orders.totals := SELECT sum(total) as price,
sum(discount) as saving FROM @.items;
sum(discount0) as saving FROM @.items;

-- Replacing users from import
Users := DISTINCT Users ON id ORDER BY timestamp DESC;
Users.purchases := JOIN Orders ON Orders.customerid = @.id;
Users.country := country?'none';
Users.country0 := country?'none';
Orders.user := JOIN Users ON @.customerid = Users.id;

Users.spending := SELECT endOfWeek(p.time) AS week,
Users.spending := SELECT endOfWeek(p.timestamp) AS week,
sum(t.price) AS spend, sum(t.saving) AS saved
FROM @.purchases p JOIN p.totals t
GROUP BY week ORDER BY week DESC;
Expand All @@ -34,7 +34,7 @@ Products.ordered_items := JOIN Orders.items i ON i.productid = @.id;
--

-- aggregating by country
Products.volume_10day := SELECT u.country, sum(i.quantity) as quantity,
Products.volume_10day := SELECT u.country0 AS country, sum(i.quantity) as quantity,
sum(i.total) as spend, sum(i.quantity * @.weight_in_gram) as weight
FROM @ JOIN @.ordered_items i JOIN i.parent o JOIN o.user u
WHERE o.time > now() - INTERVAL 10 DAY GROUP BY u.country;
WHERE o.timestamp > now() - INTERVAL 10 DAY GROUP BY u.country0;
Loading

0 comments on commit 2d7314f

Please sign in to comment.