1 | /* | |
2 | * Copyright OpenSearch Contributors | |
3 | * SPDX-License-Identifier: Apache-2.0 | |
4 | */ | |
5 | ||
6 | ||
7 | package org.opensearch.sql.data.type; | |
8 | ||
9 | import com.google.common.collect.ImmutableMap; | |
10 | import com.google.common.collect.ImmutableSet; | |
11 | import java.util.ArrayList; | |
12 | import java.util.Arrays; | |
13 | import java.util.List; | |
14 | import java.util.Map; | |
15 | import java.util.Set; | |
16 | import java.util.stream.Collectors; | |
17 | ||
18 | /** | |
19 | * Expression Type. | |
20 | */ | |
21 | public enum ExprCoreType implements ExprType { | |
22 | /** | |
23 | * Unknown due to unsupported data type. | |
24 | */ | |
25 | UNKNOWN, | |
26 | ||
27 | /** | |
28 | * Undefined type for special literal such as NULL. | |
29 | * As the root of data type tree, it is compatible with any other type. | |
30 | * In other word, undefined type is the "narrowest" type. | |
31 | */ | |
32 | UNDEFINED, | |
33 | ||
34 | /** | |
35 | * Numbers. | |
36 | */ | |
37 | BYTE(UNDEFINED), | |
38 | SHORT(BYTE), | |
39 | INTEGER(SHORT), | |
40 | LONG(INTEGER), | |
41 | FLOAT(LONG), | |
42 | DOUBLE(FLOAT), | |
43 | ||
44 | /** | |
45 | * String. | |
46 | */ | |
47 | STRING(UNDEFINED), | |
48 | ||
49 | /** | |
50 | * Boolean. | |
51 | */ | |
52 | BOOLEAN(STRING), | |
53 | ||
54 | /** | |
55 | * Date. | |
56 | * Todo. compatible relationship. | |
57 | */ | |
58 | TIMESTAMP(STRING), | |
59 | DATE(STRING), | |
60 | TIME(STRING), | |
61 | DATETIME(STRING), | |
62 | INTERVAL(UNDEFINED), | |
63 | ||
64 | /** | |
65 | * Struct. | |
66 | */ | |
67 | STRUCT(UNDEFINED), | |
68 | ||
69 | /** | |
70 | * Array. | |
71 | */ | |
72 | ARRAY(UNDEFINED); | |
73 | ||
74 | /** | |
75 | * Parents (wider/compatible types) of current base type. | |
76 | */ | |
77 | private final List<ExprType> parents = new ArrayList<>(); | |
78 | ||
79 | /** | |
80 | * The mapping between Type and legacy JDBC type name. | |
81 | */ | |
82 | private static final Map<ExprCoreType, String> LEGACY_TYPE_NAME_MAPPING = | |
83 | new ImmutableMap.Builder<ExprCoreType, String>() | |
84 | .put(STRUCT, "object") | |
85 | .put(ARRAY, "nested") | |
86 | .put(STRING, "keyword") | |
87 | .build(); | |
88 | ||
89 | private static final Set<ExprType> NUMBER_TYPES = | |
90 | new ImmutableSet.Builder<ExprType>() | |
91 | .add(BYTE) | |
92 | .add(SHORT) | |
93 | .add(INTEGER) | |
94 | .add(LONG) | |
95 | .add(FLOAT) | |
96 | .add(DOUBLE) | |
97 | .build(); | |
98 | ||
99 | ExprCoreType(ExprCoreType... compatibleTypes) { | |
100 | for (ExprCoreType subType : compatibleTypes) { | |
101 | subType.parents.add(this); | |
102 | } | |
103 | } | |
104 | ||
105 | @Override | |
106 | public List<ExprType> getParent() { | |
107 |
2
1. getParent : negated conditional → KILLED 2. getParent : replaced return value with Collections.emptyList for org/opensearch/sql/data/type/ExprCoreType::getParent → KILLED |
return parents.isEmpty() ? ExprType.super.getParent() : parents; |
108 | } | |
109 | ||
110 | @Override | |
111 | public String typeName() { | |
112 |
1
1. typeName : replaced return value with "" for org/opensearch/sql/data/type/ExprCoreType::typeName → KILLED |
return this.name(); |
113 | } | |
114 | ||
115 | @Override | |
116 | public String legacyTypeName() { | |
117 |
1
1. legacyTypeName : replaced return value with "" for org/opensearch/sql/data/type/ExprCoreType::legacyTypeName → KILLED |
return LEGACY_TYPE_NAME_MAPPING.getOrDefault(this, this.name()); |
118 | } | |
119 | ||
120 | /** | |
121 | * Return all the valid ExprCoreType. | |
122 | */ | |
123 | public static List<ExprCoreType> coreTypes() { | |
124 |
1
1. coreTypes : replaced return value with Collections.emptyList for org/opensearch/sql/data/type/ExprCoreType::coreTypes → KILLED |
return Arrays.stream(ExprCoreType.values()) |
125 |
2
1. lambda$coreTypes$0 : replaced boolean return with true for org/opensearch/sql/data/type/ExprCoreType::lambda$coreTypes$0 → SURVIVED 2. lambda$coreTypes$0 : negated conditional → KILLED |
.filter(type -> type != UNKNOWN) |
126 |
2
1. lambda$coreTypes$1 : negated conditional → KILLED 2. lambda$coreTypes$1 : replaced boolean return with true for org/opensearch/sql/data/type/ExprCoreType::lambda$coreTypes$1 → KILLED |
.filter(type -> type != UNDEFINED) |
127 | .collect(Collectors.toList()); | |
128 | } | |
129 | ||
130 | public static Set<ExprType> numberTypes() { | |
131 |
1
1. numberTypes : replaced return value with Collections.emptySet for org/opensearch/sql/data/type/ExprCoreType::numberTypes → KILLED |
return NUMBER_TYPES; |
132 | } | |
133 | } | |
Mutations | ||
107 |
1.1 2.2 |
|
112 |
1.1 |
|
117 |
1.1 |
|
124 |
1.1 |
|
125 |
1.1 2.2 |
|
126 |
1.1 2.2 |
|
131 |
1.1 |