-
Notifications
You must be signed in to change notification settings - Fork 23
Version 2.0 #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Version 2.0 #73
Conversation
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
Refactored to use Chevrotain instead of ANTLR Added lex, parser, visitor Adjusted code structure Migrated to Webpack instead of Rollup Documented breaking changes in the changelog Fixes #34 fixed typeof when ELSE was not included in query Updated README to include new documentation
Updated doc dependencies added release-it back in
Upgraded and fixed tyeps for doc website Added support for APEX_BIND_VARIABLE literalType Fixed minor bugs with parsing types with NULL as the rhs Fixed bug with an array of variable types in where clause worked around #74
Added useRawValueForFn as an option to compose to allow better control over composing functions field aliasing is now only available for FieldFunctionExpressions instead of all fields Added unit tests for some broken use-cases and fixed issues. (nested functions in groupBy did not parse or compose properly) resolves #75
Fixed the offset parsing to ensure that it is not improperly added as an alias resolves #74
Added support to turn on or off apex bind variables - resolves #76 Added support for USING SCOPE Added support for currency prefixed numbers in where clause expressions Added two additional LiteralTypes to support currency prefixed numbers Fixed bug with date N literals - not all items were working cleaned up code comments Added numerous additional test-cases based on SFDC documentation and minor bugfixes to support adjustments
Added check and forced a parsing error if parens are not matched Added notes to do a large refactor in the future for better parsing of parens resolves #80
the having clause now shares the same condition code as where clause updated changelog updated compose to support new having clause structure updated parser to allow aggregate clause in value for having clauses updated unit tests
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.
2.0.0
Summary
Version 2.0 brings some significant bundle size and performance improvements. This library now uses Chevrotain instead of antlr4. With this change, everything related to parsing had to be re-written from scratch. Chevrotain uses pure javascript to handle lexing, parsing, and visiting the generated ast/cst as opposed to using a grammar file and generating a javascript parser based on the grammar.
With this change, the data model was reviewed and analyzed, and there are some significant breaking changes to the data structures. Review the 🔥breaking changes🔥 below for a detailed description of each breaking change.
Bundle Size
soql-parser-jsbundles all of the library code and three dependencieschevrotain(which relies onregexp-to-ast) andlodash.get(required by chevrotain) into the javascript bundle. Previously,antlr4was not bundled and was required to be installed separately.To compare the bundle size, the following small program was written and then compiled using the default configuration of webpack, and the output bundle was compared.
Benchmarks
Here is an example benchmark of parsing all the unit tests 1,000 times
Breaking Changes 🔥
General Changes
parseQuery()function no longer acceptsoptionsas a second parameter.rawValuewill always have a space between parametersGROUPING(Id, BillingCountry)literalTypevalues may have differing case from prior versions, regardless of the data input.TRUE,FALSE, and all functions except those listed below will always be returned in uppercase, regardless of case of input.toLabel,convertTimezone,convertCurrencywill always be in camelCase.DateLiteralandDateNLiteral.LiteralTypevalue was added forAPEX_BIND_VARIABLE.Compose Query
getComposedField()is deprecated, you should now usegetField().getComposedField()will remain available for backward compatibility.getField()/getComposedField()has the following changes:fnproperty is has been deprecated (but still exists), you should now usefunctionNameinstead.fromproperty has been removed for subqueries. TherelationshipNameis required to be populated to compose a subquery.fieldMaxLineLenwas renamed tofieldMaxLineLength.export interface FormatOptions { numIndent?: number; - fieldMaxLineLen?: number; + fieldMaxLineLength?: number; fieldSubqueryParensOnOwnLine?: boolean; whereClauseOperatorsIndented?: boolean; logging?: boolean; }Parse Query
rawValuewill now be included onFieldifobjectPrefixis defined.aliasmay be included onField, if defined.FieldFunctionExpression,fnwas renamed tofunctionName. this was done because all other usages offnwereFunctionExp, but it was a string in this case.parameterstype onFieldFunctionExpressionwas modified to allow an array of varying types.fromproperty fromFieldSubquery.havingwas removed fromQueryBaseand now lives as a property onGroupByClause.Conditionobject,literalTypemay be an array. This will be an array ifvalueis an array and there are variable types within thevalue. For example:WHERE Foo IN ('a', null, 'b')would produceliteralType: ['STRING', 'NULL', 'STRING'].GroupByClausehas the following modifications:fieldis now optional, and will be populated only if the grouping is on a single field.typehas been renamed tofnand will be populated whenCUBEandROLLUPare used.havingclause has been moved as a top-level property to theGroupByClauseand will be populated only if ahavingclause is present.HavingConditionnow has aliteralTypethat will be populated with the type of thevalueproperty.FunctionExphas the following modificationstextwas renamed torawValueto be more consistent with other places in the data model.namewas renamed tofunctionName.parameterwas renamed toparametersand the type was changed to(string | FunctionExp)[]to support nested functions. This will ALWAYS be an array now even if there is only one parameter.fnwas removed, as nested functionParameters are always stored as an entry in theparametersarray.export interface Field { type: 'Field'; field: string; objectPrefix?: string; + rawValue?: string; + alias?: string; } export interface FieldFunctionExpression { type: 'FieldFunctionExpression'; - fn: string; + functionName: string; - parameters?: string[] | FieldFunctionExpression[]; + parameters?: (string | FieldFunctionExpression)[]; alias?: string; isAggregateFn?: boolean; rawValue?: string; } export interface FieldRelationship { type: 'FieldRelationship'; field: string; relationships: string[]; objectPrefix?: string; rawValue?: string; + alias?: string; } export interface FieldSubquery { type: 'FieldSubquery'; subquery: Subquery; - from?: string; } export interface QueryBase { fields: FieldType[]; sObjectAlias?: string; where?: WhereClause; limit?: number; offset?: number; groupBy?: GroupByClause; - having?: HavingClause; orderBy?: OrderByClause | OrderByClause[]; withDataCategory?: WithDataCategoryClause; withSecurityEnforced?: boolean; for?: ForClause; update?: UpdateClause; } export interface Condition { openParen?: number; closeParen?: number; logicalPrefix?: LogicalPrefix; field?: string; fn?: FunctionExp; operator: Operator; value?: string | string[]; valueQuery?: Query; - literalType?: LiteralType; + literalType?: LiteralType | LiteralType[]; dateLiteralVariable?: number;parsed } export interface GroupByClause { - field: string | string[]; + field?: string | string[]; - type?: GroupByType; + fn?: FunctionExp; + having?: HavingClause; } export interface HavingCondition { openParen?: number; closeParen?: number; field?: string; fn?: FunctionExp; operator: string; value: string | number; + literalType?: String; } export interface FunctionExp { - text?: string; + rawValue?: string; - name?: string; + functionName?: string; alias?: string; - parameter?: string | string[]; + parameters?: (string | FunctionExp)[]; isAggregateFn?: boolean; - fn?: FunctionExp; }resolves #72
resolves #34