Repository navigation
Conversation
Member
Author
|
This change is the parser support for plugin query operators. The pull requests that build on it:
Merge order: this pull request first, then cinchapi/concourse#1555 after its ccl dependency moves to the released version, then cinchapi/vector-search#37 after its Concourse dependency moves to the released version. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
Before this change, a CCL condition could not use an operator that a Concourse
plugin provides. CCL read an operator only from the tokens that its grammar
reserves, such as
=,bw,like, andcontains, so the conditionbio about "red running shoes"was a syntax error. Each operator also took afixed number of values (one, or two for
bw), whether the condition came fromCCL text or from a list of symbols, such as the one a Concourse
Criteriabuilds. The
Operatorinterface could state only that fixed number of values,and it had no way to reject a value of the wrong kind.
An order could apply only a plain function name to a key, so
order by bio | vec.about descdid not parse either.Change
A condition can use a custom operator, which is an operator that CCL does not
define, such as one that a Concourse plugin provides. A word in the operator
position that is not a built-in operator names a custom operator, and the word
can be plain, as in
about, or qualified with periods, as invec.about. Theoperator function that the caller passes to
Compiler.createresolves the wordto an
Operator, the same way it resolves the symbol of a built-in operator.One or more values follow the word, and a timestamp,
and,or, andparentheses work with it as they do with a built-in operator.
Operatorhas three new default methods that describe the values an operatoraccepts.
minOperands()andmaxOperands()bound how many values a conditioncan give it, and
validate(List<Object>)throwsIllegalArgumentExceptionforvalues it rejects. The parser applies those rules through
Parsing.checkOperands, a new public method.In this example, a caller defines an operator that takes a phrase and an
optional limit, and resolves both
aboutandvec.aboutto it.Parsing.isOperatorName(String)returns whether a name is one plain word that acustom operator can use as its symbol.
Most of the diff is mechanical, because
Grammar.javais generated fromgrammar.jjt, and thewithinduration constants inParsingonly moved tothe end of the class.
Semantics
Custom operators in CCL
value that contains spaces needs quotes. For example,
loc near x 1 2givesnearthree values, whilea = 1 2 3still gives=the single value1 2 3.findOrInsert, a quoted string that ends the command is the command's JSONand not a value. For example,
findOrInsert bio about x 'y' '{"a": 1}'givesaboutthe valuesxandy.SyntaxExceptionwhose message names the word, its line and column, and thereason that the function gave.
Value checks
the condition comes from CCL text or from a list of symbols. A condition with
too few values, too many values, or values that
validaterejects fails witha
SyntaxExceptionthat names the operator.validateonly after the number of values is within bounds,and it passes the parsed values in order. So
validatecan read the firstvalue whenever
minOperands()is at least 1.minOperands()andmaxOperands()both returnoperands(), andvalidateaccepts any values. So an existingOperatortakes exactlyoperands()values, and every built-in operator parses as it did before.as its
maxOperands()allows, so aCriteriacan give a custom operator morethan two values.