pydpm_xl 0.1.39rc32__py3-none-any.whl → 0.2.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. py_dpm/__init__.py +1 -1
  2. py_dpm/api/__init__.py +58 -189
  3. py_dpm/api/dpm/__init__.py +20 -0
  4. py_dpm/api/{data_dictionary.py → dpm/data_dictionary.py} +903 -984
  5. py_dpm/api/dpm/explorer.py +236 -0
  6. py_dpm/api/dpm/hierarchical_queries.py +142 -0
  7. py_dpm/api/{migration.py → dpm/migration.py} +16 -19
  8. py_dpm/api/{operation_scopes.py → dpm/operation_scopes.py} +319 -267
  9. py_dpm/api/dpm_xl/__init__.py +25 -0
  10. py_dpm/api/{ast_generator.py → dpm_xl/ast_generator.py} +3 -3
  11. py_dpm/api/{complete_ast.py → dpm_xl/complete_ast.py} +186 -284
  12. py_dpm/api/dpm_xl/semantic.py +358 -0
  13. py_dpm/api/{syntax.py → dpm_xl/syntax.py} +6 -5
  14. py_dpm/api/explorer.py +4 -0
  15. py_dpm/api/semantic.py +30 -306
  16. py_dpm/cli/__init__.py +9 -0
  17. py_dpm/{client.py → cli/main.py} +12 -10
  18. py_dpm/dpm/__init__.py +11 -0
  19. py_dpm/{models.py → dpm/models.py} +112 -88
  20. py_dpm/dpm/queries/base.py +100 -0
  21. py_dpm/dpm/queries/basic_objects.py +33 -0
  22. py_dpm/dpm/queries/explorer_queries.py +352 -0
  23. py_dpm/dpm/queries/filters.py +139 -0
  24. py_dpm/dpm/queries/glossary.py +45 -0
  25. py_dpm/dpm/queries/hierarchical_queries.py +838 -0
  26. py_dpm/dpm/queries/tables.py +133 -0
  27. py_dpm/dpm/utils.py +356 -0
  28. py_dpm/dpm_xl/__init__.py +8 -0
  29. py_dpm/dpm_xl/ast/__init__.py +14 -0
  30. py_dpm/{AST/ASTConstructor.py → dpm_xl/ast/constructor.py} +6 -6
  31. py_dpm/{AST/MLGeneration.py → dpm_xl/ast/ml_generation.py} +137 -87
  32. py_dpm/{AST/ModuleAnalyzer.py → dpm_xl/ast/module_analyzer.py} +7 -7
  33. py_dpm/{AST/ModuleDependencies.py → dpm_xl/ast/module_dependencies.py} +56 -41
  34. py_dpm/{AST/ASTObjects.py → dpm_xl/ast/nodes.py} +1 -1
  35. py_dpm/{AST/check_operands.py → dpm_xl/ast/operands.py} +16 -13
  36. py_dpm/{AST/ASTTemplate.py → dpm_xl/ast/template.py} +2 -2
  37. py_dpm/{AST/WhereClauseChecker.py → dpm_xl/ast/where_clause.py} +2 -2
  38. py_dpm/dpm_xl/grammar/__init__.py +18 -0
  39. py_dpm/dpm_xl/operators/__init__.py +19 -0
  40. py_dpm/{Operators/AggregateOperators.py → dpm_xl/operators/aggregate.py} +7 -7
  41. py_dpm/{Operators/NumericOperators.py → dpm_xl/operators/arithmetic.py} +6 -6
  42. py_dpm/{Operators/Operator.py → dpm_xl/operators/base.py} +5 -5
  43. py_dpm/{Operators/BooleanOperators.py → dpm_xl/operators/boolean.py} +5 -5
  44. py_dpm/{Operators/ClauseOperators.py → dpm_xl/operators/clause.py} +8 -8
  45. py_dpm/{Operators/ComparisonOperators.py → dpm_xl/operators/comparison.py} +5 -5
  46. py_dpm/{Operators/ConditionalOperators.py → dpm_xl/operators/conditional.py} +7 -7
  47. py_dpm/{Operators/StringOperators.py → dpm_xl/operators/string.py} +5 -5
  48. py_dpm/{Operators/TimeOperators.py → dpm_xl/operators/time.py} +6 -6
  49. py_dpm/{semantics/SemanticAnalyzer.py → dpm_xl/semantic_analyzer.py} +168 -68
  50. py_dpm/{semantics/Symbols.py → dpm_xl/symbols.py} +3 -3
  51. py_dpm/dpm_xl/types/__init__.py +13 -0
  52. py_dpm/{DataTypes/TypePromotion.py → dpm_xl/types/promotion.py} +2 -2
  53. py_dpm/{DataTypes/ScalarTypes.py → dpm_xl/types/scalar.py} +2 -2
  54. py_dpm/dpm_xl/utils/__init__.py +14 -0
  55. py_dpm/{data_handlers.py → dpm_xl/utils/data_handlers.py} +2 -2
  56. py_dpm/{Utils → dpm_xl/utils}/operands_mapping.py +1 -1
  57. py_dpm/{Utils → dpm_xl/utils}/operator_mapping.py +8 -8
  58. py_dpm/{OperationScopes/OperationScopeService.py → dpm_xl/utils/scopes_calculator.py} +148 -58
  59. py_dpm/{Utils/ast_serialization.py → dpm_xl/utils/serialization.py} +3 -4
  60. py_dpm/dpm_xl/validation/__init__.py +12 -0
  61. py_dpm/{Utils/ValidationsGenerationUtils.py → dpm_xl/validation/generation_utils.py} +2 -3
  62. py_dpm/{ValidationsGeneration/PropertiesConstraintsProcessor.py → dpm_xl/validation/property_constraints.py} +56 -21
  63. py_dpm/{ValidationsGeneration/auxiliary_functions.py → dpm_xl/validation/utils.py} +2 -2
  64. py_dpm/{ValidationsGeneration/VariantsProcessor.py → dpm_xl/validation/variants.py} +149 -55
  65. py_dpm/exceptions/__init__.py +23 -0
  66. py_dpm/{Exceptions → exceptions}/exceptions.py +7 -2
  67. pydpm_xl-0.2.1.dist-info/METADATA +278 -0
  68. pydpm_xl-0.2.1.dist-info/RECORD +88 -0
  69. pydpm_xl-0.2.1.dist-info/entry_points.txt +2 -0
  70. py_dpm/Exceptions/__init__.py +0 -0
  71. py_dpm/OperationScopes/__init__.py +0 -0
  72. py_dpm/Operators/__init__.py +0 -0
  73. py_dpm/Utils/__init__.py +0 -0
  74. py_dpm/Utils/utils.py +0 -2
  75. py_dpm/ValidationsGeneration/Utils.py +0 -364
  76. py_dpm/ValidationsGeneration/__init__.py +0 -0
  77. py_dpm/api/data_dictionary_validation.py +0 -614
  78. py_dpm/db_utils.py +0 -221
  79. py_dpm/grammar/__init__.py +0 -0
  80. py_dpm/grammar/dist/__init__.py +0 -0
  81. py_dpm/grammar/dpm_xlLexer.g4 +0 -437
  82. py_dpm/grammar/dpm_xlParser.g4 +0 -263
  83. py_dpm/semantics/DAG/DAGAnalyzer.py +0 -158
  84. py_dpm/semantics/DAG/__init__.py +0 -0
  85. py_dpm/semantics/__init__.py +0 -0
  86. py_dpm/views/data_types.sql +0 -12
  87. py_dpm/views/datapoints.sql +0 -65
  88. py_dpm/views/hierarchy_operand_reference.sql +0 -11
  89. py_dpm/views/hierarchy_preconditions.sql +0 -13
  90. py_dpm/views/hierarchy_variables.sql +0 -26
  91. py_dpm/views/hierarchy_variables_context.sql +0 -14
  92. py_dpm/views/key_components.sql +0 -18
  93. py_dpm/views/module_from_table.sql +0 -11
  94. py_dpm/views/open_keys.sql +0 -13
  95. py_dpm/views/operation_info.sql +0 -27
  96. py_dpm/views/operation_list.sql +0 -18
  97. py_dpm/views/operations_versions_from_module_version.sql +0 -30
  98. py_dpm/views/precondition_info.sql +0 -17
  99. py_dpm/views/report_type_operand_reference_info.sql +0 -18
  100. py_dpm/views/subcategory_info.sql +0 -17
  101. py_dpm/views/table_info.sql +0 -19
  102. pydpm_xl-0.1.39rc32.dist-info/METADATA +0 -53
  103. pydpm_xl-0.1.39rc32.dist-info/RECORD +0 -96
  104. pydpm_xl-0.1.39rc32.dist-info/entry_points.txt +0 -2
  105. /py_dpm/{AST → cli/commands}/__init__.py +0 -0
  106. /py_dpm/{migration.py → dpm/migration.py} +0 -0
  107. /py_dpm/{AST/ASTVisitor.py → dpm_xl/ast/visitor.py} +0 -0
  108. /py_dpm/{DataTypes → dpm_xl/grammar/generated}/__init__.py +0 -0
  109. /py_dpm/{grammar/dist → dpm_xl/grammar/generated}/dpm_xlLexer.interp +0 -0
  110. /py_dpm/{grammar/dist → dpm_xl/grammar/generated}/dpm_xlLexer.py +0 -0
  111. /py_dpm/{grammar/dist → dpm_xl/grammar/generated}/dpm_xlLexer.tokens +0 -0
  112. /py_dpm/{grammar/dist → dpm_xl/grammar/generated}/dpm_xlParser.interp +0 -0
  113. /py_dpm/{grammar/dist → dpm_xl/grammar/generated}/dpm_xlParser.py +0 -0
  114. /py_dpm/{grammar/dist → dpm_xl/grammar/generated}/dpm_xlParser.tokens +0 -0
  115. /py_dpm/{grammar/dist → dpm_xl/grammar/generated}/dpm_xlParserListener.py +0 -0
  116. /py_dpm/{grammar/dist → dpm_xl/grammar/generated}/dpm_xlParserVisitor.py +0 -0
  117. /py_dpm/{grammar/dist → dpm_xl/grammar/generated}/listeners.py +0 -0
  118. /py_dpm/{DataTypes/TimeClasses.py → dpm_xl/types/time.py} +0 -0
  119. /py_dpm/{Utils → dpm_xl/utils}/tokens.py +0 -0
  120. /py_dpm/{Exceptions → exceptions}/messages.py +0 -0
  121. {pydpm_xl-0.1.39rc32.dist-info → pydpm_xl-0.2.1.dist-info}/WHEEL +0 -0
  122. {pydpm_xl-0.1.39rc32.dist-info → pydpm_xl-0.2.1.dist-info}/licenses/LICENSE +0 -0
  123. {pydpm_xl-0.1.39rc32.dist-info → pydpm_xl-0.2.1.dist-info}/top_level.txt +0 -0
