Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
59865: sql: add schema_name,table_id to crdb_internal.ranges r=rafiss a=jordanlewis

... and crdb_internal.ranges_no_leases

Closes #59601.

This commit adds schema_name to crdb_internal.ranges and
crdb_internal.ranges_no_leases to ensure that it's possible to
disambiguate between ranges that are contained by a table with the same
name in two different user-defined schemas.

In addition, it also adds the table_id column which allows unambiguous
lookups of ranges for a given table id. This will also enable making a
virtual index on the table_id column later, which should be a nice win
for some introspection commands.

Release note (sql change): add the schema_name and table_id columns to
the crdb_internal.ranges and crdb_internal.ranges_no_leases virtual
tables.

60546: kvserver: improve handling for removal of a replica, when multiple replicas already exist on the same node r=lunevalex a=lunevalex

Fixes #60545

The allocator in some cases allows for a range to have a replica
on multiple stores of the same node. If that happens, it should allow
itself to fix the situation by removing one of the offending replicas.
This was only half working due to an ordering problem in how the replicas
appeared in the descriptor. It could remove the first replica, but not the second one.

.

Release note: None

60561: geo/wkt: simplify parser grammar and improve error messages r=otan a=andyyang890

This patch simplifies the yacc grammar for the WKT parser
and also improves the error messages for mixed dimensionality
problems.

Refs: #53091

Release note: None

Co-authored-by: Jordan Lewis <[email protected]>
Co-authored-by: Alex Lunev <[email protected]>
Co-authored-by: Andy Yang <[email protected]>
  • Loading branch information
4 people committed Feb 16, 2021
4 parents 497a9c0 + 6c4bccb + 306d2e9 + 0abdc79 commit 959750d
Show file tree
Hide file tree
Showing 8 changed files with 983 additions and 1,109 deletions.
145 changes: 139 additions & 6 deletions pkg/geo/wkt/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,28 @@ type ParseError struct {
problem string
pos int
str string
hint string
}

func (e *ParseError) Error() string {
return fmt.Sprintf("%s at pos %d\n%s\n%s^", e.problem, e.pos, e.str, strings.Repeat(" ", e.pos))
// TODO(ayang): print only relevant line (with line and pos no) instead of entire input
err := fmt.Sprintf("%s at pos %d\n%s\n%s^", e.problem, e.pos, e.str, strings.Repeat(" ", e.pos))
if e.hint != "" {
err += fmt.Sprintf("\nHINT: %s", e.hint)
}
return err
}

// Constant expected by parser when lexer reaches EOF.
const eof = 0

type wktLex struct {
line string
pos int
lastPos int
ret geom.T
lastErr error
line string
pos int
lastPos int
ret geom.T
curLayout geom.Layout
lastErr error
}

// Lex lexes a token from the input.
Expand Down Expand Up @@ -224,10 +231,136 @@ func (l *wktLex) trimLeft() {
}
}

func getDefaultLayoutForStride(stride int) geom.Layout {
switch stride {
case 2:
return geom.XY
case 3:
return geom.XYZ
case 4:
return geom.XYZM
default:
// This should never happen.
panic("unsupported stride")
}
}

func (l *wktLex) validateStrideAndSetLayoutIfNoLayout(stride int) bool {
if !l.validateStride(stride) {
return false
}
l.setLayoutIfNoLayout(getDefaultLayoutForStride(stride))
return true
}

func (l *wktLex) validateStride(stride int) bool {
if !l.isValidStrideForLayout(stride) {
l.setIncorrectStrideError(stride, "")
return false
}
return true
}

func (l *wktLex) isValidStrideForLayout(stride int) bool {
switch l.curLayout {
case geom.NoLayout:
return true
case geom.XY:
return stride == 2
case geom.XYM:
return stride == 3
case geom.XYZ:
return stride == 3
case geom.XYZM:
return stride == 4
default:
// This should never happen.
panic("unknown geom.Layout")
}
}

func (l *wktLex) setLayout(layout geom.Layout) bool {
if layout == l.curLayout {
return true
}
if l.curLayout != geom.NoLayout {
l.setIncorrectLayoutError(layout, "")
return false
}
l.setLayoutIfNoLayout(layout)
return true
}

func (l *wktLex) setLayoutEmptyInCollection() bool {
if l.curLayout == geom.XY {
return true
}
if l.curLayout == geom.NoLayout {
l.curLayout = geom.XY
return true
}
l.setIncorrectLayoutError(geom.XY, "EMPTY is XY layout in base geometry type collection")
return false
}

func (l *wktLex) setLayoutIfNoLayout(layout geom.Layout) {
switch l.curLayout {
case geom.NoLayout:
l.curLayout = layout
case geom.XY, geom.XYM, geom.XYZ, geom.XYZM:
break
default:
// This should never happen.
panic("unknown geom.Layout")
}
}

func (l *wktLex) setLexError(expectedTokType string) {
l.lastErr = &LexError{expectedTokType: expectedTokType, pos: l.lastPos, str: l.line}
}

func getLayoutName(layout geom.Layout) string {
switch layout {
case geom.XY:
return "XY"
case geom.XYM:
return "XYM"
case geom.XYZ:
return "XYZ"
case geom.XYZM:
return "XYZM"
default:
// This should never happen.
panic("unknown geom.Layout")
}
}

func (l *wktLex) setIncorrectStrideError(incorrectStride int, hint string) {
problem := fmt.Sprintf("mixed dimensionality, parsed layout is %s so expecting %d coords but got %d coords",
getLayoutName(l.curLayout), l.curLayout.Stride(), incorrectStride)
l.setParseError(problem, hint)
}

func (l *wktLex) setIncorrectLayoutError(incorrectLayout geom.Layout, hint string) {
problem := fmt.Sprintf("mixed dimensionality, parsed layout is %s but encountered layout of %s",
getLayoutName(l.curLayout), getLayoutName(incorrectLayout))
l.setParseError(problem, hint)
}

func (l *wktLex) setParseError(problem string, hint string) {
// Lex errors take precedence.
if l.lastErr != nil {
return
}
errProblem := "syntax error: " + problem
l.lastErr = &ParseError{
problem: errProblem,
pos: l.lastPos,
str: l.line,
hint: hint,
}
}

func (l *wktLex) Error(s string) {
// NB: Lex errors are set in the Lex function.
if l.lastErr == nil {
Expand Down
Loading

0 comments on commit 959750d

Please sign in to comment.