Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for infinite loop replication #481

Merged
merged 3 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class TestCmd {

private static final Path OUTPUT_DIR = Paths.get("src", "test", "resources", "output");
private static final Path SUBSCRIPTION_PATH = Paths.get("src/test/resources/subscriptions");
private static final Path CC_PATH = Paths.get("src/test/resources/creditcard");

protected Path buildDir = null;
SnapshotTest.Snapshot snapshot;
Expand Down Expand Up @@ -174,6 +175,14 @@ public void discoverRetail() {
createSnapshot();
}

// SQRL #479 - Infinite loop replication
@Test
public void testCreditCardInfiniteLoop() {
Path basePath = CC_PATH;
execute(basePath,
"compile", basePath.resolve("creditcard.sqrl").toString(), basePath.resolve("creditcard.graphqls").toString());
}

public static int execute(Path rootDir, String... args) {
return execute(rootDir, AssertStatusHook.INSTANCE, args);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type Query {
CustomerSpending(customerid: Int!, fromTime: String!, toTime: String!, limit: Int = 10, offset: Int = 0): [CustomerSpending!]
}

type CustomerSpending {
category: String!
spending: Float!
}
19 changes: 19 additions & 0 deletions sqrl-tools/sqrl-cli/src/test/resources/creditcard/creditcard.sqrl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
IMPORT creditcard.Merchant;
IMPORT creditcard.Assignment AS CardAssignment;
IMPORT creditcard.Transaction;
IMPORT time.*;

Merchant := DISTINCT Merchant ON merchantId ORDER BY updatedTime DESC;
CardAssignment := DISTINCT CardAssignment ON cardNo ORDER BY timestamp DESC;

CustomerSpendingByDay := SELECT customerid, endOfDay(time) as timeDay, category, SUM(amount) as spending
FROM Transaction t
JOIN CardAssignment c ON t.cardNo = c.cardNo
JOIN Merchant m ON t.merchantId = m.merchantid
GROUP BY customerid, timeDay, category;

CustomerSpending(@customerid: BIGINT, @fromTime: TIMESTAMP, @toTime: TIMESTAMP) :=
SELECT category, SUM(spending) as spending
FROM CustomerSpendingByDay WHERE customerid = @customerid AND @fromTime <= timeDay AND @toTime > timeDay
GROUP BY category ORDER BY category ASC;

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: "assignment"
schema_version: "1"
partial_schema: false
columns:
- name: "customerId"
type: "BIGINT"
tests:
- "not_null"
- name: "cardNo"
type: "STRING"
tests:
- "not_null"
- name: "timestamp"
type: "TIMESTAMP"
tests:
- "not_null"
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"format" : {
"name" : "json"
},
"schema" : "flexible",
"identifier" : "assignment",
"type" : "source",
"connector" : {
"name" : "file",
"directoryURI" : "../../sqrl-examples/creditcard/data"
},
"canonicalizer" : "system"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
name: "merchant"
schema_version: "1"
partial_schema: false
columns:
- name: "merchantId"
type: "BIGINT"
tests:
- "not_null"
- name: "name"
type: "STRING"
tests:
- "not_null"
- name: "category"
type: "STRING"
tests:
- "not_null"
- name: "updatedTime"
type: "TIMESTAMP"
tests:
- "not_null"
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"format" : {
"name" : "json"
},
"schema" : "flexible",
"identifier" : "merchant",
"type" : "source",
"connector" : {
"name" : "file",
"directoryURI" : "../../sqrl-examples/creditcard/data"
},
"canonicalizer" : "system"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
name: "transaction"
schema_version: "1"
partial_schema: false
columns:
- name: "transactionId"
type: "BIGINT"
tests:
- "not_null"
- name: "cardNo"
type: "STRING"
tests:
- "not_null"
- name: "time"
type: "TIMESTAMP"
tests:
- "not_null"
- name: "amount"
type: "DOUBLE"
tests:
- "not_null"
- name: "merchantId"
type: "BIGINT"
tests:
- "not_null"
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"format" : {
"name" : "json"
},
"schema" : "flexible",
"identifier" : "transaction",
"type" : "source",
"connector" : {
"name" : "file",
"directoryURI" : "../../sqrl-examples/creditcard/data"
},
"canonicalizer" : "system"
}