Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
cdouglas committed Jul 10, 2024
1 parent 430e2c5 commit a3861d9
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 162 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(in_warehouse_static, in_warehouse, in_district_static, in_district_next_id, in_district_ytd, in_customer, in_transaction_parameters, out_ncustomers, out_cust_enum, out_cust_agg, out_cust_med, out_cust_med, out_cust_max, out_median_pos)
(in_warehouse_static, in_warehouse, in_district_static, in_district_next_id, in_district_ytd, in_customer, in_transaction_parameters, out_cust_agg, out_cust_byname)
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(in_warehouse_static, in_warehouse, in_district_static, in_district_next_id, in_district_ytd, in_customer, in_transaction_parameters, out_ncustomers, out_cust_enum, out_cust_agg, out_cust_med, out_cust_med, out_cust_max, out_median_pos)
(in_warehouse_static, in_warehouse, in_district_static, in_district_next_id, in_district_ytd, in_customer, in_transaction_parameters, out_cust_agg, out_cust_byname)
110 changes: 1 addition & 109 deletions incremental_transactions/tpcc/sql/byname.sql
Original file line number Diff line number Diff line change
@@ -1,28 +1,3 @@
-- Ignoring byname for now
-- if (byname)
-- {


-- CREATE VIEW ncustomers AS -- SELECT count(c_id) INTO :namecnt
-- SELECT count(c_id) AS name_cnt -- FROM customer
-- FROM customer AS c, -- WHERE c_last=:c_last AND c_d_id=:c_d_id AND c_w_id=:c_w_id;
-- transaction_parameters as t
-- WHERE c.c_last = t.c_last
-- AND c.c_d_id = t.c_d_id
-- AND c.c_w_id = t.c_w_id;

-- CREATE VIEW cust_enum AS
-- SELECT c.c_first, c.c_middle, c.c_id,
-- c.c_street_1, c.c_street_2, c.c_city, c.c_state, c.c_zip,
-- c.c_phone, c.c_credit, c.c_credit_lim,
-- c.c_discount, c.c_balance, c.c_since
-- FROM customer AS c,
-- transaction_parameters AS t
-- WHERE c.c_last = t.c_last
-- AND c.c_d_id = t.c_d_id
-- AND c.c_w_id = t.c_w_id
-- ORDER BY c_first;

CREATE VIEW cust_agg AS
SELECT ARRAY_AGG(c_id ORDER BY c_first) AS cust_array
FROM (SELECT c.c_id, c.c_first
Expand All @@ -33,7 +8,7 @@ FROM (SELECT c.c_id, c.c_first
AND c.c_w_id = t.c_w_id
ORDER BY c_first);

CREATE VIEW cust_med AS
CREATE VIEW cust_byname AS
SELECT c.c_first, c.c_middle, c.c_id,
c.c_street_1, c.c_street_2, c.c_city, c.c_state, c.c_zip,
c.c_phone, c.c_credit, c.c_credit_lim,
Expand All @@ -42,86 +17,3 @@ FROM customer as c,
cust_agg as a,
transaction_parameters as t
WHERE c.c_id = a.cust_array[(ARRAY_LENGTH(a.cust_array) / 2) + 1];

-- CREATE VIEW cust_med AS
-- SELECT c.c_first, c.c_middle, c.c_id,
-- c.c_street_1, c.c_street_2, c.c_city, c.c_state, c.c_zip,
-- c.c_phone, c.c_credit, c.c_credit_lim,
-- c.c_discount, c.c_balance, c.c_since
-- FROM cust_agg AS a,
-- cust_enum AS c,
-- transaction_parameters AS t
-- WHERE c.c_id = a.cust_array[FLOOR(ARRAY_LENGTH(a.cust_array) / 2) + 1];
--
-- create view cust_max as
-- SELECT c.c_first, c.c_middle, c.c_id,
-- c.c_street_1, c.c_street_2, c.c_city, c.c_state, c.c_zip,
-- c.c_phone, c.c_credit, c.c_credit_lim,
-- c.c_discount, c.c_balance, c.c_since
-- FROM customer AS c,
-- transaction_parameters AS t
-- WHERE c.c_last = t.c_last
-- AND c.c_d_id = t.c_d_id
-- AND c.c_w_id = t.c_w_id
-- AND c_first = (select max(c_first) from customer LIMIT 1)
-- LIMIT 1;

-- CREATE VIEW cust_max AS
-- SELECT c_first, c_last
-- FROM customer
-- ORDER BY c_first
-- LIMIT 1;

-- SELECT c_first, c_middle, c_id,
-- c_street_1, c_street_2, c_city, c_state, c_zip,
-- c_phone, c_credit, c_credit_lim,
-- c_discount, c_balance, c_since


-- DECLARE c_byname CURSOR FOR
-- SELECT c_first, c_middle, c_id,
-- c_street_1, c_street_2, c_city, c_state, c_zip,
-- c_phone, c_credit, c_credit_lim,
-- c_discount, c_balance, c_since
-- FROM customer
-- WHERE c_w_id=:c_w_id AND c_d_id=:c_d_id AND c_last=:c_last
-- ORDER BY c_first;

-- CREATE VIEW median_pos AS
-- SELECT c_first, c_middle, c_id,
-- c_street_1, c_street_2, c_city, c_state, c_zip,
-- c_phone, c_credit, c_credit_lim,
-- c_discount, c_balance, c_since
-- FROM cust_last
-- ORDER BY c_first
-- LIMIT 1 OFFSET (
-- SELECT FLOOR((COUNT(*) - 1) / 2)
-- FROM cust_last
-- );

-- OPEN c_byname;
--
-- if (namecnt%2) namecnt++; --Locate midpoint customer;
-- for (n=0; n<namecnt/2; n++)
-- {
-- EXEC SQL FETCH c_byname
-- INTO :c_first, :c_middle, :c_id,
-- :c_street_1, :c_street_2, :c_city, :c_state, :c_zip,
-- :c_phone, :c_credit, :c_credit_lim,
-- :c_discount, :c_balance, :c_since;
-- }
-- EXEC SQL CLOSE c_byname;
--}
/*
else
{
EXEC SQL SELECT c_first, c_middle, c_last, c_street_1, c_street_2, c_city, c_state, c_zip,
c_phone, c_credit, c_credit_lim,
c_discount, c_balance, c_since
INTO :c_first, :c_middle, :c_last,
:c_street_1, :c_street_2, :c_city, :c_state, :c_zip,
:c_phone, :c_credit, :c_credit_lim,
:c_discount, :c_balance, :c_since
FROM customer
WHERE c_w_id=:c_w_id AND c_d_id=:c_d_id AND c_id=:c_id;
} */
120 changes: 71 additions & 49 deletions incremental_transactions/tpcc/sql/payment.sql
Original file line number Diff line number Diff line change
@@ -1,68 +1,86 @@
-- gettimestamp(datetime);
-- Make transaction parameters a table to join against
CREATE TABLE transaction_parameters (
txn_id INT PRIMARY KEY,
w_id INT,
d_id INT,
c_id INT,
c_w_id INT,
c_d_id INT,
h_amount DECIMAL(5,2),
h_date TIMESTAMP,
datetime_ TIMESTAMP
);

/* UPDATE warehouse SET w_ytd = w_ytd + :h_amount
WHERE w_id=:w_id; */
CREATE VIEW warehouse_updates AS SELECT t.txn_id, w.w_id, (w.w_ytd + t.h_amount) AS w_ytd FROM warehouse AS w, transaction_parameters AS t WHERE w.w_id=t.w_id;
CREATE VIEW warehouse_updates AS SELECT t.txn_id, w.w_id, (w.w_ytd + t.h_amount) AS w_ytd
FROM warehouse AS w, transaction_parameters AS t
WHERE w.w_id=t.w_id;

/* SELECT w_street_1, w_street_2, w_city, w_state, w_zip, w_name
INTO :w_street_1, :w_street_2, :w_city, :w_state, :w_zip, :w_name
FROM warehouse
WHERE w_id=:w_id; */
CREATE VIEW warehouse_select AS SELECT w.w_street_1, w.w_street_2, w.w_city, w.w_state, w.w_zip, w.w_name, t.txn_id FROM warehouse_static AS w, transaction_parameters AS t WHERE w.w_id=t.w_id;
CREATE VIEW warehouse_select AS SELECT w.w_street_1, w.w_street_2, w.w_city, w.w_state, w.w_zip, w.w_name, t.txn_id
FROM warehouse_static AS w, transaction_parameters AS t
WHERE w.w_id=t.w_id;

/* UPDATE district SET d_ytd = d_ytd + :h_amount
WHERE d_w_id=:w_id AND d_id=:d_id; */
CREATE VIEW district_updates AS SELECT d.d_w_id, d.d_id, (d.d_ytd + t.h_amount) AS d_ytd FROM district_ytd AS d, transaction_parameters AS t WHERE d.d_w_id=t.w_id AND d.d_id=t.d_id;
CREATE VIEW district_updates AS SELECT d.d_w_id, d.d_id, (d.d_ytd + t.h_amount) AS d_ytd
FROM district_ytd AS d, transaction_parameters AS t
WHERE d.d_w_id=t.w_id AND d.d_id=t.d_id;

/* SELECT d_street_1, d_street_2, d_city, d_state, d_zip, d_name
INTO :d_street_1, :d_street_2, :d_city, :d_state, :d_zip, :d_name
FROM district
WHERE d_w_id=:w_id AND d_id=:d_id; */
CREATE VIEW district_select AS SELECT d.d_street_1, d.d_street_2, d.d_city, d.d_state, d.d_zip, d.d_name, t.txn_id FROM district_static AS d, transaction_parameters AS t WHERE d.d_w_id=t.w_id AND d.d_id=t.d_id;
CREATE VIEW district_select AS SELECT d.d_street_1, d.d_street_2, d.d_city, d.d_state, d.d_zip, d.d_name, t.txn_id
FROM district_static AS d, transaction_parameters AS t
WHERE d.d_w_id=t.w_id AND d.d_id=t.d_id;

-- Ignoring byname for now
/* if (byname)
{
SELECT count(c_id) INTO :namecnt
FROM customer
WHERE c_last=:c_last AND c_d_id=:c_d_id AND c_w_id=:c_w_id;
DECLARE c_byname CURSOR FOR
SELECT c_first, c_middle, c_id,
c_street_1, c_street_2, c_city, c_state, c_zip,
c_phone, c_credit, c_credit_lim,
c_discount, c_balance, c_since
FROM customer
WHERE c_w_id=:c_w_id AND c_d_id=:c_d_id AND c_last=:c_last
ORDER BY c_first;
OPEN c_byname;
if (namecnt%2) namecnt++; --Locate midpoint customer;
for (n=0; n<namecnt/2; n++)
{
EXEC SQL FETCH c_byname
INTO :c_first, :c_middle, :c_id,
:c_street_1, :c_street_2, :c_city, :c_state, :c_zip,
:c_phone, :c_credit, :c_credit_lim,
:c_discount, :c_balance, :c_since;
}
EXEC SQL CLOSE c_byname;
}
else
{
EXEC SQL SELECT c_first, c_middle, c_last, c_street_1, c_street_2, c_city, c_state, c_zip,
c_phone, c_credit, c_credit_lim,
c_discount, c_balance, c_since
INTO :c_first, :c_middle, :c_last,
:c_street_1, :c_street_2, :c_city, :c_state, :c_zip,
:c_phone, :c_credit, :c_credit_lim,
:c_discount, :c_balance, :c_since
FROM customer
WHERE c_w_id=:c_w_id AND c_d_id=:c_d_id AND c_id=:c_id;
} */
-- Using the simpler by-id else branch for now
CREATE VIEW customer_select AS SELECT c.c_first, c.c_middle, c.c_last, c.c_street_1, c.c_street_2, c.c_city, c.c_state, c.c_zip, c.c_phone, c.c_credit, c.c_credit_lim, c.c_discount, c.c_balance, c.c_since, t.txn_id FROM customer AS c, transaction_parameters AS t WHERE c.c_w_id=t.c_w_id AND c.c_d_id=t.c_d_id AND c.c_id=t.c_id;
CREATE VIEW cust_agg AS -- if (byname)
SELECT ARRAY_AGG(c_id ORDER BY c_first) AS cust_array -- {
FROM (SELECT c.c_id, c.c_first -- SELECT count(c_id) INTO :namecnt
FROM customer AS c, -- FROM customer
transaction_parameters AS t -- WHERE c_last=:c_last AND c_d_id=:c_d_id AND c_w_id=:c_w_id;
WHERE c.c_last = t.c_last --
AND c.c_d_id = t.c_d_id -- DECLARE c_byname CURSOR FOR
AND c.c_w_id = t.c_w_id -- SELECT c_first, c_middle, c_id,
ORDER BY c_first); -- c_street_1, c_street_2, c_city, c_state, c_zip,
-- c_phone, c_credit, c_credit_lim,
CREATE VIEW cust_byname AS -- c_discount, c_balance, c_since
SELECT c.c_first, c.c_middle, c.c_id, -- FROM customer
c.c_street_1, c.c_street_2, c.c_city, c.c_state, c.c_zip, -- WHERE c_w_id=:c_w_id AND c_d_id=:c_d_id AND c_last=:c_last
c.c_phone, c.c_credit, c.c_credit_lim, -- ORDER BY c_first;
c.c_discount, c.c_balance, c.c_since, t.txn_id --
FROM customer as c, -- OPEN c_byname;
cust_agg as a, --
transaction_parameters as t -- if (namecnt%2) namecnt++; --Locate midpoint customer;
WHERE c.c_id = a.cust_array[(ARRAY_LENGTH(a.cust_array) / 2) + 1]; -- for (n=0; n<namecnt/2; n++)
-- {
-- EXEC SQL FETCH c_byname
-- INTO :c_first, :c_middle, :c_id,
-- :c_street_1, :c_street_2, :c_city, :c_state, :c_zip,
-- :c_phone, :c_credit, :c_credit_lim,
-- :c_discount, :c_balance, :c_since;
-- }
-- EXEC SQL CLOSE c_byname;
-- }
CREATE VIEW customer_select AS -- else
SELECT c.c_first, c.c_middle, c.c_id, -- {
c.c_street_1, c.c_street_2, c.c_city, c.c_state, c.c_zip, -- EXEC SQL SELECT c_first, c_middle, c_last, c_street_1, c_street_2, c_city, c_state, c_zip,
c.c_phone, c.c_credit, c.c_credit_lim, -- c_phone, c_credit, c_credit_lim,
c.c_discount, c.c_balance, c.c_since, t.txn_id -- c_discount, c_balance, c_since
FROM customer AS c, -- INTO :c_first, :c_middle, :c_last,
transaction_parameters AS t -- :c_street_1, :c_street_2, :c_city, :c_state, :c_zip,
WHERE c.c_w_id=t.c_w_id AND c.c_d_id=t.c_d_id AND c.c_id=t.c_id; -- :c_phone, :c_credit, :c_credit_lim,
-- :c_discount, :c_balance, :c_since
-- FROM customer
-- WHERE c_w_id=:c_w_id AND c_d_id=:c_d_id AND c_id=:c_id;
-- }
-- Using the simpler by-id else branch for now

-- Ignoring the BC credit branch for now, using the simpler else branch
/* c_balance += h_amount;
Expand All @@ -88,7 +106,9 @@ else
c_id = :c_id;
} */
-- TODO: Create a new customer record with the updated balance
CREATE VIEW customer_update AS SELECT c.c_first, c.c_middle, c.c_last, c.c_street_1, c.c_street_2, c.c_city, c.c_state, c.c_zip, c.c_phone, c.c_credit, c.c_credit_lim, c.c_discount, (c.c_balance + t.h_amount) as c_balance, c.c_since FROM customer_select AS c, transaction_parameters as t WHERE c.txn_id=t.txn_id;
CREATE VIEW customer_update AS SELECT c.c_first, c.c_middle, c.c_last, c.c_street_1, c.c_street_2, c.c_city, c.c_state, c.c_zip, c.c_phone, c.c_credit, c.c_credit_lim, c.c_discount, (c.c_balance + t.h_amount) as c_balance, c.c_since
FROM customer_select AS c, transaction_parameters as t
WHERE c.txn_id=t.txn_id;

/* strncpy(h_data,w_name,10);
h_data[10]='\0';
Expand All @@ -101,4 +121,6 @@ EXEC SQL INSERT INTO history (h_c_d_id, h_c_w_id, h_c_id, h_d_id,
h_w_id, h_date, h_amount, h_data)
VALUES (:c_d_id, :c_w_id, :c_id, :d_id,
:w_id, :datetime, :h_amount, :h_data); */
CREATE VIEW history_insert AS SELECT t.c_d_id AS h_c_d_id, t.c_w_id AS h_c_w_id, t.c_id AS h_c_id, t.d_id AS h_d_id, t.w_id AS h_w_id, t.datetime_ AS h_date, t.h_amount AS h_amount, CONCAT(w.w_name, d.d_name) AS h_data FROM transaction_parameters AS t, warehouse_select AS w, district_select AS d WHERE t.txn_id=w.txn_id AND t.txn_id=d.txn_id;
CREATE VIEW history_insert AS SELECT t.c_d_id AS h_c_d_id, t.c_w_id AS h_c_w_id, t.c_id AS h_c_id, t.d_id AS h_d_id, t.w_id AS h_w_id, t.datetime_ AS h_date, t.h_amount AS h_amount, CONCAT(w.w_name, d.d_name) AS h_data
FROM transaction_parameters AS t, warehouse_select AS w, district_select AS d
WHERE t.txn_id=w.txn_id AND t.txn_id=d.txn_id;
2 changes: 1 addition & 1 deletion incremental_transactions/tpcc/src/byname_sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ pub fn circuit(cconf: CircuitConfig) -> Result<(DBSPHandle, (ZSetHandle<Tup8<Opt
Tup14<Option<String>, Option<String>, Option<i32>, Option<String>, Option<String>, Option<String>, Option<String>, Option<String>, Option<String>, Option<String>, Option<Decimal>, Option<Decimal>, Option<Decimal>, Option<Timestamp>> {
Tup14::new((*t_18).3.clone().clone(), (*t_18).4.clone().clone(), (*t_18).0, (*t_18).6.clone().clone(), (*t_18).7.clone().clone(), (*t_18).8.clone().clone(), (*t_18).9.clone().clone(), (*t_18).10.clone().clone(), (*t_18).11.clone().clone(), (*t_18).13.clone().clone(), (*t_18).14.clone().clone(), (*t_18).15.clone().clone(), (*t_18).16.clone().clone(), (*t_18).12)
});
// CREATE VIEW `CUST_MED` AS
// CREATE VIEW `CUST_BYNAME` AS
// SELECT `C`.`C_FIRST`, `C`.`C_MIDDLE`, `C`.`C_ID`, `C`.`C_STREET_1`, `C`.`C_STREET_2`, `C`.`C_CITY`, `C`.`C_STATE`, `C`.`C_ZIP`, `C`.`C_PHONE`, `C`.`C_CREDIT`, `C`.`C_CREDIT_LIM`, `C`.`C_DISCOUNT`, `C`.`C_BALANCE`, `C`.`C_SINCE`
// FROM `schema`.`CUSTOMER` AS `C`,
// `schema`.`CUST_AGG` AS `A`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ pub fn circuit(cconf: CircuitConfig) -> Result<(DBSPHandle, (ZSetHandle<Tup8<Opt
Tup14<Option<String>, Option<String>, Option<i32>, Option<String>, Option<String>, Option<String>, Option<String>, Option<String>, Option<String>, Option<String>, Option<Decimal>, Option<Decimal>, Option<Decimal>, Option<Timestamp>> {
Tup14::new((*t_18).3.clone().clone(), (*t_18).4.clone().clone(), (*t_18).0, (*t_18).6.clone().clone(), (*t_18).7.clone().clone(), (*t_18).8.clone().clone(), (*t_18).9.clone().clone(), (*t_18).10.clone().clone(), (*t_18).11.clone().clone(), (*t_18).13.clone().clone(), (*t_18).14.clone().clone(), (*t_18).15.clone().clone(), (*t_18).16.clone().clone(), (*t_18).12)
});
// CREATE VIEW `CUST_MED` AS
// CREATE VIEW `CUST_BYNAME` AS
// SELECT `C`.`C_FIRST`, `C`.`C_MIDDLE`, `C`.`C_ID`, `C`.`C_STREET_1`, `C`.`C_STREET_2`, `C`.`C_CITY`, `C`.`C_STATE`, `C`.`C_ZIP`, `C`.`C_PHONE`, `C`.`C_CREDIT`, `C`.`C_CREDIT_LIM`, `C`.`C_DISCOUNT`, `C`.`C_BALANCE`, `C`.`C_SINCE`
// FROM `schema`.`CUSTOMER` AS `C`,
// `schema`.`CUST_AGG` AS `A`,
Expand Down
45 changes: 45 additions & 0 deletions incremental_transactions/tpcc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,49 @@ mod test {

circuit.step().unwrap();
}

#[test]
fn test_byname_sql() {
let cconf = CircuitConfig::with_workers(1);
let (mut circuit, handles) = byname_sql::circuit(cconf).unwrap();
let (
in_warehouse_static,
in_warehouse,
in_district_static,
in_district_next_id,
in_district_ytd,
in_customer,
in_transaction_parameters,
out_cust_agg,
out_cust_byname,
) = handles;
in_customer.push(
(
Some(1),
Some(43),
Some(44),
Some("Alice"),
Some("Q"),
Some("Public"),
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
)
.into(),
1,
);

circuit.step().unwrap();
}
}

0 comments on commit a3861d9

Please sign in to comment.