From 38e6d911eaa2579f92c42dde31239f2736d2f893 Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Wed, 30 Oct 2019 09:16:55 +0100 Subject: [PATCH] S3 Select: Detect full object (#8456) Check if select is `SELECT s.* from S3Object s` and forward it to All Fixes #8371 and makes this case run significantly faster. --- pkg/s3select/select_test.go | 10 ++++++++++ pkg/s3select/sql/statement.go | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/pkg/s3select/select_test.go b/pkg/s3select/select_test.go index ba8b9214e..79ab00db7 100644 --- a/pkg/s3select/select_test.go +++ b/pkg/s3select/select_test.go @@ -165,6 +165,16 @@ func TestJSONQueries(t *testing.T) { query: `SELECT * from s3object s WHERE (7,8.5,9) = s.nested[1]`, wantResult: `{"id":3,"title":"Second Record","desc":"another text","nested":[[2,3,4],[7,8.5,9]]}`, }, + { + name: "indexed-list-match-equals-s-star", + query: `SELECT s.* from s3object s WHERE (7,8.5,9) = s.nested[1]`, + wantResult: `{"id":3,"title":"Second Record","desc":"another text","nested":[[2,3,4],[7,8.5,9]]}`, + }, + { + name: "indexed-list-match-equals-s-index", + query: `SELECT s.nested[1], s.nested[0] from s3object s WHERE (7,8.5,9) = s.nested[1]`, + wantResult: `{"_1":[7,8.5,9],"_2":[2,3,4]}`, + }, { name: "indexed-list-match-not-equals", query: `SELECT * from s3object s WHERE (7,8.5,9) != s.nested[1]`, diff --git a/pkg/s3select/sql/statement.go b/pkg/s3select/sql/statement.go index 57814dfd8..fe42890a5 100644 --- a/pkg/s3select/sql/statement.go +++ b/pkg/s3select/sql/statement.go @@ -56,6 +56,21 @@ func ParseSelectStatement(s string) (stmt SelectStatement, err error) { err = errQueryParseFailure(err) return } + + // Check if select is "SELECT s.* from S3Object s" + if !selectAST.Expression.All && + len(selectAST.Expression.Expressions) == 1 && + len(selectAST.Expression.Expressions[0].Expression.And) == 1 && + len(selectAST.Expression.Expressions[0].Expression.And[0].Condition) == 1 && + selectAST.Expression.Expressions[0].Expression.And[0].Condition[0].Operand != nil && + selectAST.Expression.Expressions[0].Expression.And[0].Condition[0].Operand.Operand.Left != nil && + selectAST.Expression.Expressions[0].Expression.And[0].Condition[0].Operand.Operand.Left.Left != nil && + selectAST.Expression.Expressions[0].Expression.And[0].Condition[0].Operand.Operand.Left.Left.Primary != nil && + selectAST.Expression.Expressions[0].Expression.And[0].Condition[0].Operand.Operand.Left.Left.Primary.JPathExpr != nil { + if selectAST.Expression.Expressions[0].Expression.And[0].Condition[0].Operand.Operand.Left.Left.Primary.JPathExpr.String() == selectAST.From.As+".*" { + selectAST.Expression.All = true + } + } stmt.selectAST = &selectAST // Check the parsed limit value