ParseUtils.java

1
/*
2
 * Copyright OpenSearch Contributors
3
 * SPDX-License-Identifier: Apache-2.0
4
 */
5
6
7
package org.opensearch.sql.utils;
8
9
import com.google.common.collect.ImmutableMap;
10
import java.util.List;
11
import java.util.Map;
12
import lombok.experimental.UtilityClass;
13
import org.opensearch.sql.ast.expression.Literal;
14
import org.opensearch.sql.ast.expression.ParseMethod;
15
import org.opensearch.sql.expression.Expression;
16
import org.opensearch.sql.expression.parse.GrokExpression;
17
import org.opensearch.sql.expression.parse.ParseExpression;
18
import org.opensearch.sql.expression.parse.PatternsExpression;
19
import org.opensearch.sql.expression.parse.RegexExpression;
20
21
/**
22
 * Utils for {@link ParseExpression}.
23
 */
24
@UtilityClass
25
public class ParseUtils {
26
  private static final String NEW_FIELD_KEY = "new_field";
27
  private static final Map<ParseMethod, ParseExpressionFactory> FACTORY_MAP = ImmutableMap.of(
28
      ParseMethod.REGEX, RegexExpression::new,
29
      ParseMethod.GROK, GrokExpression::new,
30
      ParseMethod.PATTERNS, PatternsExpression::new
31
  );
32
33
  /**
34
   * Construct corresponding ParseExpression by {@link ParseMethod}.
35
   *
36
   * @param parseMethod method used to parse
37
   * @param sourceField source text field
38
   * @param pattern     pattern used for parsing
39
   * @param identifier  derived field
40
   * @return {@link ParseExpression}
41
   */
42
  public static ParseExpression createParseExpression(ParseMethod parseMethod,
43
                                                      Expression sourceField, Expression pattern,
44
                                                      Expression identifier) {
45 1 1. createParseExpression : replaced return value with null for org/opensearch/sql/utils/ParseUtils::createParseExpression → KILLED
    return FACTORY_MAP.get(parseMethod).initialize(sourceField, pattern, identifier);
46
  }
47
48
  /**
49
   * Get list of derived fields based on parse pattern.
50
   *
51
   * @param pattern pattern used for parsing
52
   * @return list of names of the derived fields
53
   */
54
  public static List<String> getNamedGroupCandidates(ParseMethod parseMethod, String pattern,
55
                                                     Map<String, Literal> arguments) {
56
    switch (parseMethod) {
57
      case REGEX:
58 1 1. getNamedGroupCandidates : replaced return value with Collections.emptyList for org/opensearch/sql/utils/ParseUtils::getNamedGroupCandidates → KILLED
        return RegexExpression.getNamedGroupCandidates(pattern);
59
      case GROK:
60 1 1. getNamedGroupCandidates : replaced return value with Collections.emptyList for org/opensearch/sql/utils/ParseUtils::getNamedGroupCandidates → KILLED
        return GrokExpression.getNamedGroupCandidates(pattern);
61
      default:
62 2 1. getNamedGroupCandidates : negated conditional → KILLED
2. getNamedGroupCandidates : replaced return value with Collections.emptyList for org/opensearch/sql/utils/ParseUtils::getNamedGroupCandidates → KILLED
        return PatternsExpression.getNamedGroupCandidates(arguments.containsKey(NEW_FIELD_KEY)
63
            ? (String) arguments.get(NEW_FIELD_KEY).getValue() : null);
64
    }
65
  }
66
67
  private interface ParseExpressionFactory {
68
    ParseExpression initialize(Expression sourceField, Expression expression,
69
                               Expression identifier);
70
  }
71
}

Mutations

45

1.1
Location : createParseExpression
Killed by : org.opensearch.sql.analysis.AnalyzerTest.[engine:junit-jupiter]/[class:org.opensearch.sql.analysis.AnalyzerTest]/[method:parse_relation_with_patterns_expression_no_args()]
replaced return value with null for org/opensearch/sql/utils/ParseUtils::createParseExpression → KILLED

58

1.1
Location : getNamedGroupCandidates
Killed by : org.opensearch.sql.analysis.AnalyzerTest.[engine:junit-jupiter]/[class:org.opensearch.sql.analysis.AnalyzerTest]/[method:parse_relation_with_regex_expression()]
replaced return value with Collections.emptyList for org/opensearch/sql/utils/ParseUtils::getNamedGroupCandidates → KILLED

60

1.1
Location : getNamedGroupCandidates
Killed by : org.opensearch.sql.analysis.AnalyzerTest.[engine:junit-jupiter]/[class:org.opensearch.sql.analysis.AnalyzerTest]/[method:parse_relation_with_grok_expression()]
replaced return value with Collections.emptyList for org/opensearch/sql/utils/ParseUtils::getNamedGroupCandidates → KILLED

62

1.1
Location : getNamedGroupCandidates
Killed by : org.opensearch.sql.analysis.AnalyzerTest.[engine:junit-jupiter]/[class:org.opensearch.sql.analysis.AnalyzerTest]/[method:parse_relation_with_patterns_expression_no_args()]
negated conditional → KILLED

2.2
Location : getNamedGroupCandidates
Killed by : org.opensearch.sql.analysis.AnalyzerTest.[engine:junit-jupiter]/[class:org.opensearch.sql.analysis.AnalyzerTest]/[method:parse_relation_with_patterns_expression_no_args()]
replaced return value with Collections.emptyList for org/opensearch/sql/utils/ParseUtils::getNamedGroupCandidates → KILLED

Active mutators

Tests examined


Report generated by PIT 1.9.0