evaluateExpressionValue evaluates any expression to get its value from a record
(expr ExprNode, result HybridScanResult)
| 4679 | |
| 4680 | // evaluateExpressionValue evaluates any expression to get its value from a record |
| 4681 | func (e *SQLEngine) evaluateExpressionValue(expr ExprNode, result HybridScanResult) (*schema_pb.Value, error) { |
| 4682 | switch exprType := expr.(type) { |
| 4683 | case *ColName: |
| 4684 | columnName := exprType.Name.String() |
| 4685 | upperColumnName := strings.ToUpper(columnName) |
| 4686 | |
| 4687 | // Check if this is actually a string literal that was parsed as ColName |
| 4688 | if (strings.HasPrefix(columnName, "'") && strings.HasSuffix(columnName, "'")) || |
| 4689 | (strings.HasPrefix(columnName, "\"") && strings.HasSuffix(columnName, "\"")) { |
| 4690 | // This is a string literal that was incorrectly parsed as a column name |
| 4691 | literal := strings.Trim(strings.Trim(columnName, "'"), "\"") |
| 4692 | return &schema_pb.Value{Kind: &schema_pb.Value_StringValue{StringValue: literal}}, nil |
| 4693 | } |
| 4694 | |
| 4695 | // Check if this is actually a function call that was parsed as ColName |
| 4696 | if strings.Contains(columnName, "(") && strings.Contains(columnName, ")") { |
| 4697 | // This is a function call that was parsed incorrectly as a column name |
| 4698 | // We need to manually evaluate it as a function |
| 4699 | return e.evaluateColumnNameAsFunction(columnName, result) |
| 4700 | } |
| 4701 | |
| 4702 | // Check if this is a datetime constant |
| 4703 | if upperColumnName == FuncCURRENT_DATE || upperColumnName == FuncCURRENT_TIME || |
| 4704 | upperColumnName == FuncCURRENT_TIMESTAMP || upperColumnName == FuncNOW { |
| 4705 | switch upperColumnName { |
| 4706 | case FuncCURRENT_DATE: |
| 4707 | return e.CurrentDate() |
| 4708 | case FuncCURRENT_TIME: |
| 4709 | return e.CurrentTime() |
| 4710 | case FuncCURRENT_TIMESTAMP: |
| 4711 | return e.CurrentTimestamp() |
| 4712 | case FuncNOW: |
| 4713 | return e.Now() |
| 4714 | } |
| 4715 | } |
| 4716 | |
| 4717 | // Check if this is actually a numeric literal disguised as a column name |
| 4718 | if val, err := strconv.ParseInt(columnName, 10, 64); err == nil { |
| 4719 | return &schema_pb.Value{Kind: &schema_pb.Value_Int64Value{Int64Value: val}}, nil |
| 4720 | } |
| 4721 | if val, err := strconv.ParseFloat(columnName, 64); err == nil { |
| 4722 | return &schema_pb.Value{Kind: &schema_pb.Value_DoubleValue{DoubleValue: val}}, nil |
| 4723 | } |
| 4724 | |
| 4725 | // Otherwise, treat as a regular column lookup |
| 4726 | value := e.findColumnValue(result, columnName) |
| 4727 | if value == nil { |
| 4728 | return nil, nil |
| 4729 | } |
| 4730 | return value, nil |
| 4731 | case *ArithmeticExpr: |
| 4732 | return e.evaluateArithmeticExpression(exprType, result) |
| 4733 | case *SQLVal: |
| 4734 | // Handle literal values |
| 4735 | return e.convertSQLValToSchemaValue(exprType), nil |
| 4736 | case *FuncExpr: |
| 4737 | // Handle function calls that are part of arithmetic expressions |
| 4738 | funcName := strings.ToUpper(exprType.Name.String()) |
no test coverage detected