1 | /* | |
2 | * Copyright OpenSearch Contributors | |
3 | * SPDX-License-Identifier: Apache-2.0 | |
4 | */ | |
5 | ||
6 | ||
7 | package org.opensearch.sql.analysis; | |
8 | ||
9 | import java.util.ArrayList; | |
10 | import java.util.HashMap; | |
11 | import java.util.List; | |
12 | import java.util.Map; | |
13 | import java.util.Objects; | |
14 | import lombok.Getter; | |
15 | import org.opensearch.sql.expression.Expression; | |
16 | import org.opensearch.sql.expression.NamedExpression; | |
17 | ||
18 | /** | |
19 | * The context used for Analyzer. | |
20 | */ | |
21 | public class AnalysisContext { | |
22 | /** | |
23 | * Environment stack for symbol scope management. | |
24 | */ | |
25 | private TypeEnvironment environment; | |
26 | @Getter | |
27 | private final List<NamedExpression> namedParseExpressions; | |
28 | ||
29 | /** | |
30 | * Storage for values of functions which return a constant value. | |
31 | * We are storing the values there to use it in sequential calls to those functions. | |
32 | * For example, `now` function should the same value during processing a query. | |
33 | */ | |
34 | @Getter | |
35 | private final Map<String, Expression> constantFunctionValues; | |
36 | ||
37 | public AnalysisContext() { | |
38 | this(new TypeEnvironment(null)); | |
39 | } | |
40 | ||
41 | /** | |
42 | * Class CTOR. | |
43 | * @param environment Env to set to a new instance. | |
44 | */ | |
45 | public AnalysisContext(TypeEnvironment environment) { | |
46 | this.environment = environment; | |
47 | this.namedParseExpressions = new ArrayList<>(); | |
48 | this.constantFunctionValues = new HashMap<>(); | |
49 | } | |
50 | ||
51 | /** | |
52 | * Push a new environment. | |
53 | */ | |
54 | public void push() { | |
55 | environment = new TypeEnvironment(environment); | |
56 | } | |
57 | ||
58 | /** | |
59 | * Return current environment. | |
60 | * | |
61 | * @return current environment | |
62 | */ | |
63 | public TypeEnvironment peek() { | |
64 |
1
1. peek : replaced return value with null for org/opensearch/sql/analysis/AnalysisContext::peek → KILLED |
return environment; |
65 | } | |
66 | ||
67 | /** | |
68 | * Pop up current environment from environment chain. | |
69 | * | |
70 | * @return current environment (before pop) | |
71 | */ | |
72 | public TypeEnvironment pop() { | |
73 | Objects.requireNonNull(environment, "Fail to pop context due to no environment present"); | |
74 | ||
75 | TypeEnvironment curEnv = environment; | |
76 | environment = curEnv.getParent(); | |
77 |
1
1. pop : replaced return value with null for org/opensearch/sql/analysis/AnalysisContext::pop → SURVIVED |
return curEnv; |
78 | } | |
79 | } | |
Mutations | ||
64 |
1.1 |
|
77 |
1.1 |