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

Cli act tests #1260

Merged
merged 8 commits into from
Jan 22, 2025
Merged

Cli act tests #1260

merged 8 commits into from
Jan 22, 2025

Conversation

brennanjl
Copy link
Collaborator

Still some work to do on this but putting it up for a discussion

@brennanjl brennanjl marked this pull request as ready for review January 21, 2025 07:37
@brennanjl
Copy link
Collaborator Author

Ok this is ready to go. There are still some tests we need with roundtripping all data types, kgw, etc., but for a beta this should be enough.

@charithabandi charithabandi self-assigned this Jan 21, 2025
config/config.go Outdated Show resolved Hide resolved
jchappelow
jchappelow previously approved these changes Jan 21, 2025
Copy link
Member

@jchappelow jchappelow left a comment

Choose a reason for hiding this comment

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

LGTM. @Yaiba probably should look though.

Comment on lines 24 to 26
execActionLong = `TODO: fill me out`

execActionExample = `TODO: fill me out`
Copy link
Member

Choose a reason for hiding this comment

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

I was wondering how this compared to database execute etc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So @Yaiba pointed out that our old version of database execute simply doesn't work with some of the new things supported within the engine. Namely, it requires all named parameters, rather than positional (which doesn't work for a lot of the things Gavin is doing with extension methods).

Furthermore, the old execute got pretty overloaded. Now that we have ad-hoc INSERT/UPDATE/DELETE, it had to also handle that (at least that's what I felt was most clear, since execute is definitely what I would expect to use to do that).

So I sort've took this as a chance to fix that. Now, it is clear what to use for actions and SQL. It can still use named params if you want, but positional is the default. The same command that handles executing an action once also handles it with CSV values.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have another commit coming that adds docs for this, as well as a few other things. Since this is already reviewed, we can merge this and then Ill add the other later, since it has a lot of stuff (found a lot of bugs/edge cases)

Comment on lines 308 to 309
if !wrote {
// if it didnt write a value, do not add the empty pointer to the slice
Copy link
Member

@jchappelow jchappelow Jan 21, 2025

Choose a reason for hiding this comment

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

This means "leave the nil pointer in the slice" or, equivalently, "do not insert a non-nil pointer to the zero value for T"? I didn't know what an "empty pointer" was describing at first.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think thats a bad comment, will fix.

It should say: "if convertScalar did not write to val, we should not add the new pointer to the slice"

@jchappelow jchappelow requested a review from Yaiba January 21, 2025 23:13
@Yaiba
Copy link
Contributor

Yaiba commented Jan 21, 2025

LGTM. @Yaiba probably should look though.

will take a quick scan


for _, arg := range args {
// trim off any leading '$'
arg = strings.TrimPrefix(arg, "$")
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to point it out that this is unlikely to happen, if user pass $xx(without single quote) to the cli, it'll be expanded by SHELL.

Copy link
Collaborator Author

@brennanjl brennanjl Jan 22, 2025

Choose a reason for hiding this comment

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

They often times will need to wrap it in single quotes though. For example, if they are passing an array, they have to do:

'param:int[]=[1,2]'
# or
'$param:int[]=[1,2]'
# regardless, they need single quotes

So IMO we should keep it

tests := []testcase{
// scalars
{"username:text=satoshi", "username", "satoshi", false},
{`username:text="satoshi"`, "username", "satoshi", 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 we should only support single quote, to avoid the confusion if user want to insert a text like $xxx, because the SHELL will expand the value

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is still the case though. For example:

$ ab='hello!'; kwil-cli query 'select $a' -p a:text="$ab"
|        |
+--------+
| hello! |

The double quotes will only get parsed if a user wraps the entire param in them:

ab='hello!'; kwil-cli query 'select $a' -p 'a:text="$ab"'
|     |
+-----+
| $ab |

@@ -75,6 +85,28 @@ func makeActionToExecutable(namespace string, act *Action) *executable {
for _, stmt := range stmtFns {
err := stmt(exec2, func(row *row) error {
row.columns = returnColNames

// we will ensure that the return values match the expected return types
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

@Yaiba
Copy link
Contributor

Yaiba commented Jan 21, 2025

lgtm, only issue I have is parsing 'text' type in cli I mentioned at #1260 (comment)

@brennanjl
Copy link
Collaborator Author

I ended up including some other changes in this PR. It's all in the last commit, so if you would like me to pop it off into a separate PR so that it is easier to review, I'm happy to.

It doesn't include much new stuff except tests, bug fixes, and docs for the new CLI commands.

many encoding, engine, and CLI fixes

ran tidy

fix lint
Copy link
Member

@jchappelow jchappelow left a comment

Choose a reason for hiding this comment

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

LGTM. Send it

@brennanjl brennanjl merged commit 88353e6 into main Jan 22, 2025
2 checks passed
@brennanjl brennanjl deleted the cli-act-tests branch January 22, 2025 05:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants