@@ -53,6 +53,9 @@ public class OracleAggregateSupport extends AggregateSupportImpl {
53
53
private static final AggregateSupport V12_INSTANCE = new OracleAggregateSupport ( false , JsonSupport .QUERY );
54
54
private static final AggregateSupport LEGACY_INSTANCE = new OracleAggregateSupport ( false , JsonSupport .NONE );
55
55
56
+ private static final String JSON_QUERY_START = "json_query(" ;
57
+ private static final String JSON_QUERY_END = "')" ;
58
+
56
59
private final boolean checkConstraintSupport ;
57
60
private final JsonSupport jsonSupport ;
58
61
@@ -98,82 +101,22 @@ public String aggregateComponentCustomReadExpression(
98
101
switch ( jsonSupport ) {
99
102
case OSON :
100
103
case MERGEPATCH :
101
- switch ( columnType .getTypeCode () ) {
102
- case BOOLEAN :
103
- if ( columnType .getTypeName ().toLowerCase ( Locale .ROOT ).trim ().startsWith ( "number" ) ) {
104
- return template .replace (
105
- placeholder ,
106
- "decode(" + aggregateParentReadExpression + "." + column + ".boolean(),'true',1,'false',0,null)"
107
- );
108
- }
109
- case TINYINT :
110
- case SMALLINT :
111
- case INTEGER :
112
- case BIGINT :
113
- return template .replace (
114
- placeholder ,
115
- "" + aggregateParentReadExpression + "." + column + ".number()"
116
- );
117
- case DATE :
118
- return template .replace (
119
- placeholder ,
120
- aggregateParentReadExpression + "." + column + ".date()"
121
- );
122
- case TIME :
123
- case TIME_WITH_TIMEZONE :
124
- case TIME_UTC :
125
- return template .replace (
126
- placeholder ,
127
- "to_timestamp(" + aggregateParentReadExpression + "." + column + ".string(),'hh24:mi:ss')"
128
- );
129
- case TIMESTAMP :
130
- return template .replace (
131
- placeholder ,
132
- // Don't use .timestamp() directly because that is limited to precision 6
133
- "to_timestamp(" + aggregateParentReadExpression + "." + column + ".string(),'YYYY-MM-DD\" T\" hh24:mi:ss.FF9')"
134
- );
135
- case TIMESTAMP_WITH_TIMEZONE :
136
- case TIMESTAMP_UTC :
137
- return template .replace (
138
- placeholder ,
139
- // Don't use .timestamp() directly because that is limited to precision 6
140
- "to_timestamp_tz(" + aggregateParentReadExpression + "." + column + ".string(),'YYYY-MM-DD\" T\" hh24:mi:ss.FF9TZH:TZM')"
141
- );
142
- case BINARY :
143
- case VARBINARY :
144
- case LONG32VARBINARY :
145
- // We encode binary data as hex, so we have to decode here
146
- return template .replace (
147
- placeholder ,
148
- "hextoraw(" + aggregateParentReadExpression + "." + column + ".string())"
149
- );
150
- case CLOB :
151
- case NCLOB :
152
- case BLOB :
153
- // We encode binary data as hex, so we have to decode here
154
- return template .replace (
155
- placeholder ,
156
- "(select * from json_table(" + aggregateParentReadExpression + ",'$' columns (" + column + " " + columnType .getTypeName () + " path '$." + column + "')))"
157
- );
158
- case JSON :
159
- return template .replace (
160
- placeholder ,
161
- aggregateParentReadExpression + "." + column
162
- );
163
- default :
164
- return template .replace (
165
- placeholder ,
166
- "cast(" + aggregateParentReadExpression + "." + column + ".string() as " + columnType .getTypeName () + ')'
167
- );
168
- }
169
104
case QUERY_AND_PATH :
170
105
case QUERY :
106
+ final String parentPartExpression ;
107
+ if ( aggregateParentReadExpression .startsWith ( JSON_QUERY_START )
108
+ && aggregateParentReadExpression .endsWith ( JSON_QUERY_END ) ) {
109
+ parentPartExpression = aggregateParentReadExpression .substring ( JSON_QUERY_START .length (), aggregateParentReadExpression .length () - JSON_QUERY_END .length () ) + "." ;
110
+ }
111
+ else {
112
+ parentPartExpression = aggregateParentReadExpression + ",'$." ;
113
+ }
171
114
switch ( columnType .getTypeCode () ) {
172
115
case BOOLEAN :
173
116
if ( columnType .getTypeName ().toLowerCase ( Locale .ROOT ).trim ().startsWith ( "number" ) ) {
174
117
return template .replace (
175
118
placeholder ,
176
- "decode(json_value(" + aggregateParentReadExpression + ",'$." + column + "'),'true',1,'false',0,null)"
119
+ "decode(json_value(" + parentPartExpression + column + "'),'true',1,'false',0,null)"
177
120
);
178
121
}
179
122
case TINYINT :
@@ -182,36 +125,36 @@ public String aggregateComponentCustomReadExpression(
182
125
case BIGINT :
183
126
return template .replace (
184
127
placeholder ,
185
- "json_value(" + aggregateParentReadExpression + ",'$." + column + "' returning " + columnType .getTypeName () + ')'
128
+ "json_value(" + parentPartExpression + column + "' returning " + columnType .getTypeName () + ')'
186
129
);
187
130
case DATE :
188
131
return template .replace (
189
132
placeholder ,
190
- "to_date(json_value(" + aggregateParentReadExpression + ",'$." + column + "'),'YYYY-MM-DD')"
133
+ "to_date(json_value(" + parentPartExpression + column + "'),'YYYY-MM-DD')"
191
134
);
192
135
case TIME :
193
136
return template .replace (
194
137
placeholder ,
195
- "to_timestamp(json_value(" + aggregateParentReadExpression + ",'$." + column + "'),'hh24:mi:ss')"
138
+ "to_timestamp(json_value(" + parentPartExpression + column + "'),'hh24:mi:ss')"
196
139
);
197
140
case TIMESTAMP :
198
141
return template .replace (
199
142
placeholder ,
200
- "to_timestamp(json_value(" + aggregateParentReadExpression + ",'$." + column + "'),'YYYY-MM-DD\" T\" hh24:mi:ss.FF9')"
143
+ "to_timestamp(json_value(" + parentPartExpression + column + "'),'YYYY-MM-DD\" T\" hh24:mi:ss.FF9')"
201
144
);
202
145
case TIMESTAMP_WITH_TIMEZONE :
203
146
case TIMESTAMP_UTC :
204
147
return template .replace (
205
148
placeholder ,
206
- "to_timestamp_tz(json_value(" + aggregateParentReadExpression + ",'$." + column + "'),'YYYY-MM-DD\" T\" hh24:mi:ss.FF9TZH:TZM')"
149
+ "to_timestamp_tz(json_value(" + parentPartExpression + column + "'),'YYYY-MM-DD\" T\" hh24:mi:ss.FF9TZH:TZM')"
207
150
);
208
151
case BINARY :
209
152
case VARBINARY :
210
153
case LONG32VARBINARY :
211
154
// We encode binary data as hex, so we have to decode here
212
155
return template .replace (
213
156
placeholder ,
214
- "hextoraw(json_value(" + aggregateParentReadExpression + ",'$." + column + "'))"
157
+ "hextoraw(json_value(" + parentPartExpression + column + "'))"
215
158
);
216
159
case CLOB :
217
160
case NCLOB :
@@ -224,12 +167,12 @@ public String aggregateComponentCustomReadExpression(
224
167
case JSON :
225
168
return template .replace (
226
169
placeholder ,
227
- "json_value (" + aggregateParentReadExpression + ",'$." + column + "')"
170
+ "json_query (" + parentPartExpression + column + "')"
228
171
);
229
172
default :
230
173
return template .replace (
231
174
placeholder ,
232
- "cast(json_value(" + aggregateParentReadExpression + ",'$." + column + "') as " + columnType .getTypeName () + ')'
175
+ "cast(json_value(" + parentPartExpression + column + "') as " + columnType .getTypeName () + ')'
233
176
);
234
177
}
235
178
case NONE :
0 commit comments