diff --git a/common/pinot/pinotQueryValidator.go b/common/pinot/pinotQueryValidator.go index d869ff1c06c..e01fd32eef7 100644 --- a/common/pinot/pinotQueryValidator.go +++ b/common/pinot/pinotQueryValidator.go @@ -386,6 +386,12 @@ func processCustomString(comparisonExpr *sqlparser.ComparisonExpr, colNameStr st Type: sqlparser.StrVal, Val: []byte("%" + colValStr + "%"), } + + if colValStr == "" { + return fmt.Sprintf("(JSON_MATCH(Attr, '\"$.%s\" is not null') "+ + "AND REGEXP_LIKE(JSON_EXTRACT_SCALAR(Attr, '$.%s', 'string'), '^$'))", colNameStr, colNameStr) + } + return fmt.Sprintf("(JSON_MATCH(Attr, '\"$.%s\" is not null') "+ "AND REGEXP_LIKE(JSON_EXTRACT_SCALAR(Attr, '$.%s', 'string'), '%s*'))", colNameStr, colNameStr, colValStr) } diff --git a/common/pinot/pinotQueryValidator_test.go b/common/pinot/pinotQueryValidator_test.go index b7c7b1025b5..0705aa2b5a3 100644 --- a/common/pinot/pinotQueryValidator_test.go +++ b/common/pinot/pinotQueryValidator_test.go @@ -46,10 +46,14 @@ func TestValidateQuery(t *testing.T) { query: "WorkflowID = 'wid'", validated: "WorkflowID = 'wid'", }, - "Case3: query with custom field": { + "Case3-1: query with custom field": { query: "CustomStringField = 'custom'", validated: "(JSON_MATCH(Attr, '\"$.CustomStringField\" is not null') AND REGEXP_LIKE(JSON_EXTRACT_SCALAR(Attr, '$.CustomStringField', 'string'), 'custom*'))", }, + "Case3-2: query with custom field value is empty": { + query: "CustomStringField = ''", + validated: "(JSON_MATCH(Attr, '\"$.CustomStringField\" is not null') AND REGEXP_LIKE(JSON_EXTRACT_SCALAR(Attr, '$.CustomStringField', 'string'), '^$'))", + }, "Case4: custom field query with or in string": { query: "CustomStringField='Or'", validated: "(JSON_MATCH(Attr, '\"$.CustomStringField\" is not null') AND REGEXP_LIKE(JSON_EXTRACT_SCALAR(Attr, '$.CustomStringField', 'string'), 'Or*'))",