mirror of
https://github.com/minio/minio.git
synced 2025-11-20 18:06:10 -05:00
Add new SQL parser to support S3 Select syntax (#7102)
- New parser written from scratch, allows easier and complete parsing of the full S3 Select SQL syntax. Parser definition is directly provided by the AST defined for the SQL grammar. - Bring support to parse and interpret SQL involving JSON path expressions; evaluation of JSON path expressions will be subsequently added. - Bring automatic type inference and conversion for untyped values (e.g. CSV data).
This commit is contained in:
committed by
Harshavardhana
parent
0a28c28a8c
commit
2786055df4
87
pkg/s3select/sql/utils.go
Normal file
87
pkg/s3select/sql/utils.go
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Minio Cloud Storage, (C) 2019 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package sql
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// String functions
|
||||
|
||||
// String - returns the JSONPath representation
|
||||
func (e *JSONPath) String() string {
|
||||
parts := make([]string, len(e.PathExpr)+1)
|
||||
parts[0] = e.BaseKey.String()
|
||||
for i, pe := range e.PathExpr {
|
||||
parts[i+1] = pe.String()
|
||||
}
|
||||
return strings.Join(parts, "")
|
||||
}
|
||||
|
||||
func (e *JSONPathElement) String() string {
|
||||
switch {
|
||||
case e.Key != nil:
|
||||
return e.Key.String()
|
||||
case e.Index != nil:
|
||||
return fmt.Sprintf("[%d]", *e.Index)
|
||||
case e.ObjectWildcard:
|
||||
return ".*"
|
||||
case e.ArrayWildcard:
|
||||
return "[*]"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// Removes double quotes in quoted identifiers
|
||||
func (i *Identifier) String() string {
|
||||
if i.Unquoted != nil {
|
||||
return *i.Unquoted
|
||||
}
|
||||
return string(*i.Quoted)
|
||||
}
|
||||
|
||||
func (o *ObjectKey) String() string {
|
||||
if o.Lit != nil {
|
||||
return fmt.Sprintf("['%s']", string(*o.Lit))
|
||||
}
|
||||
return fmt.Sprintf(".%s", o.ID.String())
|
||||
}
|
||||
|
||||
// getLastKeypathComponent checks if the given expression is a path
|
||||
// expression, and if so extracts the last dot separated component of
|
||||
// the path. Otherwise it returns false.
|
||||
func getLastKeypathComponent(e *Expression) (string, bool) {
|
||||
if len(e.And) > 1 ||
|
||||
len(e.And[0].Condition) > 1 ||
|
||||
e.And[0].Condition[0].Not != nil ||
|
||||
e.And[0].Condition[0].Operand.ConditionRHS != nil {
|
||||
return "", false
|
||||
}
|
||||
|
||||
operand := e.And[0].Condition[0].Operand.Operand
|
||||
if operand.Right != nil ||
|
||||
operand.Left.Right != nil ||
|
||||
operand.Left.Left.Negated != nil ||
|
||||
operand.Left.Left.Primary.JPathExpr == nil {
|
||||
return "", false
|
||||
}
|
||||
|
||||
keypath := operand.Left.Left.Primary.JPathExpr.String()
|
||||
ps := strings.Split(keypath, ".")
|
||||
return ps[len(ps)-1], true
|
||||
}
|
||||
Reference in New Issue
Block a user