From 51456e6adc7682f7198236408614e00c6bb7aff1 Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Wed, 30 Oct 2019 07:04:40 +0100 Subject: [PATCH] Select: Support Square Bracket Lists (#8457) Allows for S3 compatible `SELECT * from s3object s WHERE id IN [3,2]` Fixes #8422 --- pkg/s3select/select_test.go | 16 ++++++++++++++++ pkg/s3select/sql/parser.go | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/pkg/s3select/select_test.go b/pkg/s3select/select_test.go index 7467c040e..ba8b9214e 100644 --- a/pkg/s3select/select_test.go +++ b/pkg/s3select/select_test.go @@ -171,6 +171,22 @@ func TestJSONQueries(t *testing.T) { wantResult: `{"id":0,"title":"Test Record","desc":"Some text","synonyms":["foo","bar","whatever"]} {"id":1,"title":"Second Record","desc":"another text","synonyms":["some","synonym","value"]} {"id":2,"title":"Second Record","desc":"another text","numbers":[2,3,4]}`, + }, + { + name: "indexed-list-square-bracket", + 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-square-bracket", + query: `SELECT * from s3object s WHERE [7,8.5,9] IN s.nested`, + wantResult: `{"id":3,"title":"Second Record","desc":"another text","nested":[[2,3,4],[7,8.5,9]]}`, + }, + { + name: "indexed-list-square-bracket", + query: `SELECT * from s3object s WHERE id IN [3,2]`, + wantResult: `{"id":2,"title":"Second Record","desc":"another text","numbers":[2,3,4]} +{"id":3,"title":"Second Record","desc":"another text","nested":[[2,3,4],[7,8.5,9]]}`, }, { name: "index-wildcard-in", diff --git a/pkg/s3select/sql/parser.go b/pkg/s3select/sql/parser.go index d8d5c21ab..095008068 100644 --- a/pkg/s3select/sql/parser.go +++ b/pkg/s3select/sql/parser.go @@ -149,7 +149,7 @@ type Expression struct { // ListExpr represents a literal list with elements as expressions. type ListExpr struct { - Elements []*Expression `parser:"\"(\" @@ ( \",\" @@ )* \")\""` + Elements []*Expression `parser:"\"(\" @@ ( \",\" @@ )* \")\" | \"[\" @@ ( \",\" @@ )* \"]\""` } // AndCondition represents logical conjunction of clauses