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

select: return error if field doesn't exist on tables with strict schema #477

Closed
wants to merge 1 commit into from

Conversation

tzzed
Copy link
Contributor

@tzzed tzzed commented Jul 15, 2022

This PR fixes #465.

add path analyzer.
@codecov
Copy link

codecov bot commented Jul 15, 2022

Codecov Report

Merging #477 (363c909) into main (a518533) will increase coverage by 0.03%.
The diff coverage is 97.50%.

❗ Current head 363c909 differs from pull request most recent head 3e41060. Consider uploading reports for the commit 3e41060 to get more accurate results

@@            Coverage Diff             @@
##             main     #477      +/-   ##
==========================================
+ Coverage   79.09%   79.12%   +0.03%     
==========================================
  Files         128      128              
  Lines       10748    10822      +74     
==========================================
+ Hits         8501     8563      +62     
- Misses       1543     1549       +6     
- Partials      704      710       +6     
Impacted Files Coverage Δ
internal/query/statement/select.go 95.21% <97.50%> (-4.79%) ⬇️
document/path.go 90.58% <0.00%> (-2.36%) ⬇️
internal/planner/optimizer.go 81.27% <0.00%> (-2.29%) ⬇️
internal/database/encoding.go 85.60% <0.00%> (-1.61%) ⬇️
internal/encoding/helpers.go 91.59% <0.00%> (+0.84%) ⬆️
internal/expr/comparison.go 87.50% <0.00%> (+1.92%) ⬆️
internal/expr/expr.go 71.79% <0.00%> (+2.56%) ⬆️

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@asdine asdine changed the title handle error of selectStatement preparer. select: return error if field doesn't exist on tables with strict schema Jul 18, 2022
Copy link
Collaborator

@asdine asdine left a comment

Choose a reason for hiding this comment

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

Thanks @tzzed !

The problem with this approach is that it's a hack: we are generating a string representation of an expression just because it's easier to analyze it while parsing it.

The thing is it has already been parsed before this function was called, and now we are parsing it again.

// Lifecycle of a query
Query string -> parser -> prepare -> exec stream

We should instead simply walk over all expressions and use GetFieldConstraintForPath to see if it's declared or not.

for _, pe := range stmt.ProjectionExprs {
  expr.Walk(pe, func(e expr.Expr) bool {
    switch t := e.(type) {
      case expr.Path:
          if fc := ti.FieldConstraints.GetFieldConstraintForPath(document.Path(t)); fc == nil {
             // return an error
          }
      }
  })
}

Perhaps make this a function and use it for all expressions of the SELECT statement.

{"EXPLAIN SELECT a + 1 FROM test WHERE c > 10 AND d > 20", false, `"table.Scan(\"test\") | docs.Filter(c > 10) | docs.Filter(d > 20) | docs.Project(a + 1)"`},
{"EXPLAIN SELECT a + 1 FROM test WHERE c > 10 OR d > 20", false, `"table.Scan(\"test\") | docs.Filter(c > 10 OR d > 20) | docs.Project(a + 1)"`},
{"EXPLAIN SELECT a + 1 FROM test WHERE c IN [1 + 1, 2 + 2]", false, `"table.Scan(\"test\") | docs.Filter(c IN [2, 4]) | docs.Project(a + 1)"`},
{"EXPLAIN SELECT a + 1 FROM test WHERE c > 10", true, ``},
Copy link
Collaborator

Choose a reason for hiding this comment

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

These tests were written to test something specific, we should not disable them by expecting them to fail.
We should instead either:

  • change the declaration of the table so that it's not a strict table anymore
  • change the path c with something that is already declared
  • declare missing paths in the table declaration

@asdine
Copy link
Collaborator

asdine commented Dec 25, 2023

Closing this as the codebase have changed quite a bit, and this is no longer neeed. Thanks @tzzed !

@asdine asdine closed this Dec 25, 2023
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.

SELECT: If the schema is strict and a projected field doesn't exist, we should return an error
2 participants