forked from cube2222/octosql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
464 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package execution | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"strings" | ||
|
||
"github.com/cube2222/octosql" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
type Requalifier struct { | ||
qualifier string | ||
source Node | ||
} | ||
|
||
func NewRequalifier(qualifier string, child Node) *Requalifier { | ||
return &Requalifier{qualifier: qualifier, source: child} | ||
} | ||
|
||
func (node *Requalifier) Get(variables octosql.Variables) (RecordStream, error) { | ||
recordStream, err := node.source.Get(variables) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "couldn't get record stream") | ||
} | ||
|
||
return &RequalifiedStream{ | ||
qualifier: node.qualifier, | ||
variables: variables, | ||
source: recordStream, | ||
}, nil | ||
} | ||
|
||
type RequalifiedStream struct { | ||
qualifier string | ||
variables octosql.Variables | ||
source RecordStream | ||
} | ||
|
||
// TODO: Do table name validation on logical -> physical plan transformation | ||
var simpleQualifierMatcher = regexp.MustCompile("[a-zA-Z0-9-_]") | ||
|
||
func (stream *RequalifiedStream) Next() (*Record, error) { | ||
record, err := stream.source.Next() | ||
if err != nil { | ||
if err == ErrEndOfStream { | ||
return nil, ErrEndOfStream | ||
} | ||
return nil, errors.Wrap(err, "couldn't get source record") | ||
} | ||
oldFields := record.Fields() | ||
|
||
fields := make([]octosql.VariableName, len(record.Fields())) | ||
values := make(map[octosql.VariableName]interface{}) | ||
for i := range oldFields { | ||
name := string(oldFields[i].Name) | ||
if dotIndex := strings.Index(name, "."); dotIndex != -1 { | ||
if simpleQualifierMatcher.MatchString(name[:dotIndex]) { | ||
name = name[dotIndex+1:] | ||
} | ||
} | ||
qualifiedName := octosql.VariableName(fmt.Sprintf("%s.%s", stream.qualifier, name)) | ||
|
||
fields = append(fields, qualifiedName) | ||
values[qualifiedName] = record.Value(oldFields[i].Name) | ||
} | ||
|
||
return NewRecord(fields, values), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
module github.com/cube2222/octosql | ||
|
||
require ( | ||
github.com/bradleyjkemp/cupaloy v2.3.0+incompatible // indirect | ||
github.com/bradleyjkemp/memmap v0.2.2 // indirect | ||
github.com/bradleyjkemp/memviz v0.2.2 | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/pkg/errors v0.8.1 | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,14 @@ | ||
github.com/bradleyjkemp/cupaloy v2.3.0+incompatible h1:UafIjBvWQmS9i/xRg+CamMrnLTKNzo+bdmT/oH34c2Y= | ||
github.com/bradleyjkemp/cupaloy v2.3.0+incompatible/go.mod h1:Au1Xw1sgaJ5iSFktEhYsS0dbQiS1B0/XMXl+42y9Ilk= | ||
github.com/bradleyjkemp/memmap v0.2.2 h1:K1MRR3CePpyv5fCF92VVRQa0YTCF1lBeHYUe1YQKPt8= | ||
github.com/bradleyjkemp/memmap v0.2.2/go.mod h1:hk93kmTK3wk+ezO+gS/h/W7ZXi5CRoB3sXCajzC2PMU= | ||
github.com/bradleyjkemp/memviz v0.2.2 h1:4401FLjMkfcpjrCJNSorhiPSkjiq8QBS++fsppQSk1s= | ||
github.com/bradleyjkemp/memviz v0.2.2/go.mod h1:O8KbRC1I+XiOeTs6+KcaCuME1yAAEc54zsQrlv6nkKg= | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= | ||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2 h1:zzrxE1FKn5ryBNl9eKOeqQ58Y/Qpo3Q9QNxKHX5uzzQ= | ||
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2/go.mod h1:hzfGeIUDq/j97IG+FhNqkowIyEcD88LrW6fyU3K3WqY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.