diff --git a/ppl/src/main/antlr/OpenDistroPPLLexer.g4 b/ppl/src/main/antlr/OpenDistroPPLLexer.g4 new file mode 100644 index 0000000000..d3db17281d --- /dev/null +++ b/ppl/src/main/antlr/OpenDistroPPLLexer.g4 @@ -0,0 +1,256 @@ +/* + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +lexer grammar OpenDistroPPLLexer; + +channels { WHITESPACE, ERRORCHANNEL } + + +// COMMAND KEYWORDS +SEARCH: 'SEARCH'; +FROM: 'FROM'; +WHERE: 'WHERE'; +FIELDS: 'FIELDS'; +RENAME: 'RENAME'; +STATS: 'STATS'; +DEDUP: 'DEDUP'; +SORT: 'SORT'; +EVAL: 'EVAL'; + +// COMMAND ASSIST KEYWORDS +AS: 'AS'; +BY: 'BY'; +SOURCE: 'SOURCE'; +INDEX: 'INDEX'; +D: 'D'; +DESC: 'DESC'; + +// CLAUSE KEYWORDS +SORTBY: 'SORTBY'; + +// FIELD KEYWORDS +AUTO: 'AUTO'; +STR: 'STR'; +IP: 'IP'; +NUM: 'NUM'; + +// ARGUMENT KEYWORDS +KEEPEVENTS: 'KEEPEVENTS'; +KEEPEMPTY: 'KEEPEMPTY'; +CONSECUTIVE: 'CONSECUTIVE'; +DEDUP_SPLITVALUES: 'DEDUP_SPLITVALUES'; +PARTITIONS: 'PARTITIONS'; +ALLNUM: 'ALLNUM'; +DELIM: 'DELIM'; + +// COMPARISON FUNCTION KEYWORDS +CASE: 'CASE'; +IN: 'IN'; + +// LOGICAL KEYWORDS +NOT: 'NOT'; +OR: 'OR'; +AND: 'AND'; +TRUE: 'TRUE'; +FALSE: 'FALSE'; + +// DATASET TYPES +DATAMODEL: 'DATAMODEL'; +LOOKUP: 'LOOKUP'; +SAVEDSEARCH: 'SAVEDSEARCH'; + +// SPECIAL CHARACTERS AND OPERATORS +PIPE: '|'; +COMMA: ','; +DOT: '.'; +EQUAL: '='; +GREATER: '>'; +LESS: '<'; +NOT_GREATER: '<' '='; +NOT_LESS: '>' '='; +NOT_EQUAL: '!' '='; +PLUS: '+'; +MINUS: '-'; +STAR: '*'; +DIVIDE: '/'; +MODULE: '%'; +EXCLAMATION_SYMBOL: '!'; +COLON: ':'; +LT_PRTHS: '('; +RT_PRTHS: ')'; + +// AGGREGATIONS +AVG: 'AVG'; +COUNT: 'COUNT'; +DISTINCT_COUNT: 'DISTINCT_COUNT'; +ESTDC: 'ESTDC'; +ESTDC_ERROR: 'ESTDC_ERROR'; +MAX: 'MAX'; +MEAN: 'MEAN'; +MEDIAN: 'MEDIAN'; +MIN: 'MIN'; +MODE: 'MODE'; +RANGE: 'RANGE'; +STDEV: 'STDEV'; +STDEVP: 'STDEVP'; +SUM: 'SUM'; +SUMSQ: 'SUMSQ'; +VAR: 'VAR'; +VARP: 'VARP'; +PERCENTILE: 'PERCENTILE'; +FIRST: 'FIRST'; +LAST: 'LAST'; +LIST: 'LIST'; +VALUES: 'VALUES'; +EARLIEST: 'EARLIEST'; +EARLIEST_TIME: 'EARLIEST_TIME'; +LATEST: 'LATEST'; +LATEST_TIME: 'LATEST_TIME'; +PER_DAY: 'PER_DAY'; +PER_HOUR: 'PER_HOUR'; +PER_MINUTE: 'PER_MINUTE'; +PER_SECOND: 'PER_SECOND'; +RATE: 'RATE'; +SPARKLINE: 'SPARKLINE'; +C: 'C'; +DC: 'DC'; + +// BASIC FUNCTIONS +ABS: 'ABS'; +ACOS: 'ACOS'; +ADD: 'ADD'; +ADDDATE: 'ADDDATE'; +ADDTIME: 'ADDTIME'; +ASCII: 'ASCII'; +ASIN: 'ASIN'; +ATAN: 'ATAN'; +ATAN2: 'ATAN2'; +CBRT: 'CBRT'; +CEIL: 'CEIL'; +CONCAT: 'CONCAT'; +CONCAT_WS: 'CONCAT_WS'; +COS: 'COS'; +COSH: 'COSH'; +COT: 'COT'; +CURDATE: 'CURDATE'; +DATE: 'DATE'; +DATE_FORMAT: 'DATE_FORMAT'; +DAYOFMONTH: 'DAYOFMONTH'; +DEGREES: 'DEGREES'; +E: 'E'; +EXP: 'EXP'; +EXPM1: 'EXPM1'; +FLOOR: 'FLOOR'; +GREATEST: 'GREATEST'; +IF: 'IF'; +IFNULL: 'IFNULL'; +ISNULL: 'ISNULL'; +LEAST: 'LEAST'; +LEFT: 'LEFT'; +LENGTH: 'LENGTH'; +LN: 'LN'; +LOCATE: 'LOCATE'; +LOG: 'LOG'; +LOG10: 'LOG10'; +LOG2: 'LOG2'; +LOWER: 'LOWER'; +LTRIM: 'LTRIM'; +MAKETIME: 'MAKETIME'; +MISSING: 'MISSING'; +MODULUS: 'MODULUS'; +MONTH: 'MONTH'; +MONTHNAME: 'MONTHNAME'; +MULTIPLY: 'MULTIPLY'; +NOW: 'NOW'; +PI: 'PI'; +POW: 'POW'; +POWER: 'POWER'; +RADIANS: 'RADIANS'; +RAND: 'RAND'; +REPLACE: 'REPLACE'; +RIGHT: 'RIGHT'; +RINT: 'RINT'; +ROUND: 'ROUND'; +RTRIM: 'RTRIM'; +SIGN: 'SIGN'; +SIGNUM: 'SIGNUM'; +SIN: 'SIN'; +SINH: 'SINH'; +SQRT: 'SQRT'; +SUBTRACT: 'SUBTRACT'; +SUBSTRING: 'SUBSTRING'; +TAN: 'TAN'; +TIMESTAMP: 'TIMESTAMP'; +TRIM: 'TRIM'; +UPPER: 'UPPER'; +YEAR: 'YEAR'; + +// ES FUNCTIONS +DATE_HISTOGRAM: 'DATE_HISTOGRAM'; +DAY_OF_MONTH: 'DAY_OF_MONTH'; +DAY_OF_YEAR: 'DAY_OF_YEAR'; +DAY_OF_WEEK: 'DAY_OF_WEEK'; +EXCLUDE: 'EXCLUDE'; +EXTENDED_STATS: 'EXTENDED_STATS'; +FIELD: 'FIELD'; +FILTER: 'FILTER'; +GEO_BOUNDING_BOX: 'GEO_BOUNDING_BOX'; +GEO_CELL: 'GEO_CELL'; +GEO_DISTANCE: 'GEO_DISTANCE'; +GEO_DISTANCE_RANGE: 'GEO_DISTANCE_RANGE'; +GEO_INTERSECTS: 'GEO_INTERSECTS'; +GEO_POLYGON: 'GEO_POLYGON'; +HISTOGRAM: 'HISTOGRAM'; +HOUR_OF_DAY: 'HOUR_OF_DAY'; +INCLUDE: 'INCLUDE'; +IN_TERMS: 'IN_TERMS'; +MATCHPHRASE: 'MATCHPHRASE'; +MATCH_PHRASE: 'MATCH_PHRASE'; +MATCHQUERY: 'MATCHQUERY'; +MATCH_QUERY: 'MATCH_QUERY'; +MINUTE_OF_DAY: 'MINUTE_OF_DAY'; +MINUTE_OF_HOUR: 'MINUTE_OF_HOUR'; +MONTH_OF_YEAR: 'MONTH_OF_YEAR'; +MULTIMATCH: 'MULTIMATCH'; +MULTI_MATCH: 'MULTI_MATCH'; +NESTED: 'NESTED'; +PERCENTILES: 'PERCENTILES'; +REGEXP_QUERY: 'REGEXP_QUERY'; +REVERSE_NESTED: 'REVERSE_NESTED'; +QUERY: 'QUERY'; +SCORE: 'SCORE'; +SECOND_OF_MINUTE: 'SECOND_OF_MINUTE'; +TERM: 'TERM'; +TERMS: 'TERMS'; +TOPHITS: 'TOPHITS'; +WEEK_OF_YEAR: 'WEEK_OF_YEAR'; +WILDCARDQUERY: 'WILDCARDQUERY'; +WILDCARD_QUERY: 'WILDCARD_QUERY'; + +// LITERALS AND VALUES +STRING_LITERAL: DQUOTA_STRING | SQUOTA_STRING | BQUOTA_STRING; +ID: ID_LITERAL; +DOT_ID: '.' ID; +DECIMAL_LITERAL: DEC_DIGIT+; +// TODO: define WCFIELD + +fragment ID_LITERAL: [A-Z_$0-9@]*?[A-Z_$\-]+?[A-Z_$\-0-9]*; +fragment DQUOTA_STRING: '"' ( '\\'. | '""' | ~('"'| '\\') )* '"'; +fragment SQUOTA_STRING: '\'' ('\\'. | '\'\'' | ~('\'' | '\\'))* '\''; +fragment BQUOTA_STRING: '`' ( '\\'. | '``' | ~('`'|'\\'))* '`'; +fragment DEC_DIGIT: [0-9]; + + +ERROR_RECOGNITION: . -> channel(ERRORCHANNEL); \ No newline at end of file diff --git a/ppl/src/main/antlr/OpenDistroPPLParser.g4 b/ppl/src/main/antlr/OpenDistroPPLParser.g4 new file mode 100644 index 0000000000..300e71b515 --- /dev/null +++ b/ppl/src/main/antlr/OpenDistroPPLParser.g4 @@ -0,0 +1,314 @@ +/* + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + + +parser grammar OpenDistroPPLParser; +options { tokenVocab=OpenDistroPPLLexer; } + +root + : pplStatement? EOF + ; + +/** statement */ +pplStatement + : searchCommand (PIPE commands)* + ; + + +/** commands */ +commands + : whereCommand | fieldsCommand | renameCommand | statsCommand | dedupCommand | sortCommand | evalCommand + ; + +searchCommand + : (SEARCH)? fromClause #searchWithoutFilter + | (SEARCH)? fromClause logicalExpression #searchFromClauseLogicExpr + | (SEARCH)? logicalExpression fromClause #searchLogicExprFromClause + ; + +whereCommand + : WHERE evalExpression + ; + +fieldsCommand + : FIELDS fieldList + ; + +renameCommand + : RENAME wcField AS wcField + ; + +statsCommand + : STATS (statsArgument)* (statsAggTerm | sparklineAggTerm) (byClause)? (dedupSplitValues)? + ; + +dedupCommand + : DEDUP (number=decimalLiteral)? fieldList (dedupArgument)* (SORTBY sortbyClause)? + ; + +sortCommand + : SORT (count=decimalLiteral)? sortbyClause (D | DESC)? + ; + +evalCommand + : EVAL fieldExpression EQUAL evalExpression (COMMA fieldExpression EQUAL evalExpression) + ; + +/** arguments */ +dedupArgument + : KEEPEVENTS EQUAL booleanLiteral #keepevents + | KEEPEMPTY EQUAL booleanLiteral #keepempty + | CONSECUTIVE EQUAL booleanLiteral #consecutive + ; + +dedupSplitValues + : DEDUP_SPLITVALUES EQUAL booleanLiteral + ; + +statsArgument + : PARTITIONS EQUAL decimalLiteral #partitions + | ALLNUM EQUAL booleanLiteral #allnum + | DELIM EQUAL stringLiteral #delim + ; + +/** clauses */ +fromClause + : SOURCE EQUAL tableSource + | INDEX EQUAL tableSource + ; + +byClause + : BY fieldList + ; + +sortbyClause + : (PLUS | MINUS) sortField (COMMA (PLUS | MINUS) sortField)* + ; + +/** aggregation terms */ +aggregationTerm + : statsAggTerm | sparklineAggTerm + ; + +statsAggTerm + : statsFunction LT_PRTHS (fieldExpression)? RT_PRTHS + ; + +sparklineAggTerm + : sparklineAggregation | sparklineFunction + ; + +/** aggregation functions */ +statsFunction + : aggregationFunction | eventOrderFunction | multivalueStatsChartFunction | timeFunction + ; + +aggregationFunction + : aggFunctionName LT_PRTHS fieldExpression RT_PRTHS + | percentileAggFunction + ; + +aggFunctionName + : AVG | COUNT | DISTINCT_COUNT | ESTDC | ESTDC_ERROR | MAX | MEAN | MEDIAN | MIN | MODE | RANGE + | STDEV | STDEVP | SUM | SUMSQ | VAR | VARP + ; + +percentileAggFunction + : PERCENTILE LESS fieldExpression GREATER LT_PRTHS fieldExpression RT_PRTHS + ; + +eventOrderFunction + : FIRST LT_PRTHS fieldExpression RT_PRTHS + | LAST LT_PRTHS fieldExpression RT_PRTHS + ; + +multivalueStatsChartFunction + : LIST LT_PRTHS fieldExpression RT_PRTHS + | VALUES LT_PRTHS fieldExpression RT_PRTHS + ; + +timeFunction + : timeFunctionName LT_PRTHS fieldExpression RT_PRTHS + ; + +timeFunctionName + : EARLIEST | EARLIEST_TIME | LATEST | LATEST_TIME | PER_DAY | PER_HOUR | PER_MINUTE | PER_SECOND | RATE + ; + +sparklineAggregation + : SPARKLINE LT_PRTHS COUNT LT_PRTHS wcField RT_PRTHS COMMA spanLength=decimalLiteral RT_PRTHS + | SPARKLINE RT_PRTHS sparklineFunction LT_PRTHS wcField RT_PRTHS COMMA spanLength=decimalLiteral RT_PRTHS + ; + +sparklineFunction + : sparklineFunctionName LT_PRTHS fieldExpression RT_PRTHS + ; + +sparklineFunctionName + : C | COUNT | DC | MEAN | AVG | STDEV | STDEVP | VAR | VARP | SUM | SUMSQ | MIN | MAX | RANGE + ; + +/** expressions */ +expression + : logicalExpression + | booleanExpression + | comparisonExpression + | evalExpression + ; + +logicalExpression + : booleanExpression #booleanLabel + | comparisonExpression #comparsion + | evalExpression #eval + | NOT logicalExpression #logicalNot + | left=logicalExpression OR right=logicalExpression #logicalOrBinary + | left=logicalExpression (AND)? right=logicalExpression #logicalAndBinary + ; + +evalExpression + : literalValue EQUAL literalValue + | evalFunctionCall + ; + +comparisonExpression + : left=fieldExpression comparisonOperator right=literalValue + | fieldExpression IN valueList + ; + +booleanExpression + : LT_PRTHS booleanExpression RT_PRTHS + | booleanLiteral + ; + +/** tables */ +tableSource + : ident + ; + +/** fields */ +fieldList + : fieldExpression (COMMA fieldExpression)* + ; + +sortField + : fieldExpression #defaultSort + | AUTO LT_PRTHS fieldExpression RT_PRTHS #autoSort + | STR LT_PRTHS fieldExpression RT_PRTHS #strSort + | IP LT_PRTHS fieldExpression RT_PRTHS #ipSort + | NUM LT_PRTHS fieldExpression RT_PRTHS #numSort + ; + +wcField + : WCFIELD + ; + +fieldExpression + : ident + ; + +/** functions */ +evalFunctionCall + : evalFunctionName LT_PRTHS functionArgs RT_PRTHS + ; + +evalFunctionName + : basicFunctionNameBase | esFunctionNameBase + ; + +basicFunctionNameBase + : ABS | ACOS | ADD | ASCII | ASIN | ATAN | ATAN2 | CBRT | CEIL | CONCAT | CONCAT_WS + | COS | COSH | COT | CURDATE | DATE | DATE_FORMAT | DAYOFMONTH | DEGREES + | E | EXP | EXPM1 | FLOOR | IF | IFNULL | ISNULL | LEFT | LENGTH | LN | LOCATE | LOG + | LOG10 | LOG2 | LOWER | LTRIM | MAKETIME | MODULUS | MONTH | MONTHNAME | MULTIPLY + | NOW | PI | POW | POWER | RADIANS | RAND | REPLACE | RIGHT | RINT | ROUND | RTRIM + | SIGN | SIGNUM | SIN | SINH | SQRT | SUBSTRING | SUBTRACT | TAN | TIMESTAMP | TRIM + | UPPER | YEAR | ADDDATE | ADDTIME | GREATEST | LEAST + ; + +esFunctionNameBase + : DATE_HISTOGRAM | DAY_OF_MONTH | DAY_OF_YEAR | DAY_OF_WEEK | EXCLUDE + | EXTENDED_STATS | FILTER | GEO_BOUNDING_BOX | GEO_CELL | GEO_DISTANCE | GEO_DISTANCE_RANGE | GEO_INTERSECTS + | GEO_POLYGON | INCLUDE | IN_TERMS | HISTOGRAM | HOUR_OF_DAY + | MATCHPHRASE | MATCH_PHRASE | MATCHQUERY | MATCH_QUERY | MINUTE_OF_DAY + | MINUTE_OF_HOUR | MISSING | MONTH_OF_YEAR | MULTIMATCH | MULTI_MATCH | NESTED + | PERCENTILES | QUERY | RANGE | REGEXP_QUERY | REVERSE_NESTED | SCORE + | SECOND_OF_MINUTE | STATS | TERM | TERMS | TOPHITS + | WEEK_OF_YEAR | WILDCARDQUERY | WILDCARD_QUERY + ; + +functionArgs + : functionArg (COMMA functionArg)* + ; + +functionArg + : constant | fullColumnName | expression | evalFunctionCall + ; + +/** operators */ +comparisonOperator + : EQUAL | NOT_EQUAL | LESS | NOT_LESS | GREATER | NOT_GREATER + ; + +/** literals and values*/ +literalValue + : stringLiteral + | decimalLiteral + ; + +stringLiteral + : STRING_LITERAL + ; + +decimalLiteral + : DECIMAL_LITERAL + ; + +booleanLiteral + : TRUE | FALSE + ; + +valueList + : LT_PRTHS literalValue (COMMA literalValue)* RT_PRTHS + ; + +fullColumnName + : simpleId DOT_ID* + ; + +constant + : stringLiteral | decimalLiteral + | MINUS decimalLiteral + | booleanLiteral + ; + +simpleId + : ID + | DOT_ID + | STRING_LITERAL + ; + +ident + : ID + | DOT_ID + ; + +/** dataset */ +datasetType + : DATAMODEL | LOOKUP | SAVEDSEARCH + ; + +datasetName + : + ; diff --git a/ppl/src/main/antlr/PPLLexer.g4 b/ppl/src/main/antlr/PPLLexer.g4 deleted file mode 100644 index 80c85200d6..0000000000 --- a/ppl/src/main/antlr/PPLLexer.g4 +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -lexer grammar PPLLexer; - -channels { WHITESPACE, ERRORCHANNEL } - - -// COMMAND KEYWORDS -SEARCH: 'SEARCH'; -TOP: 'TOP'; -RARE: 'RARE'; -FROM: 'FROM'; -WHERE: 'WHERE'; -LIMIT: 'LIMIT'; -BY: 'BY'; -COUNTFIELD: 'COUNTFIELD'; -SOURCE: 'SOURCE'; -INDEX: 'INDEX'; -FIELDS: 'FIELDS'; -STATS: 'STATS'; -OTHERSTR: 'OTHERSTR'; -PERCENTFIELD: 'PERCENTFIELD'; -SHOWCOUNT: 'SHOWCOUNT'; -SHOWPERC: 'SHOWPERC'; -USEOTHER: 'USEROTHER'; - - - -// COMPARISON FUNCTION KEYWORDS -CASE: 'CASE'; -IN: 'IN'; - - -// MATH FUNCTION KEYWORDS -ABS: 'ABS'; -POW: 'POW'; - - -// AGGREGATE FUNCTION KEYWORDS -AVG: 'AVG'; -COUNT: 'COUNT'; - - -// LOGICAL KEYWORDS -NOT: 'NOT'; -OR: 'OR'; -AND: 'AND'; -TRUE: 'TRUE'; -FALSE: 'FALSE'; - - -// DATASET TYPE -DATAMODEL: 'DATAMODEL'; -LOOKUP: 'LOOKUP'; -SAVEDSEARCH: 'SAVEDSEARCH'; - - -// SPECIAL CHARS AND OPERATORS -PIPE: '|'; -COMMA: ','; -DOT: '.'; -EQUAL_SYMBOL: '='; -GREATER_SYMBOL: '>'; -LESS_SYMBOL: '<'; -NOT_GREATER: '<' '='; -NOT_LESS: '>' '='; -NOT_EQUAL: '!' '='; -PLUS: '+'; -MINUS: '-'; -STAR: '*'; -DIVIDE: '/'; -MODULE: '%'; -EXCLAMATION_SYMBOL: '!'; -COLON: ':'; -LT_PRTHS: '('; -RT_PRTHS: ')'; - - -STRING_LITERAL: DQUOTA_STRING | SQUOTA_STRING | BQUOTA_STRING; -ID: ID_LITERAL; -DOT_ID: '.' ID; -DECIMAL_LITERAL: DEC_DIGIT+; - -fragment ID_LITERAL: [A-Z_$0-9@]*?[A-Z_$\-]+?[A-Z_$\-0-9]*; -fragment DQUOTA_STRING: '"' ( '\\'. | '""' | ~('"'| '\\') )* '"'; -fragment SQUOTA_STRING: '\'' ('\\'. | '\'\'' | ~('\'' | '\\'))* '\''; -fragment BQUOTA_STRING: '`' ( '\\'. | '``' | ~('`'|'\\'))* '`'; -fragment DEC_DIGIT: [0-9]; - - - -ERROR_RECOGNITION: . -> channel(ERRORCHANNEL); \ No newline at end of file diff --git a/ppl/src/main/antlr/PPLParser.g4 b/ppl/src/main/antlr/PPLParser.g4 deleted file mode 100644 index e7a3445e8b..0000000000 --- a/ppl/src/main/antlr/PPLParser.g4 +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -parser grammar PPLParser; -options { tokenVocab=PPLLexer; } - -root - : pplStatement? EOF - ; - -//pplStatement -// : searchCommands | reportsCommands -// (PIPE resultsCommands)? -// (PIPE (searchCommands | reportsCommands))* -// EOF -// ; - -//pplStatement -// : searchCommands (PIPE fieldsCommand)* #searchFields -// | searchCommands PIPE topCommand #searchTop -// ; - -pplStatement - : searchCommands (PIPE commands)* - ; - -commands - : fieldsCommand | statsCommand | topCommand | rareCommand - ; - -searchCommands - : searchCommand - ; - -//reportsCommands -// : topCommand -// ; - -resultsCommands - : filteringCommands - ; - -filteringCommands - : fromCommand | whereCommand - ; - -searchCommand - : (SEARCH)? fromClause #searchWithoutFilter - | (SEARCH)? fromClause logicalExpression #searchFromClauseLogicExpr - | (SEARCH)? logicalExpression fromClause #searchLogicExprFromClause - ; - -statsCommand - : STATS statsAggTerm+ byClause? - ; - -statsAggTerm - : statsFunc LT_PRTHS (fieldExpression)? RT_PRTHS - ; -statsFunc - : AVG | COUNT - ; - -fromClause - : SOURCE EQUAL_SYMBOL tableSource - | INDEX EQUAL_SYMBOL tableSource - ; - -tableSource - : ident #tableSourceID - ; - -fieldsCommand - : FIELDS fieldList - ; - -topCommand - : TOP count=decimalLiteral? topOptions* fieldList byClause? - ; - -rareCommand - : RARE count=decimalLiteral? topOptions* fieldList byClause? - ; - -fromCommand - : FROM datasetType COLON datasetName - | FROM datasetType datasetName - ; - -whereCommand - : WHERE evalExpression - ; - -logicalExpression - : booleanExpression #booleanLabel - | comparisonExpression #comparsion - | evalExpression #eval - | NOT logicalExpression #logicalNot - | left=logicalExpression OR right=logicalExpression #logicalOrBinary - | left=logicalExpression (AND)? right=logicalExpression #logicalAndBinary - ; - -booleanExpression - : LT_PRTHS booleanExpression RT_PRTHS - | booleanLiteral - ; - -comparisonExpression - : fieldExpression comparisonOperator valueExpression - | fieldExpression IN valueList - ; - -evalExpression - : literalValue EQUAL_SYMBOL literalValue - | evalFunctionCall - ; - -expression - : logicalExpression - | booleanExpression - | comparisonExpression - | evalExpression - ; - -evalFunctionCall - : evalFunctionName LT_PRTHS functionArgs RT_PRTHS - ; - -topOptions - : COUNTFIELD EQUAL_SYMBOL stringLiteral #countfieldTopOption - | LIMIT EQUAL_SYMBOL decimalLiteral #limitTopOption - | OTHERSTR EQUAL_SYMBOL stringLiteral #otherstrTopOption - | PERCENTFIELD EQUAL_SYMBOL stringLiteral #percentfieldTopOption - | SHOWCOUNT EQUAL_SYMBOL booleanLiteral #showcountTopOption - | SHOWPERC EQUAL_SYMBOL booleanLiteral #showpercTopOption - | USEOTHER EQUAL_SYMBOL booleanLiteral #useotherTopOption - ; - -datasetType - : DATAMODEL | LOOKUP | SAVEDSEARCH - ; - -datasetName - : ID - ; - -byClause - : BY fieldList - ; - -booleanLiteral - : TRUE | FALSE - ; - -comparisonOperator - : EQUAL_SYMBOL | NOT_EQUAL | LESS_SYMBOL | NOT_LESS | GREATER_SYMBOL | NOT_GREATER - ; - -evalFunctionName - : evalFunctionNameBase - ; - -functionArgs - : functionArg (COMMA functionArg)* - ; - -functionArg - : constant | fullColumnName | expression | evalFunctionCall - ; - -fieldExpression - : ident - ; - -fieldList - : fieldExpression (COMMA fieldExpression)* - ; - -valueExpression - : literalValue - ; - -valueList - : LT_PRTHS literalValue (COMMA literalValue)* RT_PRTHS - ; - -constant - : stringLiteral | decimalLiteral - | MINUS decimalLiteral - | booleanLiteral - ; - -literalValue - : stringLiteral - | decimalLiteral - ; - -stringLiteral - : STRING_LITERAL - ; - -decimalLiteral - : DECIMAL_LITERAL - ; - -fullColumnName - : simpleId DOT_ID* - ; - -ident - : ID - | DOT_ID - ; - -simpleId - : ID - | DOT_ID - | STRING_LITERAL - ; - -evalFunctionNameBase - : POW | ABS - ; - - - diff --git a/ppl/src/main/java/com/amazon/opendistroforelasticsearch/sql/ppl/antlr/PPLSyntaxParser.java b/ppl/src/main/java/com/amazon/opendistroforelasticsearch/sql/ppl/antlr/PPLSyntaxParser.java index 3b796b0c9d..10ee4e2461 100644 --- a/ppl/src/main/java/com/amazon/opendistroforelasticsearch/sql/ppl/antlr/PPLSyntaxParser.java +++ b/ppl/src/main/java/com/amazon/opendistroforelasticsearch/sql/ppl/antlr/PPLSyntaxParser.java @@ -17,8 +17,8 @@ import com.amazon.opendistroforelasticsearch.sql.common.antlr.CaseInsensitiveCharStream; import com.amazon.opendistroforelasticsearch.sql.common.antlr.SyntaxAnalysisErrorListener; -import com.amazon.opendistroforelasticsearch.sql.ppl.antlr.parser.PPLLexer; -import com.amazon.opendistroforelasticsearch.sql.ppl.antlr.parser.PPLParser; +import com.amazon.opendistroforelasticsearch.sql.ppl.antlr.parser.OpenDistroPPLLexer; +import com.amazon.opendistroforelasticsearch.sql.ppl.antlr.parser.OpenDistroPPLParser; import org.antlr.v4.runtime.CommonTokenStream; import org.antlr.v4.runtime.Lexer; import org.antlr.v4.runtime.tree.ParseTree; @@ -28,18 +28,18 @@ */ public class PPLSyntaxParser { public ParseTree analyzeSyntax(String sql) { - PPLParser parser = createParser(createLexer(sql)); + OpenDistroPPLParser parser = createParser(createLexer(sql)); parser.addErrorListener(new SyntaxAnalysisErrorListener()); return parser.root(); } - private PPLParser createParser(Lexer lexer) { - return new PPLParser( + private OpenDistroPPLParser createParser(Lexer lexer) { + return new OpenDistroPPLParser( new CommonTokenStream(lexer)); } - private PPLLexer createLexer(String sql) { - return new PPLLexer( + private OpenDistroPPLLexer createLexer(String sql) { + return new OpenDistroPPLLexer( new CaseInsensitiveCharStream(sql)); } }