Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Add the expression support post processing #352

Merged

Conversation

penghuo
Copy link
Contributor

@penghuo penghuo commented Jan 23, 2020

Issue #, if available:
#229
#194
#270
#292

Description of changes:

1.Data Models

The following paragraph describe the BNF grammar for Expression Values.

value             -> collection_value
                     tuple_value
                     scalar_value
                     missing_value
missing_value     -> MISSING
tuple_value       -> {}
                   | {string_value: value (, string_value: value)*}
collection_value  -> [(value)+]
scalar_value      -> string_value
                   | float_value
                   | double_value
                   | integer_value
                   | long_value         

The type of the values are: collection_value, tuple_value, missing_value, scalar_value.

  • collection_value is an array could contain duplicated values. It is similar to the JSON array.
  • tuple_value is a set of <name, value> pairs.
  • missing_value denote the value is missing in the context.
  • scalar_value is the core data types defined in SQL

2.BindingTuple

BindingTuple is a set of <bindingName, value>. e.g. Taken the following sample JSON object as example, There are two <bindingName, value> pairs in the BindingTuple. (1) <“integerValue”, integer_value(1)>, (2) <“stringValue”, “string”>.

{
    "integerValue": 1,
    "stringValue":  "string"
}

3.Expression

The following paragraph describe the behavior of the Expression.

// constructors
reference exp    : ExprValue -> Exp
literal exp      : ExprValue -> Exp
unary exp        : Exp       -> Exp
binary exp       : Exp x Exp -> Exp

// observer
valueOf          : Exp x BindingTuple -> ExprValue

Let’s take an example to explain how to construct the expression and evaluate the expression in the BindingTuple context.

// BindingTuple
{
    "a": 1,
    "b": 2
}
// Construct Expression
addExpression = expression(ref("a"), ref("b"))

// valueOf Expression with BindingTuple.
// The evaluation is executed in application order.
addExpression.valueOf(bindingTuple)
-> (+ ref("a").valueOf(bindingTuple) ref("b").valueOf(bindingTuple))
-> (+ 1 2)
-> 3

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@penghuo penghuo assigned davidcui1225 and penghuo and unassigned davidcui1225 Jan 23, 2020
@penghuo penghuo requested a review from davidcui1225 January 23, 2020 00:25
@penghuo penghuo removed their assignment Jan 23, 2020
Copy link
Contributor

@davidcui1225 davidcui1225 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - just 1 minor question

}

@Test
public void absWithStringShouldThrowException() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any specific reason only ABS() and Tan2() were tested against with String values?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally all the type should been tested. the purpose of the test is to verify the error message is as expected.

@penghuo penghuo merged commit 3730ac6 into opendistro-for-elasticsearch:master Jan 24, 2020
@penghuo penghuo deleted the expression-support branch April 22, 2020 03:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants