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

sql/*: add support for create index statement #182

Merged
merged 2 commits into from
May 8, 2018

Conversation

erizocosmico
Copy link
Contributor

@erizocosmico erizocosmico commented May 4, 2018

Depends on #179

Closes #171

Missing:

  • Parse driver name
  • Parse config

There are a few questions around that in the document, they will be implemented once they are answered.

@erizocosmico erizocosmico force-pushed the feature/create-index branch from 8b782c5 to 4854afb Compare May 4, 2018 13:40
sql/index.go Outdated
@@ -40,8 +40,8 @@ type Index interface {
Database() string
// Table returns the table name this index belongs to.
Table() string
// Expression returns the indexed expression.
Expression() Expression
// Expressions returns the indexed expressions.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add here all the explanation about if there is more than one expression they are Columns and so on?

sql/index.go Outdated
@@ -104,8 +104,8 @@ type Mergeable interface {
type IndexDriver interface {
// ID returns the unique name of the driver.
ID() string
// Create a new index for the given expression and id.
Create(path, db, id string, expr Expression) (Index, error)
// Create a new index.
Copy link
Contributor

Choose a reason for hiding this comment

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

The same as the previous comment here.

sql/index.go Outdated
@@ -120,7 +120,7 @@ type indexKey struct {

// IndexRegistry keeps track of all indexes in the engine.
type IndexRegistry struct {
root string
Root string
Copy link
Contributor

Choose a reason for hiding this comment

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

Some documentation for this, now that is public?

sql/index.go Outdated
r.retainIndex(db, idx.ID())
return idx
if idx.Database() == db {
for _, e := range idx.Expressions() {
Copy link
Contributor

Choose a reason for hiding this comment

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

All the expressions must match, not only one. So maybe we need to change IndexByExpression(db string, expr Expression) Index to IndexByExpression(db string, expr ...Expression) Index and use exprListsEqual

Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
@erizocosmico erizocosmico force-pushed the feature/create-index branch from 4854afb to 880fccd Compare May 4, 2018 14:48
@erizocosmico
Copy link
Contributor Author

Done @ajnavarro

@ajnavarro ajnavarro requested review from jfontan, kuba-- and mcarmonaa May 4, 2018 14:54
@erizocosmico
Copy link
Contributor Author

Don't merge this until the USING and the config things are implemented.

Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
@erizocosmico
Copy link
Contributor Author

Now it's fully finished. Can be reviewed again.

Copy link
Contributor

@kuba-- kuba-- left a comment

Choose a reason for hiding this comment

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

LGTM

}

if singleQuote || doubleQuote {
switch true {
Copy link
Contributor

Choose a reason for hiding this comment

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

this is smart, if we have a cascade of ifs 👍
when we jump into ignoreNext is it ok to break it and just buf.WriteRune(r) (just asking because sounds like we ignore but write it)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case, what ignoreNext does is ignore the meaning of the next character, but we need everything written, that's why there is no break in there. We need every character written because we delegate the real parsing to sqlparser.

@ajnavarro ajnavarro merged commit f2fefea into src-d:master May 8, 2018
@erizocosmico erizocosmico deleted the feature/create-index branch May 8, 2018 13:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants