Skip to content

Commit

Permalink
check time type in custom search attribute (#5822)
Browse files Browse the repository at this point in the history
* check time type in custom search attribute

* clean up

* add test

* refactor

* typo
  • Loading branch information
bowenxia committed Mar 27, 2024
1 parent 08e8553 commit 3a2a4d9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
9 changes: 7 additions & 2 deletions common/pinot/pinotQueryValidator.go
Expand Up @@ -334,19 +334,24 @@ func (qv *VisibilityQueryValidator) processCustomKey(expr sqlparser.Expr) (strin
if !ok {
return "", errors.New("invalid comparison expression, right")
}
colValStr := string(colVal.Val)

// get the value type
indexValType := common.ConvertIndexedValueTypeToInternalType(valType, log.NewNoop())

operator := comparisonExpr.Operator
colValStr := string(colVal.Val)

switch indexValType {
case types.IndexedValueTypeString:
return processCustomString(comparisonExpr, colNameStr, colValStr), nil
case types.IndexedValueTypeKeyword:
return processCustomKeyword(operator, colNameStr, colValStr), nil
case types.IndexedValueTypeDatetime:
var err error
colVal, err = trimTimeFieldValueFromNanoToMilliSeconds(colVal)
if err != nil {
return "", fmt.Errorf("trim time field %s got error: %w", colNameStr, err)
}
colValStr := string(colVal.Val)
return processCustomNum(operator, colNameStr, colValStr, "BIGINT"), nil
case types.IndexedValueTypeDouble:
return processCustomNum(operator, colNameStr, colValStr, "DOUBLE"), nil
Expand Down
13 changes: 13 additions & 0 deletions common/pinot/pinotQueryValidator_test.go
Expand Up @@ -194,6 +194,19 @@ func TestValidateQuery(t *testing.T) {
query: "CloseTime != missing and StartTime >= 1707662555754408145",
validated: "CloseTime != -1 and StartTime >= 1707662555754",
},
"Case15-17: CustomDatetimeField with big int type case": {
query: "CustomDatetimeField = 1707319950000",
validated: "JSON_MATCH(Attr, '\"$.CustomDatetimeField\"=''1707319950000''')",
},
"Case15-18: CustomDatetimeField with time.Time() type case": {
query: "CustomDatetimeField = '2024-02-07T15:32:30Z'",
validated: "JSON_MATCH(Attr, '\"$.CustomDatetimeField\"=''1707319950000''')",
},
"Case15-19: CustomDatetimeField with error case": {
query: "CustomDatetimeField = 'test'",
validated: "",
err: "trim time field CustomDatetimeField got error: error: failed to parse int from SQLVal test",
},
"Case16-1: custom int attribute greater than or equal to": {
query: "CustomIntField >= 0",
validated: "(JSON_MATCH(Attr, '\"$.CustomIntField\" is not null') AND CAST(JSON_EXTRACT_SCALAR(Attr, '$.CustomIntField') AS INT) >= 0)",
Expand Down

0 comments on commit 3a2a4d9

Please sign in to comment.