Skip to content

Commit 438e384

Browse files
authored
Merge pull request #168 from carlosms/example-queries
Set the example queries
2 parents 57692bc + d11ad5d commit 438e384

File tree

1 file changed

+56
-18
lines changed

1 file changed

+56
-18
lines changed

frontend/src/App.js

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,30 +72,68 @@ class App extends Component {
7272

7373
this.exampleQueries = [
7474
{
75-
name: 'Number of commits per month',
76-
sql: `/* Contributor's number of commits, each month of 2018, for each repository */
77-
78-
SELECT COUNT(*) as num_commits, month, repo_id, committer_name
79-
FROM ( SELECT MONTH(committer_when) as month,
80-
r.repository_id as repo_id,
81-
committer_name
82-
FROM ref_commits r
83-
INNER JOIN commits c
84-
ON YEAR(c.committer_when) = 2018 AND r.commit_hash = c.commit_hash
85-
WHERE r.ref_name = 'HEAD'
86-
) as t GROUP BY committer_name, month, repo_id`
75+
name: 'Files named main.go',
76+
sql: `/* Files named main.go in HEAD */
77+
SELECT t.repository_id, t.tree_entry_name,
78+
LANGUAGE(t.tree_entry_name, b.blob_content) AS lang, b.blob_content,
79+
UAST(b.blob_content, LANGUAGE(t.tree_entry_name, b.blob_content)) AS uast
80+
FROM tree_entries AS t
81+
JOIN blobs b ON tree_entries.blob_hash = blobs.blob_hash
82+
JOIN commit_trees ON tree_entries.tree_hash = commit_trees.tree_hash
83+
JOIN refs ON commit_trees.commit_hash = refs.commit_hash
84+
WHERE ref_name = 'HEAD'
85+
AND tree_entries.tree_entry_name = 'main.go'`
8786
},
8887
{
89-
name: 'load all java files',
90-
sql: '/* To be done */'
88+
name: 'Last commit for each repository',
89+
sql: `/* Last commit for each repository */
90+
SELECT r.repository_id, commit_author_name, commit_author_when, commit_message
91+
FROM refs r
92+
natural JOIN commits
93+
WHERE r.ref_name = 'HEAD' `
9194
},
9295
{
93-
name: 'get uast from code',
94-
sql: '/* To be done */'
96+
name: 'Top repositories by commits',
97+
sql: `/* Top repositories by number of commits in HEAD */
98+
SELECT repository_id, commit_count
99+
FROM (SELECT r.repository_id, COUNT(*) AS commit_count
100+
FROM refs r
101+
JOIN ref_commits AS c ON r.ref_name = c.ref_name
102+
WHERE r.ref_name = 'HEAD'
103+
GROUP BY r.repository_id) AS q
104+
ORDER BY commit_count DESC
105+
LIMIT 10 `
95106
},
96107
{
97-
name: 'top 50 repositories by something very long string',
98-
sql: '/* To be done */'
108+
name: 'Top languages by repository count',
109+
sql: `/* Top languages by repository count */
110+
SELECT *
111+
FROM (SELECT language, COUNT(repository_id) AS repository_count
112+
FROM (SELECT DISTINCT
113+
r.repository_id,
114+
LANGUAGE(t.tree_entry_name, b.blob_content) AS language
115+
FROM refs r
116+
JOIN commits c ON r.commit_hash = c.commit_hash
117+
JOIN commit_trees ct ON c.commit_hash = ct.commit_hash
118+
JOIN tree_entries t ON ct.tree_hash = t.tree_hash
119+
JOIN blobs b ON t.blob_hash = b.blob_hash
120+
WHERE r.ref_name = 'HEAD') AS q1
121+
GROUP BY language) AS q2
122+
ORDER BY repository_count DESC `
123+
},
124+
{
125+
name: 'Number of commits per month',
126+
sql: `/* Commits per committer, each month of 2018, for each repository */
127+
SELECT COUNT(*) as num_commits, month, repository_id, committer_name, committer_email
128+
FROM ( SELECT MONTH(committer_when) as month,
129+
r.repository_id,
130+
committer_name,
131+
committer_email
132+
FROM ref_commits r
133+
INNER JOIN commits c
134+
ON YEAR(c.committer_when) = 2018 AND r.commit_hash = c.commit_hash
135+
WHERE r.ref_name = 'HEAD'
136+
) as t GROUP BY committer_email, committer_name, month, repository_id`
99137
}
100138
];
101139
}

0 commit comments

Comments
 (0)