py_dpm/db_utils.py DELETED
@@ -1,221 +0,0 @@
1
- import os
2
- from urllib.parse import quote_plus
3
-
4
- from dotenv import load_dotenv
5
- from sqlalchemy import create_engine
6
- from sqlalchemy.engine import URL
7
- from sqlalchemy.orm import close_all_sessions, sessionmaker
8
- from rich.console import Console
9
-
10
- console = Console()
11
-
12
- # Try to load .env from multiple locations
13
- # 1. First try py_dpm/.env (same directory as this file)
14
- env_path = os.path.join(os.path.dirname(__file__), ".env")
15
- if os.path.exists(env_path):
16
- load_dotenv(env_path)
17
- else:
18
- # 2. Try project root .env (one directory up from py_dpm)
19
- env_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), ".env")
20
- if os.path.exists(env_path):
21
- load_dotenv(env_path)
22
-
23
- # SQLite configuration
24
- sqlite_db_path = os.getenv("SQLITE_DB_PATH", "database.db")
25
-
26
- # PostgreSQL configuration
27
- postgres_host = os.getenv("POSTGRES_HOST", None)
28
- postgres_port = os.getenv("POSTGRES_PORT", "5432")
29
- postgres_db = os.getenv("POSTGRES_DB", None)
30
- postgres_user = os.getenv("POSTGRES_USER", None)
31
- postgres_pass = os.getenv("POSTGRES_PASS", None)
32
-
33
- # Legacy SQL Server configuration (kept for backward compatibility)
34
- server = os.getenv("DATABASE_SERVER", None)
35
- username = os.getenv("DATABASE_USER", None)
36
- password = os.getenv("DATABASE_PASS", None)
37
- database_name = os.getenv("DATABASE_NAME", None)
38
-
39
- # Determine database type
40
- use_postgres = os.getenv("USE_POSTGRES", "false").lower() == "true"
41
- use_sqlite = os.getenv("USE_SQLITE", "true").lower() == "true" and not use_postgres
42
-
43
- if use_postgres and not (postgres_host and postgres_user and postgres_pass and postgres_db):
44
- console.print(f"Warning: PostgreSQL credentials not provided", style="bold yellow")
45
- elif not use_sqlite and not use_postgres and not (server and username and password):
46
- console.print(f"Warning: Database credentials not provided", style="bold yellow")
47
- elif not use_sqlite and not use_postgres:
48
- # Handling special characters in password for SQL Server
49
- password = password.replace('}', '}}')
50
- for x in '%&.@#/\\=;':
51
- if x in password:
52
- password = '{' + password + '}'
53
- break
54
-
55
- engine = None
56
- connection = None
57
- sessionMakerObject = None
58
-
59
-
60
- def create_engine_from_url(connection_url):
61
- """
62
- Create SQLAlchemy engine from a connection URL with appropriate pooling parameters.
63
-
64
- Detects database type from URL scheme and applies pooling parameters conditionally:
65
- - SQLite: Only pool_pre_ping=True (no connection pooling)
66
- - PostgreSQL/MySQL/others: Full connection pooling parameters
67
-
68
- Also initializes the global sessionMakerObject for use by get_session().
69
-
70
- Args:
71
- connection_url (str): SQLAlchemy connection URL (e.g., 'sqlite:///path.db', 'postgresql://user:pass@host/db')
72
-
73
- Returns:
74
- sqlalchemy.engine.Engine: Configured database engine
75
-
76
- Examples:
77
- >>> engine = create_engine_from_url('sqlite:///database.db')
78
- >>> engine = create_engine_from_url('postgresql://user:pass@localhost/mydb')
79
- """
80
- global engine, sessionMakerObject
81
-
82
- # Detect database type from URL scheme
83
- is_sqlite = connection_url.startswith('sqlite://')
84
-
85
- if is_sqlite:
86
- # SQLite doesn't support connection pooling
87
- engine = create_engine(connection_url, pool_pre_ping=True)
88
- else:
89
- # Server-based databases (PostgreSQL, MySQL, etc.) with connection pooling
90
- engine = create_engine(
91
- connection_url,
92
- pool_size=20,
93
- max_overflow=10,
94
- pool_recycle=180,
95
- pool_pre_ping=True
96
- )
97
-
98
- # Initialize global sessionMakerObject
99
- if sessionMakerObject is not None:
100
- close_all_sessions()
101
- sessionMakerObject = sessionmaker(bind=engine)
102
-
103
- return engine
104
-
105
-
106
- def create_engine_object(url):
107
- global engine
108
-
109
- # Convert URL to string for type detection if needed
110
- url_str = str(url)
111
-
112
- # Detect database type from URL scheme (not from environment variables)
113
- is_sqlite = url_str.startswith('sqlite://')
114
-
115
- if is_sqlite:
116
- engine = create_engine(url, pool_pre_ping=True)
117
- else:
118
- # Server-based databases (PostgreSQL, MySQL, SQL Server, etc.) with connection pooling
119
- engine = create_engine(url, pool_size=20, max_overflow=10,
120
- pool_recycle=180, pool_pre_ping=True)
121
-
122
- global sessionMakerObject
123
- if sessionMakerObject is not None:
124
- close_all_sessions()
125
- sessionMakerObject = sessionmaker(bind=engine)
126
- return engine
127
-
128
-
129
- def get_engine(owner=None, database_path=None, connection_url=None):
130
- """
131
- Get database engine based on configuration or explicit parameters.
132
-
133
- Priority order:
134
- 1. Explicit connection_url parameter (for PostgreSQL or other databases)
135
- 2. Explicit database_path parameter (for SQLite)
136
- 3. Environment variable USE_POSTGRES (from .env)
137
- 4. Environment variable USE_SQLITE (from .env)
138
-
139
- Args:
140
- owner: Owner for SQL Server databases (EBA/EIOPA) - legacy support
141
- database_path: Explicit SQLite database path
142
- connection_url: Explicit SQLAlchemy connection URL (e.g., for PostgreSQL)
143
-
144
- Returns:
145
- SQLAlchemy Engine
146
- """
147
- # Priority 1: If explicit connection URL is provided, use it directly
148
- if connection_url:
149
- return create_engine_from_url(connection_url)
150
-
151
- # Priority 2: If explicit database_path is provided, use SQLite with that path
152
- if database_path:
153
- connection_url = f"sqlite:///{database_path}"
154
- return create_engine_object(connection_url)
155
-
156
- # Priority 3: Check environment variable USE_POSTGRES
157
- if use_postgres:
158
- # PostgreSQL connection
159
- connection_url = f"postgresql://{postgres_user}:{postgres_pass}@{postgres_host}:{postgres_port}/{postgres_db}"
160
- return create_engine_object(connection_url)
161
-
162
- # Priority 4: Check environment variable USE_SQLITE
163
- elif use_sqlite:
164
- # For SQLite, create the database path if it doesn't exist
165
- db_dir = os.path.dirname(sqlite_db_path)
166
- if db_dir and not os.path.exists(db_dir):
167
- os.makedirs(db_dir)
168
-
169
- # If owner is specified, append it to the filename
170
- if owner:
171
- base_name = os.path.splitext(sqlite_db_path)[0]
172
- extension = os.path.splitext(sqlite_db_path)[1] or '.db'
173
- db_path = f"{base_name}_{owner}{extension}"
174
- else:
175
- db_path = sqlite_db_path
176
-
177
- connection_url = f"sqlite:///{db_path}"
178
- return create_engine_object(connection_url)
179
- else:
180
- # Legacy SQL Server logic
181
- if owner is None:
182
- raise Exception("Cannot generate engine. No owner used.")
183
-
184
- if owner not in ('EBA', 'EIOPA'):
185
- raise Exception("Invalid owner, must be EBA or EIOPA")
186
-
187
- if database_name is None:
188
- database = "DPM_" + owner
189
- else:
190
- database = database_name
191
-
192
- if os.name == 'nt':
193
- driver = "{SQL Server}"
194
- else:
195
- driver = os.getenv('SQL_DRIVER', "{ODBC Driver 18 for SQL Server}")
196
-
197
- connection_string = (
198
- f"DRIVER={driver}", f"SERVER={server}",
199
- f"DATABASE={database}", f"UID={username}",
200
- f"PWD={password}",
201
- "TrustServerCertificate=yes")
202
- connection_string = ';'.join(connection_string)
203
- connection_url = URL.create("mssql+pyodbc", query={"odbc_connect": quote_plus(connection_string)})
204
- return create_engine_object(connection_url)
205
-
206
-
207
- def get_connection(owner=None):
208
- global engine
209
- if engine is None:
210
- engine = get_engine(owner)
211
- connection = engine.connect()
212
- return connection
213
-
214
-
215
- def get_session():
216
- global sessionMakerObject
217
- """Returns as session on the connection string"""
218
- if sessionMakerObject is None:
219
- raise Exception("Not found Session Maker")
220
- session = sessionMakerObject()
221
- return session
File without changes
File without changes
@@ -1,437 +0,0 @@
1
- lexer grammar dpm_xlLexer;
2
-
3
- // ------------ Individual tokens -----------
4
-
5
- // Boolean
6
- BOOLEAN_LITERAL:
7
- 'true'
8
- | 'false'
9
- ;
10
-
11
- AND: 'and';
12
- OR: 'or';
13
- XOR: 'xor';
14
-
15
- NOT: 'not';
16
-
17
- // Assign
18
- ASSIGN: ':=';
19
- PERSISTENT_ASSIGN: '<-';
20
-
21
- // Comparison
22
- EQ: '=';
23
- NE: '!=';
24
- LT: '<';
25
- LE: '<=';
26
- GT: '>';
27
- GE: '>=';
28
-
29
- // Matches
30
- MATCH: 'match';
31
-
32
- // With
33
- WITH: 'with';
34
-
35
- // Arithmetic
36
- PLUS: '+';
37
- MINUS: '-';
38
- MULT: '*';
39
- DIV: '/';
40
-
41
- // Aggregate
42
- MAX_AGGR: 'max_aggr';
43
- MIN_AGGR: 'min_aggr';
44
- SUM: 'sum';
45
- COUNT: 'count';
46
- AVG: 'avg';
47
- MEDIAN: 'median';
48
-
49
- // Grouping
50
- GROUP_BY: 'group by' -> pushMode(GROUPING_CLAUSE_MODE);
51
-
52
- // Unary
53
- ABS: 'abs';
54
- ISNULL: 'isnull';
55
- EXP: 'exp';
56
- LN: 'ln';
57
- SQRT: 'sqrt';
58
-
59
- // Binary
60
- POWER: 'power';
61
- LOG: 'log';
62
-
63
- MAX: 'max';
64
- MIN: 'min';
65
-
66
- // Belonging
67
- IN: 'in' -> pushMode(SET_OPERAND_MODE);
68
-
69
- // Punctuation elements
70
- COMMA: ',';
71
- COLON: ':';
72
-
73
- // Parenthesis
74
- LPAREN: '(';
75
- RPAREN: ')';
76
-
77
-
78
- // Brackets
79
- CURLY_BRACKET_LEFT: '{' -> pushMode(SELECTION_MODE);
80
- CURLY_BRACKET_RIGHT: '}';
81
- SQUARE_BRACKET_LEFT: '[' -> pushMode(CLAUSE_MODE);
82
- SQUARE_BRACKET_RIGHT: ']';
83
-
84
-
85
- // Conditional
86
- IF: 'if';
87
- ENDIF: 'endif';
88
- THEN: 'then';
89
- ELSE: 'else';
90
- NVL: 'nvl';
91
-
92
- // Filter
93
- FILTER: 'filter';
94
-
95
- // Clause
96
- WHERE: 'where';
97
- GET: 'get';
98
- RENAME: 'rename';
99
- TO: 'to';
100
- SUB: 'sub';
101
-
102
- // Reference date
103
- TIME_SHIFT: 'time_shift';
104
-
105
- // String
106
- LEN: 'len';
107
- CONCAT: '&';
108
-
109
- // Time periods
110
-
111
- TIME_PERIOD: 'A'
112
- | 'S'
113
- | 'Q'
114
- | 'M'
115
- | 'W'
116
- | 'D'
117
- ;
118
-
119
- // End of line
120
- EOL: ';';
121
-
122
-
123
- // ------------ Literals ---------------
124
- fragment
125
- DIGITS0_9: '0'..'9';
126
- fragment
127
- DIGITS1_9: '1'..'9';
128
-
129
- INTEGER_LITERAL: DIGITS0_9+
130
- | LPAREN MINUS DIGITS0_9+ RPAREN;
131
- DECIMAL_LITERAL: INTEGER_LITERAL '.' INTEGER_LITERAL;
132
- PERCENT_LITERAL: INTEGER_LITERAL '%'
133
- | DECIMAL_LITERAL '%'
134
- ;
135
- NULL_LITERAL: 'null';
136
- STRING_LITERAL: '"' (~'"')+ '"' | '\'' (~'\'')+ '\'';
137
- EMPTY_LITERAL: '\'\'' | '""';
138
-
139
- fragment
140
- YEAR: DIGITS0_9 DIGITS0_9 DIGITS0_9 DIGITS0_9;
141
-
142
- fragment
143
- MONTH: '0' DIGITS1_9
144
- | '1' [0-2]
145
- ;
146
-
147
- fragment
148
- WEEK: '0' DIGITS1_9
149
- | [1-4] DIGITS0_9
150
- | '5' [0-2]
151
- ;
152
-
153
- fragment
154
- DAY: [0-2] DIGITS0_9
155
- | '3' [0-1];
156
-
157
- fragment
158
- HOURS: [0-1] DIGITS0_9
159
- | '2' [0-3]
160
- ;
161
-
162
- fragment
163
- MINUTES: [0-5] DIGITS0_9;
164
-
165
- fragment
166
- SECONDS: [0-5] DIGITS0_9;
167
-
168
- fragment
169
- DATE_FORMAT: YEAR '-' MONTH '-' DAY ('T' HOURS COLON MINUTES COLON SECONDS)?;
170
-
171
- fragment
172
- TIME_PERIOD_FORMAT: YEAR 'A'?
173
- | YEAR 'D' [0-3] DIGITS0_9 DIGITS0_9
174
- | YEAR 'W' WEEK
175
- | YEAR 'M' MONTH
176
- | YEAR 'Q' [1-4]
177
- | YEAR 'S' [1-2]
178
- ;
179
-
180
- DATE_LITERAL: '#' DATE_FORMAT '#';
181
-
182
- TIME_INTERVAL_LITERAL: '#' DATE_FORMAT '/' DATE_FORMAT '#';
183
-
184
- TIME_PERIOD_LITERAL: '#' TIME_PERIOD_FORMAT '#';
185
-
186
- CODE: [A-Za-z]([A-Za-z0-9_.]*[A-Za-z0-9])*;
187
-
188
- WS: [ \t\r\n\u000C]+ -> channel(2);
189
-
190
-
191
- mode SELECTION_MODE;
192
-
193
- SELECTION_MODE_COMMA: COMMA -> type(COMMA);
194
- SELECTION_MODE_COLON: COLON -> type(COLON);
195
-
196
- SELECTION_MODE_LPAREN: LPAREN -> type(LPAREN);
197
- SELECTION_MODE_RPAREN: RPAREN -> type(RPAREN);
198
-
199
- SELECTION_MODE_CURLY_BRACKET_RIGHT: CURLY_BRACKET_RIGHT -> popMode, type(CURLY_BRACKET_RIGHT);
200
-
201
- INTERVAL: 'interval';
202
- DEFAULT: 'default';
203
-
204
- SELECTION_MODE_NULL_LITERAL: NULL_LITERAL -> type(NULL_LITERAL);
205
- SELECTION_MODE_BOOLEAN_LITERAL: BOOLEAN_LITERAL -> type(BOOLEAN_LITERAL);
206
-
207
- // Prefix
208
-
209
- fragment
210
- ROW_PREFIX: 'r';
211
- fragment
212
- COL_PREFIX: 'c';
213
- fragment
214
- SHEET_PREFIX: 's';
215
- fragment
216
- TABLE_PREFIX: 't';
217
- fragment
218
- TABLE_GROUP_PREFIX: 'g';
219
-
220
- fragment
221
- VAR_REF_PREFIX: 'v';
222
- fragment
223
- OPERATION_REF_PREFIX: 'o';
224
- fragment
225
- PRECONDITION_PREFIX: 'v_';
226
-
227
-
228
- // Codes
229
-
230
- fragment
231
- TABLE_CODE: [A-Za-z]([A-Za-z0-9_.-]*[A-Za-z0-9])*
232
- ;
233
- fragment
234
- CELL_COMPONENT_CODE: [0-9A-Za-z]+;
235
- fragment
236
- CELL_COMPONENT_RANGE: CELL_COMPONENT_CODE [-] CELL_COMPONENT_CODE;
237
-
238
- fragment
239
- VAR_CODE: [A-Za-z]([A-Za-z0-9_.]*[A-Za-z0-9])*;
240
- fragment
241
- OPERATION_CODE: [A-Za-z]([A-Za-z0-9_.]*[A-Za-z0-9])*;
242
-
243
- ROW: ROW_PREFIX CELL_COMPONENT_CODE;
244
- ROW_RANGE: ROW_PREFIX CELL_COMPONENT_RANGE;
245
- ROW_ALL: ROW_PREFIX [*];
246
-
247
- COL: COL_PREFIX CELL_COMPONENT_CODE;
248
- COL_RANGE: COL_PREFIX CELL_COMPONENT_RANGE;
249
- COL_ALL: COL_PREFIX [*];
250
-
251
- SHEET: SHEET_PREFIX CELL_COMPONENT_CODE;
252
- SHEET_RANGE: SHEET_PREFIX CELL_COMPONENT_RANGE;
253
- SHEET_ALL: SHEET_PREFIX [*];
254
-
255
- TABLE_REFERENCE: TABLE_PREFIX TABLE_CODE;
256
- TABLE_GROUP_REFERENCE: TABLE_GROUP_PREFIX TABLE_CODE;
257
-
258
- VAR_REFERENCE: VAR_REF_PREFIX VAR_CODE;
259
- OPERATION_REFERENCE: OPERATION_REF_PREFIX OPERATION_CODE;
260
- PRECONDITION_ELEMENT: PRECONDITION_PREFIX TABLE_CODE;
261
-
262
- SELECTION_MODE_INTEGER_LITERAL: INTEGER_LITERAL -> type(INTEGER_LITERAL);
263
- SELECTION_MODE_DECIMAL_LITERAL: DECIMAL_LITERAL -> type(DECIMAL_LITERAL);
264
- SELECTION_MODE_PERCENT_LITERAL: PERCENT_LITERAL -> type(PERCENT_LITERAL);
265
-
266
- SELECTION_MODE_STRING_LITERAL: STRING_LITERAL -> type(STRING_LITERAL);
267
- SELECTION_MODE_EMPTY_LITERAL: EMPTY_LITERAL -> type(EMPTY_LITERAL);
268
-
269
- SELECTION_MODE_DATE_LITERAL: DATE_LITERAL -> type(DATE_LITERAL);
270
- SELECTION_MODE_TIME_INTERVAL_LITERAL: TIME_INTERVAL_LITERAL -> type(TIME_INTERVAL_LITERAL);
271
- SELECTION_MODE_TIME_PERIOD_LITERAL: TIME_PERIOD_LITERAL -> type(TIME_PERIOD_LITERAL);
272
-
273
- SELECTION_MODE_WS: WS -> channel(2);
274
-
275
-
276
- mode CLAUSE_MODE;
277
-
278
- CLAUSE_BOOLEAN_LITERAL: BOOLEAN_LITERAL -> type(BOOLEAN_LITERAL);
279
-
280
- CLAUSE_AND: 'and' -> type(AND);
281
- CLAUSE_OR: 'or' -> type(OR);
282
- CLAUSE_XOR: 'xor' -> type(XOR);
283
-
284
- CLAUSE_NOT: 'not' -> type(NOT);
285
-
286
- // Comparison
287
- CLAUSE_EQ: '=' -> type(EQ);
288
- CLAUSE_NE: '!=' -> type(NE);
289
- CLAUSE_LT: '<' -> type(LT);
290
- CLAUSE_LE: '<=' -> type(LE);
291
- CLAUSE_GT: '>' -> type(GT);
292
- CLAUSE_GE: '>=' -> type(GE);
293
-
294
- // Matches
295
- CLAUSE_MATCH: 'match' -> type(MATCH);
296
-
297
- // Arithmetic
298
- CLAUSE_PLUS: '+' -> type(PLUS);
299
- CLAUSE_MINUS: '-' -> type(MINUS);
300
- CLAUSE_MULT: '*' -> type(MULT);
301
- CLAUSE_DIV: '/' -> type(DIV);
302
-
303
- // Aggregate
304
- CLAUSE_MAX_AGGR: 'max_aggr' -> type(MAX_AGGR);
305
- CLAUSE_MIN_AGGR: 'min_aggr' -> type(MIN_AGGR);
306
- CLAUSE_SUM: 'sum' -> type(SUM);
307
- CLAUSE_COUNT: 'count' -> type(COUNT);
308
- CLAUSE_AVG: 'avg' -> type(AVG);
309
- CLAUSE_MEDIAN: 'median' -> type(MEDIAN);
310
-
311
- // Grouping
312
- CLAUSE_GROUP_BY: 'group by' -> type(GROUP_BY), pushMode(GROUPING_CLAUSE_MODE);
313
-
314
- // Unary
315
- CLAUSE_ABS: 'abs' -> type(ABS);
316
- CLAUSE_ISNULL: 'isnull' -> type(ISNULL);
317
- CLAUSE_EXP: 'exp' -> type(EXP);
318
- CLAUSE_LN: 'ln' -> type(LN);
319
- CLAUSE_SQRT: 'sqrt' -> type(SQRT);
320
-
321
- // Binary
322
- CLAUSE_POWER: 'power' -> type(POWER);
323
- CLAUSE_LOG: 'log' -> type(LOG);
324
-
325
- CLAUSE_MAX: 'max' -> type(MAX);
326
- CLAUSE_MIN: 'min' -> type(MIN);
327
-
328
- // Belonging
329
- CLAUSE_IN: 'in' -> pushMode(SET_OPERAND_MODE), type(IN);
330
-
331
- // Punctuation elements
332
- CLAUSE_COMMA: ',' -> type(COMMA);
333
- CLAUSE_COLON: ':' -> type(COLON);
334
-
335
- // Parenthesis
336
- CLAUSE_LPAREN: '(' -> type(LPAREN);
337
- CLAUSE_RPAREN: ')' -> type(RPAREN);
338
-
339
-
340
- // Brackets
341
- CLAUSE_CURLY_BRACKET_LEFT: '{' -> type(CURLY_BRACKET_LEFT), pushMode(SELECTION_MODE);
342
- CLAUSE_CURLY_BRACKET_RIGHT: '}' -> type(CURLY_BRACKET_RIGHT);
343
- CLAUSE_SQUARE_BRACKET_LEFT: '[' -> type(SQUARE_BRACKET_LEFT), pushMode(CLAUSE_MODE);
344
- CLAUSE_SQUARE_BRACKET_RIGHT: ']' -> type(SQUARE_BRACKET_RIGHT), popMode;
345
-
346
-
347
- // Conditional
348
- CLAUSE_IF: 'if' -> type(IF);
349
- CLAUSE_ENDIF: 'endif' -> type(ENDIF);
350
- CLAUSE_THEN: 'then' -> type(THEN);
351
- CLAUSE_ELSE: 'else' -> type(ELSE);
352
- CLAUSE_NVL: 'nvl' -> type(NVL);
353
-
354
- // Filter
355
- CLAUSE_FILTER: 'filter' -> type(FILTER);
356
-
357
- // Clause
358
- CLAUSE_WHERE: 'where' -> type(WHERE);
359
- CLAUSE_GET: 'get' -> type(GET);
360
- CLAUSE_RENAME: 'rename' -> type(RENAME);
361
- CLAUSE_TO: 'to' -> type(TO);
362
- CLAUSE_SUB: 'sub' -> type(SUB);
363
-
364
- // Reference date
365
- CLAUSE_TIME_SHIFT: 'time_shift' -> type(TIME_SHIFT);
366
-
367
- // String
368
- CLAUSE_LEN: 'len' -> type(LEN);
369
- CLAUSE_CONCAT: '&' -> type(CONCAT);
370
-
371
- // Regex
372
-
373
- // Prefix
374
- ROW_COMPONENT: 'r';
375
- COL_COMPONENT: 'c';
376
- SHEET_COMPONENT: 's';
377
-
378
- // Time periods
379
-
380
- CLAUSE_TIME_PERIOD: TIME_PERIOD -> type(TIME_PERIOD);
381
-
382
- CLAUSE_INTEGER_LITERAL: INTEGER_LITERAL -> type(INTEGER_LITERAL);
383
- CLAUSE_DECIMAL_LITERAL: DECIMAL_LITERAL -> type(DECIMAL_LITERAL);
384
- CLAUSE_PERCENT_LITERAL: PERCENT_LITERAL -> type(PERCENT_LITERAL);
385
-
386
- CLAUSE_STRING_LITERAL: STRING_LITERAL -> type(STRING_LITERAL);
387
- CLAUSE_EMPTY_LITERAL: EMPTY_LITERAL -> type(EMPTY_LITERAL);
388
-
389
- CLAUSE_DATE_LITERAL: '#' DATE_FORMAT '#' -> type(DATE_LITERAL);
390
-
391
- CLAUSE_TIME_INTERVAL_LITERAL: '#' DATE_FORMAT '/' DATE_FORMAT '#' -> type(TIME_INTERVAL_LITERAL);
392
-
393
- CLAUSE_TIME_PERIOD_LITERAL: '#' TIME_PERIOD_FORMAT '#' -> type(TIME_PERIOD_LITERAL);
394
-
395
- ITEM_SIGNATURE: [A-Za-z]([A-Za-z0-9_-]*[:][A-Za-z0-9._-]*[A-Za-z0-9])+;
396
- PROPERTY_CODE: CODE;
397
-
398
- CLAUSE_WS: [ \t\r\n\u000C]+ -> channel(2);
399
-
400
-
401
- mode GROUPING_CLAUSE_MODE;
402
-
403
- GROUPING_RPAREN: ')' -> type(RPAREN), popMode;
404
- GROUPING_COMMA: ',' -> type(COMMA);
405
-
406
- GROUPING_ROW_COMPONENT: 'r' -> type(ROW_COMPONENT);
407
- GROUPING_COL_COMPONENT: 'c' -> type(COL_COMPONENT);
408
- GROUPING_SHEET_COMPONENT: 's' -> type(SHEET_COMPONENT);
409
- GROUPING_PROPERTY_CODE: CODE -> type(PROPERTY_CODE);
410
-
411
- GROUPING_WS: [ \t\r\n\u000C]+ -> channel(2);
412
-
413
-
414
- mode SET_OPERAND_MODE;
415
-
416
- SET_OPERAND_MODE_COMMA: COMMA -> type(COMMA);
417
-
418
- SET_OPERAND_MODE_CURLY_BRACKET_LEFT: CURLY_BRACKET_LEFT -> type(CURLY_BRACKET_LEFT);
419
- SET_OPERAND_MODE_CURLY_BRACKET_RIGHT: CURLY_BRACKET_RIGHT -> popMode, type(CURLY_BRACKET_RIGHT);
420
-
421
- SET_OPERAND_MODE_SQUARE_BRACKET_LEFT: SQUARE_BRACKET_LEFT -> type(SQUARE_BRACKET_LEFT);
422
- SET_OPERAND_MODE_SQUARE_BRACKET_RIGHT: SQUARE_BRACKET_RIGHT -> type(SQUARE_BRACKET_RIGHT);
423
-
424
- SET_OPERAND_MODE_ITEM_SIGNATURE: ITEM_SIGNATURE -> type(ITEM_SIGNATURE);
425
-
426
- SET_OPERAND_MODE_INTEGER_LITERAL: INTEGER_LITERAL -> type(INTEGER_LITERAL);
427
- SET_OPERAND_MODE_DECIMAL_LITERAL: DECIMAL_LITERAL -> type(DECIMAL_LITERAL);
428
- SET_OPERAND_MODE_PERCENT_LITERAL: PERCENT_LITERAL -> type(PERCENT_LITERAL);
429
-
430
- SET_OPERAND_MODE_STRING_LITERAL: STRING_LITERAL -> type(STRING_LITERAL);
431
- SET_OPERAND_MODE_EMPTY_LITERAL: EMPTY_LITERAL -> type(EMPTY_LITERAL);
432
-
433
- SET_OPERAND_MODE_DATE_LITERAL: DATE_LITERAL -> type(DATE_LITERAL);
434
- SET_OPERAND_MODE_TIME_INTERVAL_LITERAL: TIME_INTERVAL_LITERAL -> type(TIME_INTERVAL_LITERAL);
435
- SET_OPERAND_MODE_TIME_PERIOD_LITERAL: TIME_PERIOD_LITERAL -> type(TIME_PERIOD_LITERAL);
436
-
437
- SET_OPERAND_MODE_WS: WS -> channel(2);