From 68634b940cee60f33df5aeac10ea5b51ec1a834c Mon Sep 17 00:00:00 2001 From: tsatke Date: Fri, 30 Oct 2020 14:27:23 +0100 Subject: [PATCH] #55 #57 #58 implement literal handling in compiler and engine Implement review corrections --- internal/engine/numeric_parser.go | 22 +++++++++++----------- internal/engine/numeric_parser_test.go | 2 +- internal/engine/projected_table.go | 18 +++++++++--------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/internal/engine/numeric_parser.go b/internal/engine/numeric_parser.go index 84740880..61094c1a 100644 --- a/internal/engine/numeric_parser.go +++ b/internal/engine/numeric_parser.go @@ -16,7 +16,7 @@ type numericParser struct { isReal bool isHexadecimal bool - isErronous bool + isErroneous bool hasDigitsBeforeExponent bool value *bytes.Buffer @@ -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 { @@ -94,7 +94,7 @@ func stateInitial(p *numericParser) numericParserState { case p.get() == '.': return stateDecimalPoint } - p.isErronous = true + p.isErroneous = true return nil } @@ -103,7 +103,7 @@ func stateHex(p *numericParser) numericParserState { p.step() return stateHex } - p.isErronous = true + p.isErroneous = true return nil } @@ -115,7 +115,7 @@ func stateFirstDigits(p *numericParser) numericParserState { } else if p.get() == '.' { return stateDecimalPoint } - p.isErronous = true + p.isErroneous = true return nil } @@ -125,7 +125,7 @@ func stateDecimalPoint(p *numericParser) numericParserState { p.isReal = true return stateSecondDigits } - p.isErronous = true + p.isErroneous = true return nil } @@ -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 } @@ -149,7 +149,7 @@ func stateExponent(p *numericParser) numericParserState { p.step() return stateOptionalSign } - p.isErronous = true + p.isErroneous = true return nil } @@ -160,7 +160,7 @@ func stateOptionalSign(p *numericParser) numericParserState { } else if isDigit(p.get()) { return stateThirdDigits } - p.isErronous = true + p.isErroneous = true return nil } @@ -169,7 +169,7 @@ func stateThirdDigits(p *numericParser) numericParserState { p.step() return stateThirdDigits } - p.isErronous = true + p.isErroneous = true return nil } diff --git a/internal/engine/numeric_parser_test.go b/internal/engine/numeric_parser_test.go index 8aa660ba..d9517545 100644 --- a/internal/engine/numeric_parser_test.go +++ b/internal/engine/numeric_parser_test.go @@ -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, }, { diff --git a/internal/engine/projected_table.go b/internal/engine/projected_table.go index c5eb8430..6d239886 100644 --- a/internal/engine/projected_table.go +++ b/internal/engine/projected_table.go @@ -29,19 +29,19 @@ 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) @@ -49,12 +49,12 @@ func (e Engine) newProjectedTable(ctx ExecutionContext, originalTable table.Tabl 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)