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

update dolt blame to use sql backend and accept specific revision #6065

Merged
merged 13 commits into from
Jun 3, 2023

Conversation

stephkyou
Copy link
Contributor

This change updates dolt blame to use the appropriate sql engine to generate results. This change also allows users to specify a specific revision to annotate from.

Related: #3922

@stephkyou stephkyou requested a review from macneale4 May 31, 2023 18:20
@stephkyou stephkyou marked this pull request as ready for review June 1, 2023 00:32
@@ -108,3 +108,29 @@ teardown() {
[[ "$output" =~ "defaultDB does not exist" ]] || false
}

@test "sql-local-remote: verify dolt blame behavior is identical in switch between server/no server" {
cd defaultDB
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a bug here where we are out of sync with other command behavior. You shouldn't need to cd defaultDB - and in fact I tested this and you get an error stating that you need to dolt init first. This is incorrect behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand why I don't need to do cd defaultDB first. I would need to be in a dolt repo to do dolt add and dolt commit right?

integration-tests/bats/blame.bats Show resolved Hide resolved
integration-tests/bats/blame.bats Show resolved Hide resolved
[ "$status" -eq 0 ]
[[ "$output" =~ "1".*"insert initial value into test" ]] || false
[[ "$output" =~ "2".*"insert more values into test" ]] || false
[[ "$output" =~ "3".*"insert more values into test" ]] || false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a simpler check would be to compare the total output of both blame calls. The line by line information will be the same if that checks out, and the tests as it stands now would allow for one implementation to drop the commit date and we'd never know it.

if apr.NArg() == 1 {
schema, ri, err = queryist.Query(sqlCtx, fmt.Sprintf(blameQueryTemplate, apr.Arg(0), "HEAD"))
} else {
schema, ri, err = queryist.Query(sqlCtx, fmt.Sprintf(blameQueryTemplate, apr.Arg(1), apr.Arg(0)))
Copy link
Contributor

@macneale4 macneale4 Jun 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to validate the input or we'll have a SQL injection bug here. There is hopefully code we can find around here which validates a revision value. Example of exploit:

$ dolt blame 'HEAD;insert into tbl values (....);' tbl

At the moment, this doesn't have any real impact because blame doesn't have a write transaction

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think when we parse the value given after AS OF it will catch invalid revision values right? I'm not too clear on what your given example shows.

Copy link
Contributor

@macneale4 macneale4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ship with whatever you come up to get around the use of dEnv.

schema, ri, err = queryist.Query(sqlCtx, fmt.Sprintf(blameQueryTemplate, apr.Arg(0), "HEAD"))
} else {
// validate input
_, err = ResolveCommitWithVErr(dEnv, apr.Arg(0))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See chat discussion. This is a very reliable way to validate the input - but it used dEnv which is off limits.


run dolt blame test
[ "$status" -eq 0 ]
[[ "$output" = $out ]] || false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noice. I like this test a lot more now :-)

@macneale4 macneale4 added the cli label Jun 2, 2023
@stephkyou stephkyou merged commit 69f9995 into main Jun 3, 2023
19 checks passed
@stephkyou stephkyou deleted the steph/dolt-blame branch June 3, 2023 06:51
@github-actions
Copy link

github-actions bot commented Jun 4, 2023

@coffeegoddd DOLT

name add_cnt delete_cnt update_cnt latency
adds_only 60000 0 0 0.87
adds_updates_deletes 60000 60000 60000 5.1
deletes_only 0 60000 0 2.46
updates_only 0 0 60000 3.31

@github-actions
Copy link

github-actions bot commented Jun 5, 2023

@coffeegoddd DOLT

name add_cnt delete_cnt update_cnt latency
adds_only 60000 0 0 1.12
adds_updates_deletes 60000 60000 60000 6.49
deletes_only 0 60000 0 3.23
updates_only 0 0 60000 4.34

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants