mirror of
https://github.com/minio/minio.git
synced 2025-02-23 11:32:32 -05:00
fix: s3 sql parse error for colums as with quotes (#18765)
This commit is contained in:
parent
3a90af0bcd
commit
a89e0bab7d
@ -128,7 +128,7 @@ type JSONPath struct {
|
|||||||
// AliasedExpression is an expression that can be optionally named
|
// AliasedExpression is an expression that can be optionally named
|
||||||
type AliasedExpression struct {
|
type AliasedExpression struct {
|
||||||
Expression *Expression `parser:"@@"`
|
Expression *Expression `parser:"@@"`
|
||||||
As string `parser:"[ \"AS\" @Ident ]"`
|
As string `parser:"[ \"AS\" @Ident | \"AS\" @LitString ]"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Grammar for Expression
|
// Grammar for Expression
|
||||||
|
@ -383,3 +383,13 @@ func TestSqlLexerArithOps(t *testing.T) {
|
|||||||
// fmt.Printf("%d: %#v\n", i, t)
|
// fmt.Printf("%d: %#v\n", i, t)
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParseSelectStatement(t *testing.T) {
|
||||||
|
exp, err := ParseSelectStatement("select _3,_1,_2 as 'mytest' from S3object")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("parse alias sql error: %v", err)
|
||||||
|
}
|
||||||
|
if exp.selectAST.Expression.Expressions[2].As != "mytest" {
|
||||||
|
t.Fatalf("parse alias sql error: %s not equal %s", exp.selectAST.Expression.Expressions[2].As, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -112,6 +112,14 @@ func ParseSelectStatement(s string) (stmt SelectStatement, err error) {
|
|||||||
|
|
||||||
// Set table alias
|
// Set table alias
|
||||||
stmt.tableAlias = selectAST.From.As
|
stmt.tableAlias = selectAST.From.As
|
||||||
|
// Remove quotes from column aliases
|
||||||
|
if selectAST.Expression != nil {
|
||||||
|
for _, exp := range selectAST.Expression.Expressions {
|
||||||
|
if strings.HasSuffix(exp.As, "'") && strings.HasPrefix(exp.As, "'") && len(exp.As) >= 2 {
|
||||||
|
exp.As = exp.As[1 : len(exp.As)-1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user