Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Commit

Permalink
#55 #57 #58 implement literal handling in compiler and engine
Browse files Browse the repository at this point in the history
Implement review corrections
  • Loading branch information
tsatke committed Oct 30, 2020
1 parent 2eb2ccf commit 68634b9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
22 changes: 11 additions & 11 deletions internal/engine/numeric_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type numericParser struct {

isReal bool
isHexadecimal bool
isErronous bool
isErroneous bool
hasDigitsBeforeExponent bool

value *bytes.Buffer
Expand All @@ -39,7 +39,7 @@ func ToNumericValue(s string) (types.Value, bool) {
current: stateInitial,
}
p.parse()
if p.isErronous {
if p.isErroneous {
return nil, false
}
switch {
Expand Down Expand Up @@ -94,7 +94,7 @@ func stateInitial(p *numericParser) numericParserState {
case p.get() == '.':
return stateDecimalPoint
}
p.isErronous = true
p.isErroneous = true
return nil
}

Expand All @@ -103,7 +103,7 @@ func stateHex(p *numericParser) numericParserState {
p.step()
return stateHex
}
p.isErronous = true
p.isErroneous = true
return nil
}

Expand All @@ -115,7 +115,7 @@ func stateFirstDigits(p *numericParser) numericParserState {
} else if p.get() == '.' {
return stateDecimalPoint
}
p.isErronous = true
p.isErroneous = true
return nil
}

Expand All @@ -125,7 +125,7 @@ func stateDecimalPoint(p *numericParser) numericParserState {
p.isReal = true
return stateSecondDigits
}
p.isErronous = true
p.isErroneous = true
return nil
}

Expand All @@ -138,9 +138,9 @@ func stateSecondDigits(p *numericParser) numericParserState {
if p.hasDigitsBeforeExponent {
return stateExponent
}
p.isErronous = true // if there were no first digits,
p.isErroneous = true // if there were no first digits,
}
p.isErronous = true
p.isErroneous = true
return nil
}

Expand All @@ -149,7 +149,7 @@ func stateExponent(p *numericParser) numericParserState {
p.step()
return stateOptionalSign
}
p.isErronous = true
p.isErroneous = true
return nil
}

Expand All @@ -160,7 +160,7 @@ func stateOptionalSign(p *numericParser) numericParserState {
} else if isDigit(p.get()) {
return stateThirdDigits
}
p.isErronous = true
p.isErroneous = true
return nil
}

Expand All @@ -169,7 +169,7 @@ func stateThirdDigits(p *numericParser) numericParserState {
p.step()
return stateThirdDigits
}
p.isErronous = true
p.isErroneous = true
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/engine/numeric_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func TestToNumericValue(t *testing.T) {
{
"real with exponent",
"5.7E-242",
types.NewReal(5.7E-242),
types.NewReal(5.7e-242),
true,
},
{
Expand Down
18 changes: 9 additions & 9 deletions internal/engine/projected_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,32 @@ func (e Engine) newProjectedTable(ctx ExecutionContext, originalTable table.Tabl
// compute the column names
var cols []table.Col
for i, colNameExpr := range columnExpressions {
if ref, ok := colNameExpr.Expr.(command.ColumnReference); ok {
if ref.Name == "*" {
switch expr := colNameExpr.Expr.(type) {
case command.ColumnReference:
if expr.Name == "*" {
cols = append(cols, originalTable.Cols()...)
} else {
foundCol, ok := table.FindColumnForNameOrAlias(originalTable, ref.Name)
foundCol, ok := table.FindColumnForNameOrAlias(originalTable, expr.Name)
if !ok {
return projectedTable{}, ErrNoSuchColumn(ref.Name)
return projectedTable{}, ErrNoSuchColumn(expr.Name)
}
cols = append(cols, foundCol)
}
} else if litOrRef, ok := colNameExpr.Expr.(command.ConstantLiteralOrColumnReference); ok {
foundCol, ok := table.FindColumnForNameOrAlias(originalTable, litOrRef.ValueOrName)
if ok {
case command.ConstantLiteralOrColumnReference:
if foundCol, ok := table.FindColumnForNameOrAlias(originalTable, expr.ValueOrName); ok {
cols = append(cols, foundCol)
} else {
evaluatedName, err := e.evaluateExpression(ctx, colNameExpr.Expr)
if err != nil {
return projectedTable{}, fmt.Errorf("typeof colName: %w", err)
}
cols = append(cols, table.Col{
QualifiedName: litOrRef.ValueOrName,
QualifiedName: expr.ValueOrName,
Alias: colNameExpr.Alias,
Type: evaluatedName.Type(),
})
}
} else {
default:
colName, err := e.evaluateExpression(ctx, colNameExpr.Expr)
if err != nil {
return projectedTable{}, fmt.Errorf("col name: %w", err)
Expand Down

0 comments on commit 68634b9

Please sign in to comment.