Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

Show warnings - implementation #464

Merged
merged 1 commit into from
Oct 23, 2018
Merged

Show warnings - implementation #464

merged 1 commit into from
Oct 23, 2018

Conversation

kuba--
Copy link
Contributor

@kuba-- kuba-- commented Oct 17, 2018

Signed-off-by: kuba-- kuba@sourced.tech

This PR implements just:

SHOW WARNINGS [LIMIT [offset,] count]

Note: We need to implement collect session warnings (#465)

Closes #442

@kuba-- kuba-- requested review from erizocosmico and a team October 17, 2018 13:51
@kuba-- kuba-- added the enhancement New feature or request label Oct 17, 2018
@kuba-- kuba-- mentioned this pull request Oct 17, 2018
// ShowWarnings is a node that shows the session warnings
type ShowWarnings struct {
warnings []*sql.Warning
offset uint
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of implementing offset and limit here again, what do you think about making ShowWarnings return all warnings and then wrap it in Limit and Offset nodes instead, which are already implemented?

}
}

return plan.NewShowWarnings(ctx.Session.Warnings(), uint(offset), uint(count)), nil
Copy link
Contributor

Choose a reason for hiding this comment

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

You can just wrap ShowWarnings nodes in Limit and Offset nodes

sql/session.go Outdated
Value interface{}
// AppendWarning append a warning on to the slice
// The function implements sql.Session interface
func (s *BaseSession) AppendWarning(warn *Warning) {
Copy link
Contributor

Choose a reason for hiding this comment

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

AppendWarning is perhaps too coupled with how it's implemented (docs shouldn't specify whether it's in a slice or not. The internal implementation should not be disclosed

How about Warn or AddWarning?

@kuba--
Copy link
Contributor Author

kuba-- commented Oct 17, 2018

@erizocosmico - I wrapped it by Offset/Limit (what's cool - I didn't notice that we've already got it).
Regarding naming... I renamed AppendWarning to Warn. I don't like both (but I don't have a better idea). AddWarning describes an operation, so I don't see any difference to Append.... Eventually we can rename it to Put... (which is more stack related).
Anyway, I sticked to Warn assuming that it's pretty descriptive and less is sometimes more.

@erizocosmico
Copy link
Contributor

@kuba-- can you rebase?

@kuba--
Copy link
Contributor Author

kuba-- commented Oct 19, 2018

@erizocosmico - done.

@@ -32,15 +32,20 @@ type Session interface {
GetAll() map[string]TypedValue
// ID returns the unique ID of the connection.
ID() uint32
// Warn stores the warning in the session.
Warn(warn *Warning)
Copy link
Contributor

Choose a reason for hiding this comment

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

should we separate this into another session interface to do not force people to implement warnings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

type LogSession + func WithWarnings?

Copy link
Contributor

Choose a reason for hiding this comment

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

If warnings is supported, it should be implemented in the session imho

user string
mu sync.RWMutex
config map[string]TypedValue
warnings []*Warning
Copy link
Contributor

Choose a reason for hiding this comment

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

when is this slice deleted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It can be deleted if we have some kind Close session.

Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this supposed to be a per-query thing?

Copy link
Contributor

@ajnavarro ajnavarro Oct 19, 2018

Choose a reason for hiding this comment

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

Yep, should be deleted before new query: https://mariadb.com/kb/en/library/show-warnings/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I believe it will be auto-cleared because in handler.go (ComQuery) we create a new context. Am I right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sessions are not equal to contexts. Sessions outlive contexts. Sessions are per-connection.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any better idea than extending Session interface by ClearWarnings()?

Copy link
Contributor

Choose a reason for hiding this comment

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

we should add ClearWarnings() and call it before any query that is not a show errors or show warnings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, PTAL.

@@ -63,6 +64,11 @@ func Parse(ctx *sql.Context, query string) (sql.Node, error) {
}

lowerQuery := strings.ToLower(s)
if showWarningsRegex.MatchString(lowerQuery) {
Copy link
Contributor

Choose a reason for hiding this comment

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

should we do this on analyzer phase using a rule?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can do it (hopefully no warnings will be missed), by adding a new rule to
analyzer.OnceBeforeDefault. Is it a right place?

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 it should be on OnceAfterAll.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, it also will work:+1

Signed-off-by: kuba-- <kuba@sourced.tech>
@kuba--
Copy link
Contributor Author

kuba-- commented Oct 19, 2018

@ajnavarro - added clearWarnings rule. PTAL

@ajnavarro
Copy link
Contributor

@kuba-- could you rebase again please?

@ajnavarro ajnavarro merged commit 40f0472 into src-d:master Oct 23, 2018
@kuba-- kuba-- deleted the show-warnings branch October 23, 2018 07:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants