-
Notifications
You must be signed in to change notification settings - Fork 0
Pre release #47
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
base: main
Are you sure you want to change the base?
Pre release #47
Changes from all commits
0abb344
c25fdec
d8317f3
edeb870
62c36c8
a549495
1d9d8eb
e05fa7e
4910e16
5905cfa
fffdd78
5c7585f
a2f17cc
28d0cae
fbf7564
a734938
70dc63e
9b91355
dfdca8a
bf0bf49
9877a82
8899c6f
e2f8442
2e92fb9
3290029
1d5a987
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,6 +5,7 @@ import ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "context" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "errors" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "fmt" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "opti-sql-go/config" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "opti-sql-go/operators" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "regexp" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "strings" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -13,6 +14,7 @@ import ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/apache/arrow/go/v17/arrow/array" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/apache/arrow/go/v17/arrow/compute" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/apache/arrow/go/v17/arrow/memory" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "go.uber.org/zap" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -24,35 +26,35 @@ var ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type binaryOperator int | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type BinaryOperator int | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // arithmetic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Addition binaryOperator = 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Subtraction binaryOperator = 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Multiplication binaryOperator = 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Division binaryOperator = 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Addition BinaryOperator = 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Subtraction BinaryOperator = 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Multiplication BinaryOperator = 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Division BinaryOperator = 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // comparison | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Equal binaryOperator = 6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| NotEqual binaryOperator = 7 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LessThan binaryOperator = 8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LessThanOrEqual binaryOperator = 9 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| GreaterThan binaryOperator = 10 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| GreaterThanOrEqual binaryOperator = 11 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Equal BinaryOperator = 6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| NotEqual BinaryOperator = 7 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LessThan BinaryOperator = 8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LessThanOrEqual BinaryOperator = 9 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| GreaterThan BinaryOperator = 10 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| GreaterThanOrEqual BinaryOperator = 11 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // logical | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| And binaryOperator = 12 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Or binaryOperator = 13 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| And BinaryOperator = 12 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Or BinaryOperator = 13 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // RegEx expressions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Like binaryOperator = 14 // where column_name like "patte%n_with_wi%dcard_" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Like BinaryOperator = 14 // where column_name like "patte%n_with_wi%dcard_" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type supportedFunctions int | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type SupportedFunctions int | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Upper supportedFunctions = 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Lower supportedFunctions = 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Abs supportedFunctions = 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Round supportedFunctions = 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Upper SupportedFunctions = 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Lower SupportedFunctions = 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Abs SupportedFunctions = 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Round SupportedFunctions = 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type aggFunctions = int | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -91,6 +93,19 @@ type Expression interface { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fmt.Stringer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // To_aggr_name extracts the column name from an expression for use in aggregation schema building. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Returns the alias name if present, otherwise the column name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func To_aggr_name(expr Expression) string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| switch e := expr.(type) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case *ColumnResolve: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return e.Name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case *Alias: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return e.Name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| default: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return expr.String() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func EvalExpression(expr Expression, batch *operators.RecordBatch) (arrow.Array, error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| switch e := expr.(type) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case *Alias: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -199,7 +214,7 @@ func EvalColumn(c *ColumnResolve, batch *operators.RecordBatch) (arrow.Array, er | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for i, f := range batch.Schema.Fields() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if f.Name == c.Name { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| col := batch.Columns[i] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| col.Retain() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| //col.Retain() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return col, nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -213,8 +228,7 @@ func (c *ColumnResolve) String() string { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Evaluates to a column of length = batch-size, filled with this literal. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // sql: select 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type LiteralResolve struct { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Type arrow.DataType | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // dont forget to cast the value. so string("hello") not just "hello" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Type arrow.DataType | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Value any | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -425,11 +439,11 @@ func (l *LiteralResolve) String() string { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type BinaryExpr struct { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Left Expression | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Op binaryOperator | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Op BinaryOperator | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Right Expression | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func NewBinaryExpr(left Expression, op binaryOperator, right Expression) *BinaryExpr { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func NewBinaryExpr(left Expression, op BinaryOperator, right Expression) *BinaryExpr { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return &BinaryExpr{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Left: left, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Op: op, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -438,6 +452,7 @@ func NewBinaryExpr(left Expression, op binaryOperator, right Expression) *Binary | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func EvalBinary(b *BinaryExpr, batch *operators.RecordBatch) (arrow.Array, error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger := config.GetLogger() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| leftArr, err := EvalExpression(b.Left, batch) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return nil, err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -446,6 +461,11 @@ func EvalBinary(b *BinaryExpr, batch *operators.RecordBatch) (arrow.Array, error | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return nil, err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger.Debug("Evaluating binary expression", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| zap.String("operator", fmt.Sprintf("%v", b.Op)), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| zap.Int("left_len", leftArr.Len()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| zap.Int("right_len", rightArr.Len()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ctx := context.Background() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| opt := compute.ArithmeticOptions{} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| switch b.Op { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -578,11 +598,11 @@ func unpackDatum(d compute.Datum) (arrow.Array, error) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type ScalarFunction struct { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Function supportedFunctions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Function SupportedFunctions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Arguments Expression // resolve to something you can process IE, literal/coloumn Resolve | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func NewScalarFunction(function supportedFunctions, Argument Expression) *ScalarFunction { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func NewScalarFunction(function SupportedFunctions, Argument Expression) *ScalarFunction { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return &ScalarFunction{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Function: function, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Arguments: Argument, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -736,7 +756,7 @@ func lowerImpl(arr arrow.Array) (arrow.Array, error) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return b.NewArray(), nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func inferScalarFunctionType(fn supportedFunctions, argType arrow.DataType) arrow.DataType { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func inferScalarFunctionType(fn SupportedFunctions, argType arrow.DataType) arrow.DataType { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| switch fn { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case Upper, Lower: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -753,7 +773,7 @@ func inferScalarFunctionType(fn supportedFunctions, argType arrow.DataType) arro | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func inferBinaryType(left arrow.DataType, op binaryOperator, right arrow.DataType) arrow.DataType { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func inferBinaryType(left arrow.DataType, op BinaryOperator, right arrow.DataType) arrow.DataType { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| switch op { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case Addition, Subtraction, Multiplication, Division: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -816,3 +836,57 @@ func validRegEx(columnValue, regExExpr string) bool { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ok | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func FnToScalarFunction(s string) SupportedFunctions { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| switch s { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case "Upper": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case "Lower": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case "Abs": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case "Round": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+839
to
+850
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func FnToScalarFunction(s string) SupportedFunctions { | |
| switch s { | |
| case "Upper": | |
| return 1 | |
| case "Lower": | |
| return 2 | |
| case "Abs": | |
| return 3 | |
| case "Round": | |
| return 4 | |
| } | |
| return 1 | |
| func FnToScalarFunction(s string) (SupportedFunctions, error) { | |
| switch s { | |
| case "Upper": | |
| return 1, nil | |
| case "Lower": | |
| return 2, nil | |
| case "Abs": | |
| return 3, nil | |
| case "Round": | |
| return 4, nil | |
| default: | |
| return 0, fmt.Errorf("unsupported scalar function: %s", s) | |
| } |
Copilot
AI
Feb 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FnToScalarFunction returns Upper (1) for unknown function names. That can silently turn invalid input into a different operation. Prefer returning a sentinel (e.g., SupportedFunctions(-1)) and/or a (SupportedFunctions, bool) result so callers can handle unknown names explicitly.
| return 1 | |
| return SupportedFunctions(-1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
docker buildx buildcommand is duplicated outside of a fenced code block at the end of the README, which makes the Markdown render oddly and looks accidental. Consider removing it or wrapping it in a proper code block.