Skip to content

Assignment done; test cases passed 20/20 #70

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
Empty file added .github/.keep
Empty file.
223 changes: 212 additions & 11 deletions .github/workflows/classroom.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,220 @@
name: GitHub Classroom Workflow

on:
- push
- workflow_dispatch

name: Autograding Tests
'on':
- push
- workflow_dispatch
- repository_dispatch
permissions:
checks: write
actions: read
contents: read

jobs:
build:
name: Autograding
run-autograding-tests:
runs-on: ubuntu-latest
if: github.actor != 'github-classroom[bot]'
steps:
- uses: actions/checkout@v4
- uses: education/autograding@v1
- name: Checkout code
uses: actions/checkout@v4
- name: Step-1 Test
id: step-1-test
uses: classroom-resources/autograding-command-grader@v1
with:
test-name: Step-1 Test
setup-command: npm install
command: npm run test:1
timeout: 10
max-score: 10
- name: Step-2 Test
id: step-2-test
uses: classroom-resources/autograding-command-grader@v1
with:
test-name: Step-2 Test
setup-command: npm install
command: npm run test:2
timeout: 10
max-score: 10
- name: Step-3 Test
id: step-3-test
uses: classroom-resources/autograding-command-grader@v1
with:
test-name: Step-3 Test
setup-command: npm install
command: npm run test:3
timeout: 10
max-score: 10
- name: Step-4 Test
id: step-4-test
uses: classroom-resources/autograding-command-grader@v1
with:
test-name: Step-4 Test
setup-command: npm install
command: npm run test:4
timeout: 10
- name: Step-5 Test
id: step-5-test
uses: classroom-resources/autograding-command-grader@v1
with:
test-name: Step-5 Test
setup-command: npm install
command: npm run test:5
timeout: 10
max-score: 10
- name: Step-6 Test
id: step-6-test
uses: classroom-resources/autograding-command-grader@v1
with:
test-name: Step-6 Test
setup-command: npm install
command: npm run test:6
timeout: 10
max-score: 10
- name: Step-7 Test
id: step-7-test
uses: classroom-resources/autograding-command-grader@v1
with:
test-name: Step-7 Test
setup-command: npm install
command: npm run test:7
timeout: 10
max-score: 10
- name: Step-8 Test
id: step-8-test
uses: classroom-resources/autograding-command-grader@v1
with:
test-name: Step-8 Test
setup-command: npm install
command: npm run test:8
timeout: 10
max-score: 10
- name: Step-9 Test
id: step-9-test
uses: classroom-resources/autograding-command-grader@v1
with:
test-name: Step-9 Test
setup-command: npm install
command: npm run test:9
timeout: 10
max-score: 10
- name: Step-10 Test
id: step-10-test
uses: classroom-resources/autograding-command-grader@v1
with:
test-name: Step-10 Test
setup-command: npm install
command: npm run test:10
timeout: 10
max-score: 10
- name: Step-11 Test
id: step-11-test
uses: classroom-resources/autograding-command-grader@v1
with:
test-name: Step-11 Test
setup-command: npm install
command: npm run test:11
timeout: 10
max-score: 10
- name: Step-12 Test
id: step-12-test
uses: classroom-resources/autograding-command-grader@v1
with:
test-name: Step-12 Test
setup-command: npm install
command: npm run test:12
timeout: 10
max-score: 10
- name: Step-13 Test
id: step-13-test
uses: classroom-resources/autograding-command-grader@v1
with:
test-name: Step-13 Test
setup-command: npm install
command: npm run test:13
timeout: 10
max-score: 10
- name: Step-14 Test
id: step-14-test
uses: classroom-resources/autograding-command-grader@v1
with:
test-name: Step-14 Test
setup-command: npm install
command: npm run test:14
timeout: 10
max-score: 10
- name: Step-15 Test
id: step-15-test
uses: classroom-resources/autograding-command-grader@v1
with:
test-name: Step-15 Test
setup-command: npm install
command: npm run test:15
timeout: 10
max-score: 10
- name: Step-16 Test
id: step-16-test
uses: classroom-resources/autograding-command-grader@v1
with:
test-name: Step-16 Test
setup-command: npm install
command: npm run test:16
timeout: 10
max-score: 10
- name: Step-17 Test
id: step-17-test
uses: classroom-resources/autograding-command-grader@v1
with:
test-name: Step-17 Test
setup-command: npm install
command: npm run test:17
timeout: 10
max-score: 10
- name: Step-18 Test
id: step-18-test
uses: classroom-resources/autograding-command-grader@v1
with:
test-name: Step-18 Test
setup-command: npm install
command: npm run test:18
timeout: 10
max-score: 10
- name: Step-19 Test
id: step-19-test
uses: classroom-resources/autograding-command-grader@v1
with:
test-name: Step-19 Test
setup-command: npm install
command: npm run test:19
timeout: 10
max-score: 10
- name: Step-20 Test
id: step-20-test
uses: classroom-resources/autograding-command-grader@v1
with:
test-name: Step-20 Test
setup-command: npm install
command: npm run test:20
timeout: 10
max-score: 10
- name: Autograding Reporter
uses: classroom-resources/autograding-grading-reporter@v1
env:
STEP-1-TEST_RESULTS: "${{steps.step-1-test.outputs.result}}"
STEP-2-TEST_RESULTS: "${{steps.step-2-test.outputs.result}}"
STEP-3-TEST_RESULTS: "${{steps.step-3-test.outputs.result}}"
STEP-4-TEST_RESULTS: "${{steps.step-4-test.outputs.result}}"
STEP-5-TEST_RESULTS: "${{steps.step-5-test.outputs.result}}"
STEP-6-TEST_RESULTS: "${{steps.step-6-test.outputs.result}}"
STEP-7-TEST_RESULTS: "${{steps.step-7-test.outputs.result}}"
STEP-8-TEST_RESULTS: "${{steps.step-8-test.outputs.result}}"
STEP-9-TEST_RESULTS: "${{steps.step-9-test.outputs.result}}"
STEP-10-TEST_RESULTS: "${{steps.step-10-test.outputs.result}}"
STEP-11-TEST_RESULTS: "${{steps.step-11-test.outputs.result}}"
STEP-12-TEST_RESULTS: "${{steps.step-12-test.outputs.result}}"
STEP-13-TEST_RESULTS: "${{steps.step-13-test.outputs.result}}"
STEP-14-TEST_RESULTS: "${{steps.step-14-test.outputs.result}}"
STEP-15-TEST_RESULTS: "${{steps.step-15-test.outputs.result}}"
STEP-16-TEST_RESULTS: "${{steps.step-16-test.outputs.result}}"
STEP-17-TEST_RESULTS: "${{steps.step-17-test.outputs.result}}"
STEP-18-TEST_RESULTS: "${{steps.step-18-test.outputs.result}}"
STEP-19-TEST_RESULTS: "${{steps.step-19-test.outputs.result}}"
STEP-20-TEST_RESULTS: "${{steps.step-20-test.outputs.result}}"
with:
runners: step-1-test,step-2-test,step-3-test,step-4-test,step-5-test,step-6-test,step-7-test,step-8-test,step-9-test,step-10-test,step-11-test,step-12-test,step-13-test,step-14-test,step-15-test,step-16-test,step-17-test,step-18-test,step-19-test,step-20-test
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[![Open in Visual Studio Code](https://classroom.github.com/assets/open-in-vscode-718a45dd9cf7e7f842a935f5ebbe5719a5e09af4491e668f4dbf3b35d5cca122.svg)](https://classroom.github.com/online_ide?assignment_repo_id=14966543&assignment_repo_type=AssignmentRepo)
<h1 align="center">StylusDB SQL</h1>
<p align="center">
A SQL database engine written in JavaScript
Expand Down
6 changes: 6 additions & 0 deletions enrollment.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
student_id,course
1,Mathematics
1,Physics
2,Chemistry
3,Mathematics
5,Biology
4 changes: 4 additions & 0 deletions sample.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
id,name,age
1,John,30
2,Jane,25
3,Bob,22
29 changes: 29 additions & 0 deletions src/JoinMethods/performInnerJoin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function performInnerJoin(
data,
joinData,
joinCondition,
fields,
leftTableName
) {
// Logic for INNER JOIN
return data.flatMap((leftTableRow) => {
return joinData
.filter((rightTableRow) => {
const leftValue = leftTableRow[joinCondition.left.split(".")[1]];
const rightValue = rightTableRow[joinCondition.right.split(".")[1]];
return leftValue === rightValue;
})
.map((rightTableRow) => {
return fields.reduce((acc, field) => {
const [tableName, fieldName] = field.split(".");
acc[field] =
tableName === leftTableName
? leftTableRow[fieldName]
: rightTableRow[fieldName];
return acc;
}, {});
});
});
}

module.exports = performInnerJoin;
36 changes: 36 additions & 0 deletions src/JoinMethods/performLeftJoin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
function performLeftJoin(data, joinData, joinCondition, fields, leftTableName) {
// Logic for LEFT JOIN

return data.flatMap((leftTableRow) => {
const filteredData = joinData.filter((rightTableRow) => {
const leftValue = leftTableRow[joinCondition.left.split(".")[1]];
const rightValue = rightTableRow[joinCondition.right.split(".")[1]];
return leftValue === rightValue;
});

if (filteredData.length == 0) {
return fields.reduce((acc, field) => {
const [tableName, fieldName] = field.split(".");
acc[field] =
tableName === leftTableName ? leftTableRow[fieldName] : null;

return acc;
}, {});
}

return filteredData.map((rightTableRow) => {
return fields.reduce((acc, field) => {
const [tableName, fieldName] = field.split(".");

acc[field] =
tableName === leftTableName
? leftTableRow[fieldName]
: rightTableRow[fieldName];

return acc;
}, {});
});
});
}

module.exports = performLeftJoin;
42 changes: 42 additions & 0 deletions src/JoinMethods/performRightJoin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const performLeftJoin = require("./performLeftJoin");

function performRightJoin(
data,
joinData,
joinCondition,
fields,
rightTableName
) {
return joinData.flatMap((rightTableRow) => {
const filteredData = data.filter((leftTableRow) => {
const leftValue = leftTableRow[joinCondition.left.split(".")[1]];
const rightValue = rightTableRow[joinCondition.right.split(".")[1]];
return leftValue === rightValue;
});

if (filteredData.length == 0) {
return fields.reduce((acc, field) => {
const [tableName, fieldName] = field.split(".");
acc[field] =
tableName === rightTableName ? rightTableRow[fieldName] : null;

return acc;
}, {});
}

return filteredData.map((leftTableRow) => {
return fields.reduce((acc, field) => {
const [tableName, fieldName] = field.split(".");

acc[field] =
tableName === rightTableName
? rightTableRow[fieldName]
: leftTableRow[fieldName];

return acc;
}, {});
});
});
}

module.exports = performRightJoin;
20 changes: 20 additions & 0 deletions src/aggregateMethods.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
aggregateMethods = {
count: function (data) {
return data.length;
},
sum: function (data, column) {
return data.reduce((acc, item) => acc + Number(item[column]), 0);
},
avg: function (data, column) {
const add = this.sum(data, column);
return add / data.length;
},
min: function (data, column) {
return Math.min(...data.map((item) => item[column]));
},
max: function (data, column) {
return Math.max(...data.map((item) => item[column]));
},
};

module.exports = aggregateMethods;
Loading